public void AddConsumableShould_CallRepositoryMethodAdd(string name, int quantity, decimal?price, string type, string ingredients) { var repositoryMock = new Mock <IRepository <Consumable> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var factoryMock = new Mock <IConsumableFactory>(); var service = new Services.ConsumableService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object); var placeId = Guid.NewGuid(); var consumable = new Consumable() { PlaceId = placeId, Name = name, Quantity = quantity, Price = price, Type = type, Ingredients = ingredients }; factoryMock.Setup(f => f.CreateConsumable(placeId, name, quantity, price, type, ingredients)) .Returns(consumable); service.AddConsumable(placeId, name, quantity, price, type, ingredients); repositoryMock.Verify(r => r.Add(consumable), Times.Once); }
public void GetAllConsumablesOfShould_ReturnCorrectResult() { var repositoryMock = new Mock <IRepository <Consumable> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var factoryMock = new Mock <IConsumableFactory>(); var id = Guid.NewGuid(); var consumable = new Consumable() { PlaceId = id, Name = "Pizza" }; var list = new List <Consumable>() { consumable }; repositoryMock.Setup(r => r.All).Returns(list.AsQueryable()); var service = new Services.ConsumableService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object); var result = service.GetAllConsumablesOf(id); Assert.AreSame(consumable, result.ToList().First()); }
public void GetAllConsumablesOfShould_ReturnCorrectResult(string name) { var repositoryMock = new Mock <IRepository <Consumable> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var factoryMock = new Mock <IConsumableFactory>(); var consumable = new Consumable() { Name = "Pizza" }; var list = new List <Consumable>() { consumable }; repositoryMock.Setup(r => r.All).Returns(list.AsQueryable()); var service = new Services.ConsumableService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object); var result = service.GetByName(name); Assert.AreSame(consumable, result); }
public void ConstructorShould_SetPassedDataCorrectlly_WhenDataIsNotNull() { var repositoryMock = new Mock <IRepository <Consumable> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var factoryMock = new Mock <IConsumableFactory>(); var service = new Services.ConsumableService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object); Assert.IsNotNull(service); }
public void GetAllConsumablesOfShould_CallRepositoryMethodAll(string name) { var repositoryMock = new Mock <IRepository <Consumable> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var factoryMock = new Mock <IConsumableFactory>(); var service = new Services.ConsumableService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object); service.GetByName(name); repositoryMock.Verify(r => r.All, Times.Once); }
public void AddConsumableShould_CallFactoryMethodCreateConsumable(string name, int quantity, decimal?price, string type, string ingredients) { var repositoryMock = new Mock <IRepository <Consumable> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var factoryMock = new Mock <IConsumableFactory>(); var service = new Services.ConsumableService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object); var placeId = Guid.NewGuid(); service.AddConsumable(placeId, name, quantity, price, type, ingredients); factoryMock.Verify(f => f.CreateConsumable(placeId, name, quantity, price, type, ingredients)); }
public void AddBookingShould_CallUnitOfWorkMethodCommit() { var repositoryMock = new Mock <IRepository <Consumable> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var factoryMock = new Mock <IConsumableFactory>(); var service = new Services.ConsumableService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object); var booking = new Booking(); var consumable = new Consumable() { Bookings = new List <Booking>() }; service.AddBooking(consumable, booking); unitOfWorkMock.Verify(u => u.Commit(), Times.Once); }