public void Finds_A_New_Cart() { var cartBuilder = new CartBuilder(); var address = Builders.Utility.AddressGenerate(); var shoppingCartRepository = new ShoppingCartRepository(_shoppingCartDatabaseSettings); var cart = cartBuilder.GenerateCart(address, CustomerType.Premium, ShippingMethod.Expedited); var storedCart = shoppingCartRepository.Create(cart); var result = shoppingCartRepository.FindById(storedCart.Id); result.Should().BeEquivalentTo(cart); }
public void RemoveById_CartFound_RemoveFromDb() { var target = new ShoppingCartRepository(_databaseSettings); var cart1 = new CartBuilder().WithId(null).WithCustomerId("1").Build(); target.Create(cart1); target.Remove(cart1.Id); var result = target.FindById(cart1.Id); Assert.Null(result); }
public void Update_CartFound_UpdateValue() { var target = new ShoppingCartRepository(_databaseSettings); var cart1 = new CartBuilder().WithId(null).WithCustomerId("1").Build(); target.Create(cart1); cart1.CustomerId = "other"; target.Update(cart1.Id, cart1); var result = target.FindById(cart1.Id); Assert.Equal("other", cart1.CustomerId); }
public void GetById_hasThreeCartsInDB_returnReturnOnlyCartWithCorrectId() { var target = new ShoppingCartRepository(_databaseSettings); var cart1 = new CartBuilder().WithId(null).WithCustomerId("1").Build(); target.Create(cart1); var cart2 = new CartBuilder().WithId(null).WithCustomerId("2").Build(); target.Create(cart2); var cart3 = new CartBuilder().WithId(null).WithCustomerId("3").Build(); target.Create(cart3); var actual = target.FindById(cart2.Id); Assert.Equal(cart2, actual); }
public void GetById_CartNotFound_ReturnNull() { var target = new ShoppingCartRepository(_databaseSettings); var cart1 = new CartBuilder().WithId(null).WithCustomerId("1").Build(); target.Create(cart1); var cart2 = new CartBuilder().WithId(null).WithCustomerId("2").Build(); target.Create(cart2); var cart3 = new CartBuilder().WithId(null).WithCustomerId("3").Build(); target.Create(cart3); var actual = target.FindById(Invalid_ID); Assert.Null(actual); }
public void Delete_ValidData_RemoveShoppingCartToDB() { var cart = new CartBuilder() .WithId(null) .WithCustomerId("1") .WithItems(new List <Item> { CreateItem() }) .Build(); var repository = new ShoppingCartRepository(_databaseSettings); repository.Create(cart); var target = CreateShoppingCartController(repository); var result = target.DeleteCart(cart.Id); var value = repository.FindById(cart.Id); Assert.Null(value); }
public void Create_ValidData_SaveShoppingCartToDB() { var repository = new ShoppingCartRepository(_databaseSettings); var target = CreateShoppingCartController(repository); var result = target.Create(new CreateCartDto { Customer = new CustomerDto { Address = CreateAddress(), }, Items = new[] { CreateItemDto() } }); Assert.IsType <CreatedAtRouteResult>(result.Result); var cartId = ((CreatedAtRouteResult)result.Result).RouteValues["id"]?.ToString(); var value = repository.FindById(cartId); Assert.NotNull(value); }
public ShoppingCart GetDetail(int id) { return(repository.FindById(id)); }