I am presently working on a project that has methods which have as parameters, complicated objects (mostly Repository objects). The testing has to be done using MSTest. Would it be a wise approach to have the objects created in the TestInitialize method, so that they could be used as arguments in the used for passing as parameters to the Actual Method in the test method? Please suggest better alternatives.
I am attaching sample code of the Method that needs to be unit tested(Exectue() method) underneath
public class AddOrdersToDbCommand
{
private IOrdersRepository _ordersRepository;
private OrderSetting _ordersSetting;
public AddOrdersToDbCommand(IOrdersRepository ordersRepository, OrderSetting ordersSetting)
{
_ordersRepository = ordersRepository;
_ordersSetting = ordersSetting;
}
public void Execute()
{
OrderSetting modifyOrderSettings = _ordersRepository.Get(_ordersSetting.Id);
modifyOrderSettings.Name = _ordersSetting.Name;
modifyOrderSettings.Status = _ordersSetting.Status;
modifyOrderSettings.UpdatedBy = _ordersSetting.UpdatedBy;
modifyOrderSettings.UpdatedDate = _ordersSetting.UpdatedDate;
_ordersRepository.SaveOrUpdate(modifyOrderSettings);
_ordersRepository.DbContext.CommitChanges();
}
}
_descriptiveSettingRepositoryand_descriptiveSettingassigned?