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_Deletes_RentalOrder() { using (var context = new VivesRentalDbContext()) { //Arrange var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrderToAdd = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrderToAdd); var rentalOrderId = rentalOrderToAdd.Id; context.SaveChanges(); //Act rentalOrderRepository.Remove(rentalOrderToAdd); context.SaveChanges(); var rentalOrder = rentalOrderRepository.Get(rentalOrderId); //Assert Assert.IsNull(rentalOrder); } }
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 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 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 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 Get_Returns_Null_When_Not_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); //Act var item = itemRepository.Get(1); //Assert Assert.IsNull(item); } }
public void Get_Returns_Null_When_Not_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var rentalOrderRepository = new RentalOrderRepository(context); //Act var rentalOrder = rentalOrderRepository.Get(1); //Assert Assert.IsNull(rentalOrder); } }
public void Add_Returns_1_When_Adding_Valid_Item() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var item = ItemFactory.CreateValidEntity(); //Act itemRepository.Add(item); var result = context.SaveChanges(); //Assert Assert.AreEqual(1, result); } }
public void Add_Throws_Exception_When_Adding_InValid_Item() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); //Act var item = ItemFactory.CreateInvalidEntity(); itemRepository.Add(item); var result = context.SaveChanges(); //No Assert } }
public void Add_Throws_Exception_When_Adding_InValid_RentalOrder() { using (var context = new VivesRentalDbContext()) { //Arrange var rentalOrderRepository = new RentalOrderRepository(context); //Act var rentalOrder = RentalOrderFactory.CreateInvalidEntity(); rentalOrderRepository.Add(rentalOrder); var result = context.SaveChanges(); //No Assert } }
public void Get_Returns_Item_When_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var itemToAdd = ItemFactory.CreateValidEntity(); itemRepository.Add(itemToAdd); context.SaveChanges(); //Act var item = itemRepository.Get(itemToAdd.Id); //Assert Assert.IsNotNull(item); } }
public void Get_Returns_Item_When_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var userRepository = new UserRepository(context); var userToAdd = UserFactory.CreateValidEntity(); userRepository.Add(userToAdd); context.SaveChanges(); //Act var user = userRepository.Get(userToAdd.Id); //Assert Assert.IsNotNull(user); } }
public void Remove_Throws_Exception_When_Not_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var itemToAdd = ItemFactory.CreateValidEntity(); itemRepository.Add(itemToAdd); context.SaveChanges(); //Act itemRepository.Remove(ItemFactory.CreateValidEntity()); context.SaveChanges(); //Assert } }
public void GetAll_Returns_10_Items() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); for (int i = 0; i < 10; i++) { var itemToAdd = ItemFactory.CreateValidEntity(); itemRepository.Add(itemToAdd); } context.SaveChanges(); //Act var items = itemRepository.GetAll(); //Assert Assert.AreEqual(10, items.Count()); } }