Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public void CreateBrandShouldntCreateBrandAndShouldReturnNullIfAlreadyExists()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"CreateBrandShouldntCreateBrandAndShouldReturnNullIfAlreadyExists_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
            };

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

            Assert.True(dbContext.Brands.Count() == 1);
            Assert.Null(brand1);
        }
Пример #5
0
        public void RemoveBrandShouldReturnNullIfBrandsCountIs1()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: $"RemoveBrandShouldReturnNullIfBrandsCountIs1_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
            };

            brandService.CreateBrand(model);
            var brand = brandService.RemoveBrand(model);

            Assert.Null(brand);
        }
Пример #6
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);
        }