c# - Unit testing methods that have multiple complicated objects as parameters in MSTest -
I am currently working on projects in which the parameters are in the form of complex objects (mostly repository objects). The test will have to use MSTEST. Is it a wise approach to the manufactured items in the testing methodology, so that they can be used as a logic in the use of the method to pass the pattern of the actual method in the examination system? Please suggest better options
Public class AddOrdersToDbCommand {Private IOrdersRepository _ordersRepository; I am attaching the sample code of the method which requires the unit test (Exectue () method). Private command setting_command; Settings; Public AddOrdersToDbCommand (IOrdersRepository ordersRepository, order ordering order) {_ordersRepository = ordersRepository; _ordersSetting = commandsSetting; } Execute Public Zero () {Modify Order Settings Order Settings = _ordersRepository.Get (_ordersSetting.Id); ModifyOrderSettings.Name = _ordersSetting.Name; Modified order settings. Status = _ordersSetting.Status; Modified order settings. Updated By = _ordersSetting.Updated By; Modify the folders Update date = _ordersSetting.UpdatedDate; _ordersRepository.SaveOrUpdate (modifyOrderSettings); _ordersRepository.DbContext.CommitChanges (); }}
You should use (using the mocking structure like Moq) dependent In this way you are only doing separate and testing items, which is currently in test.
If you really want to create a stub object, then I like to do it with a support class. I have TestDataGenerator.cs class. There you can create a set of static methods to create objects.
Example will be used to then TestDataGenerator.GetStubOrderSetting (); The advantage of using a used class is that you create a whole stack of supportive methods, which will return stub objects without having to do your test initial method larger and slow, as well as, you can use more complex objects Can make different stub methods back to back For example TestDataGenerator.GetStubEmployeeWithOrder (); will first create a stub employee and then TestDataGenerator.GetStubOrderSetting (); Call that you were already created to set the order for a newly created stub employee before returning it.
Comments
Post a Comment