public void TestAddShouldThrowsArgumentNullExceptionWhenShoppingCartIdIsNull() { //Arrange var shoppingCartItem = new ShoppingCartItem { Id = 999, ShopItemId = 999, ShopItem = new ShopItem { Id = 999, Name = "TestItem", CategoryId = 999 }, ShoppingCartId = null !, Amount = 1 }; var mockDatabaseContext = new Mock <IDatabaseContext>(); var sut = new ShoppingCartItemRepository(mockDatabaseContext.Object); //Act Assert.Throws <ArgumentNullException>( //Assert () => sut.Add(shoppingCartItem)); }
public void TestAddShouldThrowsArgumentExceptionWhenShopItemWithShopItemIdNotFound() { //Arrange var uniqueId = Guid.NewGuid().ToString(); const string expectedExceptionMessage = "Shop Item not found with ShopItemId"; var shoppingCartItem = new ShoppingCartItem { Id = 999, ShopItemId = 99, ShopItem = new ShopItem { Id = 999, Name = "TestItem", CategoryId = 999 }, ShoppingCartId = uniqueId, Amount = 1 }; var mockDatabaseContext = new DatabaseContext(_options); var sut = new ShoppingCartItemRepository(mockDatabaseContext); //Act var exception = Assert.Throws <ArgumentException>( //Assert () => sut.Add(shoppingCartItem)); Assert.Equal(expectedExceptionMessage, exception.Message); }
public void TestAddShouldIncreaseTheAmountIfEntityExists() { //Arrange const int expectedShoppingCartItemsCount = 1; const int expectedShoppingCartItemsAmount = 2; var uniqueId = Guid.NewGuid().ToString(); var shoppingCartItem = new ShoppingCartItem { Id = 999, ShopItemId = 999, ShopItem = new ShopItem { Id = 999, Name = "TestItem", CategoryId = 999 }, ShoppingCartId = uniqueId, Amount = 1 }; using var context = new DatabaseContext(_options); var sut = new ShoppingCartItemRepository(context); //Act sut.Add(shoppingCartItem); sut.Add(shoppingCartItem); var result = sut.GetAll().Where(s => s.ShoppingCartId == uniqueId); //Assert Assert.Equal(expectedShoppingCartItemsCount, result.Count()); Assert.Equal(expectedShoppingCartItemsAmount, result.First().Amount); }
public void TestAddShouldThrowsArgumentNullExceptionWhenShopItemIsNull() { //Arrange var uniqueId = Guid.NewGuid().ToString(); var shoppingCartItem = new ShoppingCartItem { Id = 999, ShopItemId = 999, ShopItem = null !, ShoppingCartId = uniqueId, Amount = 1 }; var mockDatabaseContext = new Mock <IDatabaseContext>(); var sut = new ShoppingCartItemRepository(mockDatabaseContext.Object); //Act Assert.Throws <ArgumentNullException>( //Assert () => sut.Add(shoppingCartItem)); }