Ejemplo n.º 1
0
        public async Task GetOrderProductsInfoShouldReturnCollectionOfUserOrder()
        {
            //Arange
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            //Act
            var db     = new ApplicationDbContext(options);
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <ApplicationProfile>();
            });
            var mapper         = new Mapper(config);
            var cartservice    = new CartService(db);
            var productService = new ProductService(db, mapper);

            var user = new ApplicationUser
            {
                UserName     = "******",
                Email        = "*****@*****.**",
                PasswordHash = "abcdefg1"
            };
            var product = new Product
            {
                ProductCountry = ProductCountry.Bulgarian,
                Name           = "Musaka",
                Description    = "Yummi bulgarian meal",
                Image          = "https://amiraspantry.com/wp-content/uploads/2019/11/moussaka-I.jpg",
                Price          = 10,
                ProductType    = ProductType.Main
            };
            var product2 = new Product
            {
                ProductCountry = ProductCountry.Bulgarian,
                Name           = "Musaka2",
                Description    = "Yummi bulgarian meal2",
                Image          = "https://amiraspantry.com/wp-content/uploads/2019/11/moussaka-I.jpg",
                Price          = 10,
                ProductType    = ProductType.Main
            };

            db.Users.Add(user);
            db.Products.Add(product);
            db.Products.Add(product2);
            await db.SaveChangesAsync();

            await cartservice.AddCartToUserAsync(user.Id);

            await cartservice.AddProductsToCartAsync(product.Id, user.Id);

            await cartservice.AddProductsToCartAsync(product2.Id, user.Id);

            var productsModels = productService.GetOrderProductsInfo(user.Id);
        }
Ejemplo n.º 2
0
        public async Task GetCartProductsShouldReturnUserIfTheIdIsValid()
        {
            //Arange
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            //Act
            var db          = new ApplicationDbContext(options);
            var cartservice = new CartService(db);
            var user        = new ApplicationUser
            {
                UserName     = "******",
                Email        = "*****@*****.**",
                PasswordHash = "abcdefg1"
            };
            var product = new Product
            {
                ProductCountry = ProductCountry.Bulgarian,
                Name           = "Musaka",
                Description    = "Yummi bulgarian meal",
                Image          = "https://amiraspantry.com/wp-content/uploads/2019/11/moussaka-I.jpg",
                Price          = 10,
                ProductType    = ProductType.Main
            };

            db.Users.Add(user);
            db.Products.Add(product);
            await db.SaveChangesAsync();

            await cartservice.AddCartToUserAsync(user.Id);

            await cartservice.AddProductsToCartAsync(product.Id, user.Id);

            var userModel = cartservice.GetCartProducts(user.Id);

            //assert
            Assert.True(userModel != null);
        }