public void ShouldGetListOfCartsForContextShop() { // Arrange var cartService = Substitute.For <CartServiceProvider>(); var carts = new[] { new Cart { ExternalId = "1001" }, new Cart { ExternalId = "1002" } }; cartService.GetCarts(Arg.Is <GetCartsRequest>(r => r.Shop.Name == "mystore")).Returns(new GetCartsResult { Carts = carts }); CartsController controller = new CartsController(cartService); using (new SiteContextSwitcher(new TSiteContext("mystore"))) { // Act var result = controller.Get(); // Assert result.Count().Should().Be(2); result.ElementAt(0).ExternalId.Should().Be("1001"); result.ElementAt(1).ExternalId.Should().Be("1002"); } }
public void add_product_to_cart_return_cart_id() { int product_id = 1; int quantity = 10; var mockCartService = new Mock <ICartsService>(); var mockProductService = new Mock <IProductService>(); var product = new ProductsModel { id = 1, name = "43 Piece dinner Set", gender = "Female", age = "3_to_5", availability = "InStock", brand = "CoolKidz" }; mockProductService.Setup( service => service.getProductDetail(product_id)) .Returns( product ); mockCartService.Setup( service => service.add(product, quantity)) .Returns(new AddCartOutputModel { id = 1 }); CartsController cartsController = new CartsController(mockCartService.Object, mockProductService.Object); AddCartInputModel input = new AddCartInputModel { id = product_id, quantity = quantity }; JsonResult result = cartsController.Post(input) as JsonResult; var json = JsonConvert.SerializeObject(result.Value); var cart = JsonConvert.DeserializeObject <AddCartOutputModel>(json); Assert.Equal(1, cart.id); }
public void ShouldFilterListOfCartsByUserId() { // Arrange var cartService = Substitute.For <CartServiceProvider>(); var carts1 = new[] { new Cart { ExternalId = "1001", UserId = "Bob" } }; var carts2 = new[] { new Cart { ExternalId = "1001", UserId = "Stan" } }; var carts = carts1.Union(carts2); cartService.GetCarts(Arg.Is <GetCartsRequest>(r => r.Shop.Name == "mystore")).Returns(new GetCartsResult { Carts = carts }); cartService.GetCarts(Arg.Is <GetCartsRequest>(r => r.Shop.Name == "mystore" && r.UserIds.Contains("Bob"))).Returns(new GetCartsResult { Carts = carts1 }); CartsController controller = new CartsController(cartService); using (new SiteContextSwitcher(new TSiteContext("mystore"))) { // Act var result = controller.Get(userId: "Bob"); // Assert result.Count().Should().Be(1); result.ElementAt(0).ExternalId.Should().Be("1001"); result.ElementAt(0).UserId.Should().Be("Bob"); } }
public void SetUp() { var builder = new DbContextOptionsBuilder <BaseContext>().UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=AvaliacaoNonlinear;integrated security=True;"); //var builder = new DbContextOptionsBuilder<BaseContext>().UseSqlServer("Server=DESKTOP-NBVUSVN\\SQLEXPRESS;Database=AvaliacaoNonlinear;integrated security=True;"); db = new BaseContext(builder.Options); this.controllerProduct = new ProductsController(db); this.controllerSale = new SalesController(db); this.controllerPayment = new PaymentsController(db); this.controllerCart = new CartsController(db); this.controllerCartItem = new CartItemsController(db); }
public void GetCustomerCartItems_Null_ReturnsNotFound() { // Arrange cartService.Setup(repo => repo.GetCustomerCartItems(It.IsAny <string>())).Returns(() => null); var controller = new CartsController(cartService.Object, autoMapper.Object); // Act var result = controller.GetCustomerCartItems(customerEmail); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task ValidAccountId_ShouldAllowCartCreation() { //Arrange var account = await context.Accounts.FirstOrDefaultAsync(m => m.AccountId == 2); var cartController = new CartsController(context, hostEnvironment); //Act await cartController.CreateCart(account.AccountId.ToString()); //Assert Assert.True(cartController.ModelState.IsValid); }
public void TotalPointsOfPurchase21Dollars47Cents_ShouldReturn215Points() { // Arrange CartsController controllerContext = new CartsController(context, hostEnvironment); double cartTotal = 21.47; double pointsShouldRetrieve = 215; // Act double realPointValue = controllerContext.PointsEarned(cartTotal); // Arrange Assert.Equal(pointsShouldRetrieve, realPointValue); }
public void ProductTax_NegativeValuesShouldStillCalculateAndPass() { // Arrange CartsController controllerContext = new CartsController(context, hostEnvironment); double subTotal = -1500; double tax = -195; // Act double total = controllerContext.Tax(subTotal); //Assert Assert.Equal(total, tax); }
public void ProductTax_ShouldReturn195() { // Arrange CartsController controllerContext = new CartsController(context, hostEnvironment); double subTotal = 1500; double tax = 195; // Act double total = controllerContext.Tax(subTotal); // Assert Assert.Equal(total, tax); }
public void StripeTaxAmount_ShouldReturnTaxAsProperConversion() { // Arrange CartsController controllerContext = new CartsController(context, hostEnvironment); double subTotal = 2997; double tax = 0.13; double expectedTaxValue = 390; // Act double outcomeTaxValue = controllerContext.StripeTax(subTotal); // Assert Assert.Equal(expectedTaxValue, outcomeTaxValue); }
public void TotalStripeAmount_ShouldConvertTheTotalProperlyForStripe() { // Arrange CartsController controllerContext = new CartsController(context, hostEnvironment); double total = 1695; double stripeExpectedTotal = total * 100; // Act double calculatedTotal = controllerContext.StripeAmount(total); // Assert Assert.Equal(stripeExpectedTotal, calculatedTotal); }
public void TotalPointsOfPurchaseIfNegativeValues_ShouldStillFunctionAndNotCauseErrors() { // Arrange CartsController controllerContext = new CartsController(context, hostEnvironment); double cartTotal = -21.47; double pointsShouldRetrieve = -215; // Act double realPointValue = controllerContext.PointsEarned(cartTotal); // Arrange Assert.Equal(pointsShouldRetrieve, realPointValue); }
public void ProductTotalIfTax0_ShouldStillReturn() { // Arrange CartsController controllerContext = new CartsController(context, hostEnvironment); double subTotal = 1500; double tax = 0; double total = subTotal + tax; // Act double calculatedTotal = controllerContext.TotalCost(subTotal, tax); // Arrange Assert.Equal(total, calculatedTotal); }
public void EmptyCart_NotExistingCartFails() { //arrange var controller = new CartsController(ShoppingSetupFixture.DataSource.Object); var cart = new Cart() { Id = Guid.NewGuid() }; //act var result = controller.EmptyCart(cart.Id); //assert Assert.IsInstanceOf <NotFoundResult>(result); }
public void ProductTotalPrice_ShouldReturn1695() { // Arrange CartsController controllerContext = new CartsController(context, hostEnvironment); double subTotal = 1500; double tax = 195; double total = subTotal + tax; // Act double calculatedTotal = controllerContext.TotalCost(subTotal, tax); // Assert Assert.Equal(total, calculatedTotal); }
public void Constructor_AllServicesMock_CartsController() { // arrange var mockLogger = new Mock <ILogger>(); var mockHttpContext = new Mock <HttpContextBase>(); var mockCommerceService = new Mock <ICommerceService>(); // act var sut = new CartsController(mockCommerceService.Object, mockLogger.Object, mockHttpContext.Object); // assert Assert.IsNotNull(sut); }
public void TestTotalPrice_GivenGameItems_ShouldEqual() { // Arrange InitializeCartItems(); CartItem item1 = cartItems[0]; CartItem item2 = cartItems[1]; CartsController controller = new CartsController(_context); Game game1 = _context.Game.FirstOrDefault(g => g.GameId == cartItems[0].Game.GameId); Game game2 = _context.Game.FirstOrDefault(g => g.GameId == cartItems[1].Game.GameId); // Act decimal expect = Math.Round(item1.Game.GamePrice * item1.Quantity + item2.Game.GamePrice * item2.Quantity); decimal result = Math.Round(game1.GamePrice * item1.Quantity + game2.GamePrice * item2.Quantity); // Assert Assert.Equal(expect, result); }
public void Constructor_AllServicesManually_CartsController() { // arrange var httpRequest = new HttpRequest("", "https://www.vml.com", ""); var stringWriter = new StringWriter(); var httpResponse = new HttpResponse(stringWriter); var httpContext = new HttpContext(httpRequest, httpResponse); HttpContextBase contextBase = new HttpContextWrapper(httpContext); ICommerceService service = new DefaultCommerceService(new CommerceDatabaseContext()); ILogger logger = new Log4netLogger(new RootLogger(Level.Alert), new Log4netFactory()); // act var sut = new CartsController(service, logger, contextBase); // assert Assert.IsNotNull(sut); }
public async Task ValidCartObject_ShouldAllowDelete() { //Arrange var account = await context.Accounts .FirstOrDefaultAsync(m => m.AccountId == 1); var cart = await context.Cart .Include(c => c.Account) .FirstOrDefaultAsync(s => s.AccountId == account.AccountId); var cartController = new CartsController(context, hostEnvironment); //Act await cartController.DeleteCart(cart.CartId); //Assert Assert.True(cartController.ModelState.IsValid); }
public async Task ValidSellListing_ShouldAllowAddToCart() { //Arrange var sellListing = await context.SellListings.Include(s => s.PriceTrend) .Include(s => s.Seller) .Include(s => s.Seller.Account) .FirstOrDefaultAsync(s => s.SellListingId == 1); var account = await context.Accounts .FirstOrDefaultAsync(m => m.AccountId == 1); var cartController = new CartsController(context, hostEnvironment); //Act await cartController.Add(sellListing.SellListingId, account.AccountId.ToString()); //Assert Assert.True(cartController.ModelState.IsValid); }
public async Task InvalidCartObject_ShouldNotAllowChangeTransactionStatus() { //Arrange var account = await context.Accounts .FirstOrDefaultAsync(m => m.AccountId == 1); var cart = await context.Cart .Include(c => c.Account) .FirstOrDefaultAsync(s => s.AccountId == account.AccountId); var cartController = new CartsController(context, hostEnvironment); cartController.ModelState.AddModelError("test", "test"); //Act await cartController.ChangeCartTransactionStatus(cart : null); //Assert Assert.False(cartController.ModelState.IsValid); }
public void AddToModified_NotExistingItemFails() { //arrange var controller = new CartsController(ShoppingSetupFixture.DataSource.Object); var cart = new Cart() { Id = Guid.NewGuid() }; var item = new Item() { Id = Guid.NewGuid() }; ShoppingSetupFixture.Carts.Add(cart); //act var result = controller.AddToModified(item.Id, cart.Id); //assert Assert.IsInstanceOf <NotFoundResult>(result); }
public void Test_GetCarritoX() { string connString = "Data Source = (LocalDb)\\MSSQLLocalDB; Initial Catalog = MvcShopping; Integrated Security = True"; SqlConnection cn = new SqlConnection(connString); using (cn) { cn.Open(); MusicStoreEntities interop_db = new MusicStoreEntities(cn); var controller = new CartsController(interop_db); var result = controller.GetCart(0); Assert.IsNotNull(result); } cn.Close(); }
public void SetUp() { _cartService = new Mock <ICrudInterface <CartDto> >(); _cartsController = new CartsController(_cartService.Object); }
public CartsControllerTests() { this.cartService = Substitute.For <ICartService>(); this.controller = Substitute.For <CartsController>(this.cartService); this.fixture = new Fixture(); }