When the MOQ framework does a unit test, simulate adding a data, will it really have a record in the database?
1 thought on “When the MOQ framework does a unit test, simulate adding a data, will it really have a record in the database?”
Leave a Comment
You must be logged in to post a comment.
1. What can I use MOQ to simulate?
It you can use MOQ to create analog objects for interfaces and existing classes. When it is used to class, it is necessary to have certain conditions: the class cannot be a closed type; and the simulated method must be marked as a virtual type (Virtual). You can't simulate the static method (but you can use the Adaptor mode to simulate a static method). In fact, these restrictions are consistent with you when you use another simulation object framework Rhino Mocks.
MOQ and Rhino Mocks use proxy technology in the background implementation. Moreover, a deeper understanding, these two frameworks are derived from the same Castle code base class.
. Use MOQ to simulate the method and attributes
. Now, you may wish to imagine that you are writing a web application driven by a drama library -such as an online shop. Before the encoding of any other part, you want to complete the design of the business logic part of this e -store software first. In particular, before writing your business logic components, you don't want to put any energy to write data to access related components.
The case in the above situation is particularly suitable for using an analog object framework. At this point, you can create an interface to describe what you want to make your data access components look like. Then, you can simply simulate this interface and fully use the advantages of the simulation object when testing your business logic (that is, you don't need to truly realize the simulated components). Therefore, with the help of this simulation solution, you can first consider these components related codes until you have made full preparation for this part of the programming of the simulated component.
The first interface names provided in List 1 are describing two methods. Among them, the first method Select () is responsible for returning all the products in the database. The second method get () returns a product based on the given specific product ID. In addition, list 1 also provides an interface with an iProct; this interface is used to describe a specific product.