I'm new in Unit Test and i'm trying to write a unit test for the below method of my serive
public InventoryViewModel GetInventory(DateTime startDate, DateTime endDate, long roomServiceId)
{
InventoryViewModel inv = new InventoryViewModel();
var roomService = _unitOfWork.RoomServiceRepository.GetByID(roomServiceId);
if (roomService == null)
throw new InvalidOperationException("there is not the roomService");
....
}
this method works correctly, but when i call this method from my TestMethod, RoomServiceRepository don't return the roomService, my testMehtod is like this :
[TestClass]
public class InventoryTest
{
private UnityContainer _container;
readonly MockObjectsSetup _mos = new MockObjectsSetup();
private IInventoryService _inventoryService;
[TestInitialize]
public void SetupTest()
{
_container = new UnityContainer();
_mos.Setup(_container);
Config.UnityTestConfig.RegisterTypes(_container);
_container.RegisterType<IInventoryService, InventoryService>();
_inventoryService = (InventoryService)_container.Resolve(typeof(InventoryService));
}
[TestMethod]
public void Dont_Change_NotSelected_PriceValues()
{
DateTime startDate = DateTime.Parse("6/21/2016");
DateTime endDate = DateTime.Parse("6/22/2016");
long roomServiceId = 17;
InventoryViewModel invViewModel = new InventoryViewModel();
invViewModel.isUpdatingBoardPrice = invViewModel.isUpdatingPrice = invViewModel.isUpdatingFloatAvailability = true;
invViewModel.isUpdatingCertainAvailability = false;
invViewModel.StartDate = startDate;
invViewModel.EndDate = endDate;
invViewModel.RoomServiceId = roomServiceId;
invViewModel.CertainAvailability = 0;
invViewModel.FloatAvailability = 8;
var inv = _inventoryService.GetInventory(startDate, endDate, roomServiceId);
....
}
}
Aucun commentaire:
Enregistrer un commentaire