public void Remove_Deletes_RentalItem_With_RentalOrderLines() { var unitOfWorkFactory = new UnitOfWorkFactory(); //Arrange var userService = new UserService(unitOfWorkFactory); var itemService = new ItemService(unitOfWorkFactory); var rentalItemService = new RentalItemService(unitOfWorkFactory); var rentalOrderService = new RentalOrderService(unitOfWorkFactory); var rentalOrderLineService = new RentalOrderLineService(unitOfWorkFactory); var userToAdd = UserFactory.CreateValidEntity(); var user = userService.Create(userToAdd); var itemToAdd = ItemFactory.CreateValidEntity(); var item = itemService.Create(itemToAdd); var rentalItemToAdd = RentalItemFactory.CreateValidEntity(item); var rentalItem = rentalItemService.Create(rentalItemToAdd); var rentalOrder = rentalOrderService.Create(user.Id); //var rentalOrderLineToAdd = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); var rentalOrderLine = rentalOrderLineService.Rent(rentalOrder.Id, rentalItem.Id); //Act var result = rentalItemService.Remove(rentalItem.Id); //Assert Assert.IsTrue(result); }
public void Get_Returns_RentalOrder_When_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var rentalOrderLineRepository = new RentalOrderLineRepository(context); var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrder); var rentalOrderLineToAdd = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLineRepository.Add(rentalOrderLineToAdd); context.SaveChanges(); //Act var rentalOrderLine = rentalOrderLineRepository.Get(rentalOrderLineToAdd.Id); //Assert Assert.IsNotNull(rentalOrderLine); } }
public void Remove_Deletes_Item() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItemToAdd = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItemToAdd); var rentalItemId = rentalItemToAdd.Id; context.SaveChanges(); //Act rentalItemRepository.Remove(rentalItemToAdd); context.SaveChanges(); var rentalItem = rentalItemRepository.Get(rentalItemId); //Assert Assert.IsNull(rentalItem); } }
public void Remove_Throws_Exception_When_Not_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var rentalOrderLineRepository = new RentalOrderLineRepository(context); var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrder); var rentalOrderLineToAdd = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLineRepository.Add(rentalOrderLineToAdd); context.SaveChanges(); //Act rentalOrderLineRepository.Remove(RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem)); context.SaveChanges(); //Assert } }
public void Add_Returns_1_When_Adding_Valid_RentalOrder() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var rentalOrderLineRepository = new RentalOrderLineRepository(context); //Act var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrder); var rentalOrderLine = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLineRepository.Add(rentalOrderLine); var result = context.SaveChanges(); //Assert Assert.AreEqual(5, result); //Because we added five entities } }
public void GetAll_Returns_10_RentalOrders() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var rentalOrderLineRepository = new RentalOrderLineRepository(context); for (int i = 0; i < 10; i++) { var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrder); var rentalOrderLineToAdd = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLineRepository.Add(rentalOrderLineToAdd); } context.SaveChanges(); //Act var rentalOrderLines = rentalOrderLineRepository.GetAll(); //Assert Assert.AreEqual(10, rentalOrderLines.Count()); } }
public void RentalOrderLine_IsValid_Returns_True_When_Valid() { //Arrange var user = UserFactory.CreateValidEntity(); user.Id = 1; var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrder.Id = 1; var item = ItemFactory.CreateValidEntity(); item.Id = 1; var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItem.Id = 1; var rentalOrderLine = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLine.Id = 1; //Act var result = rentalOrderLine.IsValid(); //Assert Assert.IsTrue(result); }
public void RentalItem_IsValid_Returns_False_When_Invalid() { //Arrange var rentalItem = RentalItemFactory.CreateInvalidEntity(); //Act var result = rentalItem.IsValid(); //Assert Assert.IsFalse(result); }
public void Add_Throws_Exception_When_Adding_InValid_Item() { using (var context = new VivesRentalDbContext()) { //Arrange var rentalItemRepository = new RentalItemRepository(context); //Act var rentalItem = RentalItemFactory.CreateInvalidEntity(); rentalItemRepository.Add(rentalItem); var result = context.SaveChanges(); //No Assert } }
public void RentalItem_IsValid_Returns_True_When_Valid() { //Arrange var item = ItemFactory.CreateValidEntity(); item.Id = 1; var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItem.Id = 1; //Act var result = rentalItem.IsValid(); //Assert Assert.IsTrue(result); }
public void Remove_Deletes_RentalItem() { var unitOfWorkFactory = new UnitOfWorkFactory(); //Arrange var itemService = new ItemService(unitOfWorkFactory); var rentalItemService = new RentalItemService(unitOfWorkFactory); var itemToAdd = ItemFactory.CreateValidEntity(); var newItem = itemService.Create(itemToAdd); var rentalItem = RentalItemFactory.CreateValidEntity(newItem); var newRentalItem = rentalItemService.Create(rentalItem); //Act var result = rentalItemService.Remove(newRentalItem.Id); //Assert Assert.IsTrue(result); }
public void Add_Returns_1_When_Adding_Valid_Item() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); //Act var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var result = context.SaveChanges(); //Assert Assert.AreEqual(2, result); //Because we added two entities } }
public void Get_Returns_Item_When_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItemToAdd = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItemToAdd); context.SaveChanges(); //Act var rentalItem = rentalItemRepository.Get(rentalItemToAdd.Id); //Assert Assert.IsNotNull(rentalItem); } }
public void PickItem(string rentalItemCode) { if (RentalStatus == RentalStatus.Started) { RentalStatus = RentalStatus.Picking; } if (RentalStatus != RentalStatus.Picking) { throw new Exception(); } // var isUnique = true; // foreach (var rentalItem in RentalItems) // { // if (rentalItem.RentalItemCode == rentalItemCode) // { // isUnique = false; // } // } // isUnique = !RentalItems.Any(rentalItem => rentalItem.RentalItemCode == rentalItemCode); // if (!isUnique) // { // throw new Exception(); // } if (RentalItems.Any(rentalItem => rentalItem.RentalItemCode == rentalItemCode)) { throw new Exception(); } // ToDo: Add item status validation var rentalItem = RentalItemFactory.Create(rentalItemCode); RentalItems.Add(rentalItem); }