public async Task CheckGettingAllAsSelectListItemAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <Brand>(db);
            var service    = new BrandsService(repository);

            var firstBrand = new Brand()
            {
                Id = Guid.NewGuid().ToString()
            };
            var secondBrand = new Brand()
            {
                Id = Guid.NewGuid().ToString()
            };
            var thirdBrand = new Brand()
            {
                Id = Guid.NewGuid().ToString()
            };

            await db.Brands.AddAsync(firstBrand);

            await db.Brands.AddAsync(secondBrand);

            await db.Brands.AddAsync(thirdBrand);

            await db.SaveChangesAsync();

            var brands = await service.GetAllAsSelectListItemAsync();

            Assert.Equal(3, brands.Count());
        }
Ejemplo n.º 2
0
        public void CreateBrandShouldSetDeletedToFalseIfProductAlreadyExistsAndIsDeletedIsTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"CreateBrandShouldCreateBrand_Brand_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var mapper = this.SetUpAutoMapper();

            var brandService = new BrandsService(dbContext, mapper);

            var brandName  = Guid.NewGuid().ToString();
            var brandName1 = Guid.NewGuid().ToString();
            var model      = new CreateBrandBindingModel {
                Name = brandName
            };
            var model1 = new CreateBrandBindingModel {
                Name = brandName1
            };

            brandService.CreateBrand(model);
            brandService.CreateBrand(model1);

            var brandToRemove = dbContext.Brands.FirstOrDefault(x => x.Name == brandName);

            brandToRemove.IsDeleted = true;
            dbContext.Brands.Update(brandToRemove);
            dbContext.SaveChanges();

            var brand1 = brandService.CreateBrand(model);

            Assert.NotNull(brand1);
            Assert.True(brand1.IsDeleted == false);
        }
Ejemplo n.º 3
0
        public void RemoveBrandShouldSetIsDeletedToTrue()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"RemoveBrandShouldSetIsDeletedToTrue_Brand_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var mapper = this.SetUpAutoMapper();

            var brandService = new BrandsService(dbContext, mapper);

            var brandName  = Guid.NewGuid().ToString();
            var brandName1 = Guid.NewGuid().ToString();
            var model      = new CreateBrandBindingModel {
                Name = brandName
            };
            var model1 = new CreateBrandBindingModel {
                Name = brandName1
            };

            brandService.CreateBrand(model);
            brandService.CreateBrand(model1);
            brandService.RemoveBrand(model);
            var brand1 = brandService.CreateBrand(model);

            Assert.NotNull(brand1);
            Assert.True(brand1.IsDeleted == false);
        }
Ejemplo n.º 4
0
        public void FindAllBrandsShouldReturnOnlyBrandsWhereIsDeletedIsFalse()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"FindAllBrandsShouldReturnOnlyBrandsWhereIsDeletedIsFalse_Brand_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var mapper = this.SetUpAutoMapper();

            var brandService = new BrandsService(dbContext, mapper);

            var brandName  = Guid.NewGuid().ToString();
            var brandName1 = Guid.NewGuid().ToString();
            var brandName2 = Guid.NewGuid().ToString();
            var model      = new CreateBrandBindingModel {
                Name = brandName
            };
            var model1 = new CreateBrandBindingModel {
                Name = brandName1
            };
            var model2 = new CreateBrandBindingModel {
                Name = brandName2
            };

            brandService.CreateBrand(model);
            brandService.CreateBrand(model1);
            brandService.CreateBrand(model2);
            brandService.RemoveBrand(model);
            brandService.RemoveBrand(model1);

            var brands = brandService.FindAllBrands();

            Assert.True(brands.Count == 1);
        }
 public ConsumerBackgroundService(Serilog.ILogger logger, CategorysService categoryService,
                                  SpecificationsService specificationService,
                                  SpecificationsGroupService specificationGroupService,
                                  BrandsService brandsService,
                                  ProductsService productService,
                                  SKUService SKUService,
                                  SpecificationValuesService specificationValuesService,
                                  ProductSpecificationsService productSpecificationsService,
                                  SKUSpecificationsService SKUSpecificationsService,
                                  SKUFilesService SKUFilesService,
                                  InventoryService inventoryService,
                                  PricesService pricesService,
                                  MotosService motosService,
                                  FeedService feedService,
                                  OrderService ordersService)
 {
     _logger                       = logger;
     _categoryService              = categoryService;
     _specificationService         = specificationService;
     _specificationGroupService    = specificationGroupService;
     _brandsService                = brandsService;
     _productService               = productService;
     _SKUService                   = SKUService;
     _specificationValuesService   = specificationValuesService;
     _productSpecificationsService = productSpecificationsService;
     _SKUSpecificationsService     = SKUSpecificationsService;
     _SKUFilesService              = SKUFilesService;
     _inventoryService             = inventoryService;
     _pricesService                = pricesService;
     _motosService                 = motosService;
     _feedService                  = feedService;
     _ordersService                = ordersService;
 }
Ejemplo n.º 6
0
        public void CreateBrandCategoryViewModelByCategoriesAndBrandsShouldCreateBrandCategoryViewModelByCategoriesAndBrands()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"CreateBrandCategoryViewModelByCategoriesAndBrandsShouldCreateBrandCategoryViewModelByCategoriesAndBrands_Brand_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var mapper = this.SetUpAutoMapper();

            var brandService      = new BrandsService(dbContext, mapper);
            var categoriesService = new CategoriesService(dbContext, mapper);

            this.SeedDbWithCategories(dbContext);
            this.SeeDbdWithBrands(dbContext);

            var brands     = brandService.FindAllBrands();
            var categories = categoriesService.FindAllCategories();

            var model = new CategoryBrandViewModel {
                Brands = brands, Categories = categories
            };

            Assert.True(model.Brands.Count == 3 && model.Categories.Count == 3);
        }
Ejemplo n.º 7
0
        public async Task InsertBrandAsync()
        {
            IsBusy = true;

            var file = (await FileReaderService.CreateReference(inputReference).EnumerateFilesAsync()).FirstOrDefault();

            _fileInfo = await file.ReadFileInfoAsync();

            using (var ms = await file.CreateMemoryStreamAsync((int)_fileInfo.Size))
            {
                FileStream = ms;

                var result = await BrandsService.AddNewBrandAsync(Model, new AppFile
                {
                    FileStream = FileStream,
                    FileName   = _fileInfo.Name,
                    Name       = $"{Model.Name}{Path.GetExtension(_fileInfo.Name)}"
                });

                if (result.IsSuccess)
                {
                    AlertClass = "alert-success";
                    Message    = "Brand has been added successfully!";
                    brands.Add(result.Value);
                }
                else
                {
                    AlertClass = "alert-danger";
                    Message    = "There is something wrong";
                    Debug.WriteLine(result.Message);
                }
            }

            IsBusy = false;
        }
Ejemplo n.º 8
0
        private async Task GetBrandsAsync()
        {
            IsBusy = true;
            var result = await BrandsService.GetAllBrandsAsync();

            Brands = result.Values.ToList();
            IsBusy = false;
        }
        public void ReturnInstance_WhenParameterIsNotNull()
        {
            //Arrange
            var brands        = new Mock <IEfGenericRepository <Brand> >();
            var brandsService = new BrandsService(brands.Object);

            //Act & Assert
            Assert.IsInstanceOf <IBrandsService>(brandsService);
        }
        public void Throw_WhenPassedParameterIsNull()
        {
            //Arrange
            var brands        = new Mock <IEfGenericRepository <Brand> >();
            var brandsService = new BrandsService(brands.Object);

            //Act & Assert
            Assert.Throws <ArgumentNullException>(() => brandsService.Create(null));
        }
        public void Throw_WhenIdParameterIsInvalid()
        {
            // Arrange
            var brands         = new Mock <IEfGenericRepository <Brand> >();
            var invalidBrandId = 0;
            var brandsService  = new BrandsService(brands.Object);

            //Act & Assert
            Assert.Throws <ArgumentOutOfRangeException>(() => brandsService.GetById(invalidBrandId));
        }
Ejemplo n.º 12
0
        public async Task DeleteBrandShouldDeleteExistingBrand()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            await context.Brands.AddAsync(new Brand { Id = 10 });

            var service = new BrandsService(context);

            var success = await service.DeleteBrandAsync(10);

            Assert.True(success);
        }
        public void ReturnNull_WhenRepositoryMethodAll_ReturnsNull()
        {
            //Arrange
            var brands = new Mock <IEfGenericRepository <Brand> >();

            brands.Setup(x => x.All()).Returns(() => null);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            Assert.IsNull(result);
        }
        public void InvokeRepositoryMethodAddOnce_WhenPassedParameterIsValid()
        {
            //Arrange
            var brands = new Mock <IEfGenericRepository <Brand> >();

            brands.Setup(x => x.Add(It.IsAny <Brand>())).Verifiable();
            var brandsService = new BrandsService(brands.Object);
            var brand         = DataHelper.GetBrand();

            //Act
            brandsService.Create(brand);

            //Assert
            brands.Verify(x => x.Add(It.IsAny <Brand>()), Times.Once);
        }
Ejemplo n.º 15
0
        public async Task <List <Brand> > GetBrandsAsync()
        {
            IsBusy = true;
            await Task.Delay(1500);

            var response = await BrandsService.GetAllBrandsAsync();

            IsBusy = false;
            if (response.IsSuccess)
            {
                return(response.Values.ToList());
            }

            return(null);
        }
        public void InvokeRepositoryMethosAllOnce()
        {
            //Arrange
            var brands           = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollection = DataHelper.GetBrands();

            brands.Setup(x => x.All()).Returns(brandsCollection);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            brands.Verify(x => x.All(), Times.Once);
        }
        public void ReturnCorrectInstance()
        {
            //Arrange
            var brands           = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollection = DataHelper.GetBrands();

            brands.Setup(x => x.All()).Returns(brandsCollection);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            Assert.IsInstanceOf <IQueryable <Brand> >(result);
        }
Ejemplo n.º 18
0
        public async Task CreateBrandShouldCreateNewBrand()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: "TestDB").Options;

            using var context = new WHMSDbContext(options);
            var service = new BrandsService(context);

            var brandId = await service.CreateBrandAsync("TestBrand");

            var brandsCount   = service.GetAllBrandsCount();
            var expectedCount = 1;

            Assert.Equal(expectedCount, brandsCount);
            Assert.Equal(1, brandId);
        }
Ejemplo n.º 19
0
        public async Task DeleteBrandShouldReturnFalseBrandDoesNotExist()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            await context.Brands.AddAsync(new Brand { Name = "Test" });

            await context.SaveChangesAsync();

            var service = new BrandsService(context);

            var success = await service.DeleteBrandAsync(20);

            Assert.False(success);
        }
        public void ReturnCorrectModel()
        {
            //Arrange
            var brands           = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollection = DataHelper.GetBrands();

            brands.Setup(x => x.All()).Returns(brandsCollection);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, brandsCollection);
        }
        public void ReturnCorrectInstance()
        {
            //Arrange
            var brands  = new Mock <IEfGenericRepository <Brand> >();
            var brand   = DataHelper.GetBrand();
            var brandId = brand.Id;

            brands.Setup(x => x.GetById(It.IsAny <int>())).Returns(brand);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetById(brandId);

            //Assert
            Assert.IsInstanceOf <Brand>(result);
        }
        public void InvokeRepositoryMethosGetByIdOnce()
        {
            //Arrange
            var brands  = new Mock <IEfGenericRepository <Brand> >();
            var brand   = DataHelper.GetBrand();
            var brandId = brand.Id;

            brands.Setup(x => x.GetById(It.IsAny <int>())).Returns(brand);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetById(brandId);

            //Assert
            brands.Verify(x => x.GetById(It.IsAny <int>()), Times.Once);
        }
        public void ReturnCorrectCollectionCount()
        {
            //Arrange
            var brands = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollectionLast3 = DataHelper.GetBrands().Take(3);

            brands.Setup(x => x.Last3()).Returns(brandsCollectionLast3);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetLast3();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, brandsCollectionLast3);
            Assert.AreEqual(result.Count(), brandsCollectionLast3.Count());
        }
Ejemplo n.º 24
0
        public void FindAllBrandsShouldReturnAllBrands()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"FindAllBrandsShouldReturnAllBrands_Brand_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var mapper = this.SetUpAutoMapper();

            var brandService = new BrandsService(dbContext, mapper);

            this.SeeDbdWithBrands(dbContext);

            var brands = brandService.FindAllBrands();

            Assert.True(brands.Count == 3);
        }
Ejemplo n.º 25
0
        public void FindAllUserOrdersShouldReturnAllUserOrders()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"FindAllUserOrdersShouldReturnAllUserOrders_Orders_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var mapper = this.SetUpAutoMapper();

            var brandService         = new BrandsService(dbContext, mapper);
            var categoriesService    = new CategoriesService(dbContext, mapper);
            var usersService         = new UsersService(dbContext, mapper);
            var productsService      = new ProductsService(dbContext, mapper);
            var shoppingCartsService = new ShoppingCartsService(dbContext, productsService, usersService, mapper);
            var ordersService        = new OrdersService(dbContext, shoppingCartsService, mapper);
            var favouritesService    = new FavouritesService(dbContext, productsService, usersService, mapper);

            this.SeeDbdWithBrands(dbContext);
            this.SeedDbWithCategories(dbContext);

            var brands     = brandService.FindAllBrands();
            var categories = categoriesService.FindAllCategories();

            var image = new Mock <IFormFile>();

            this.SeedDbWithCountries(dbContext);
            this.SeedDbWithUserAndProduct(dbContext, productsService, mapper.Map <Category>(categories[0]), mapper.Map <Brand>(brands[0]), image.Object);

            var user     = dbContext.Users.FirstOrDefault(x => x.UserName == "1");
            var products = productsService.FindAllProducts();

            var shoppingCarts  = dbContext.ShoppingCarts;
            var shoppingCartss = dbContext.ShoppingCartProducts;

            var cart = this.SeedDbShoppingCartWithProducts(dbContext, user.UserName, products[0].Id);

            var model   = this.CreateOrderCreateBindingModel();
            var orderId = ordersService.CreateOrder(model, mapper.Map <ApplicationUserDTO>(user));
            var orders  = ordersService.FindAllUserOrders(mapper.Map <ApplicationUserDTO>(user));

            Assert.True(orders.Count == 1);
        }
        public void ReturnCorrectModelWithRightProperties()
        {
            //Arrange
            var brands           = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollection = DataHelper.GetBrands();

            brands.Setup(x => x.All()).Returns(brandsCollection);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, brandsCollection);
            Assert.AreEqual(result.FirstOrDefault().Id, brandsCollection.FirstOrDefault().Id);
            Assert.AreEqual(result.FirstOrDefault().Name, brandsCollection.FirstOrDefault().Name);
            Assert.AreEqual(result.FirstOrDefault().WebSite, brandsCollection.FirstOrDefault().WebSite);
        }
Ejemplo n.º 27
0
        public async Task GetAllBrandsShouldReturnMaxPageSize()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            for (int i = 0; i < 100; i++)
            {
                await context.Brands.AddAsync(new Brand { Name = i.ToString() });
            }

            await context.SaveChangesAsync();

            var service = new BrandsService(context);

            var brands         = service.GetAllBrands <BrandViewModel>(1);
            var brandsCount    = brands.ToList().Count();
            var exepcetedCount = GlobalConstants.PageSize;

            Assert.Equal(exepcetedCount, brandsCount);
        }
        public void ReturnCorrectModelWithRightProperties()
        {
            //Arrange
            var brands  = new Mock <IEfGenericRepository <Brand> >();
            var brand   = DataHelper.GetBrand();
            var brandId = brand.Id;

            brands.Setup(x => x.GetById(It.IsAny <int>())).Returns(brand);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetById(brandId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, brand);
            Assert.AreEqual(result.Id, brand.Id);
            Assert.AreEqual(result.Name, brand.Name);
            Assert.AreEqual(result.WebSite, brand.WebSite);
        }
Ejemplo n.º 29
0
        public void RemoveBrandShouldReturnNullIfBrandIsNull()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"RRemoveBrandShouldReturnNullIfBrandIsNull_Brand_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var mapper = this.SetUpAutoMapper();

            var brandService = new BrandsService(dbContext, mapper);

            var brandName = Guid.NewGuid().ToString();
            var model     = new CreateBrandBindingModel {
                Name = brandName
            };

            var brand = brandService.RemoveBrand(model);

            Assert.Null(brand);
        }
Ejemplo n.º 30
0
        public void CreateBrandShouldCreateBrand()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"CreateBrandShouldCreateBrand_Brand_Database")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var mapper = this.SetUpAutoMapper();

            var brandService = new BrandsService(dbContext, mapper);

            var brandName = Guid.NewGuid().ToString().Substring(0, 15);
            var model     = new CreateBrandBindingModel {
                Name = brandName
            };

            var brand = brandService.CreateBrand(model);

            Assert.True(dbContext.Brands.Count() == 1);
            Assert.True(brand.Name == brandName);
        }