Beispiel #1
0
        public async Task CategoryById()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstProduct = new Product {
                Id = 1, Name = "First"
            };
            var secondProduct = new Product {
                Id = 2, Name = "Second"
            };
            var thirdProduct = new Product {
                Id = 3, Name = "Third"
            };

            db.AddRange(firstProduct, secondProduct, thirdProduct);

            await db.SaveChangesAsync();

            var categoriesService       = new AdminCategoryService(db);
            var moderatorProductService = new ModeratorProductService(db, categoriesService);
            // Act
            var result = moderatorProductService.ById(3);


            // Assert
            result
            .Name
            .Should()
            .Equals("Third");
        }
Beispiel #2
0
        public async Task EditProduct()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstProduct = new Product {
                Id = 5, Name = "First", ImageUrl = "http://test", Price = 2.0m, Quantity = 5, Description = "test description"
            };

            db.AddRange(firstProduct);

            await db.SaveChangesAsync();

            var categoriesService       = new AdminCategoryService(db);
            var moderatorProductService = new ModeratorProductService(db, categoriesService);
            // Act
            await moderatorProductService.Edit(5, "changed", "http://changed", 3.0m, 10, "changed description");

            var result = moderatorProductService.ById(5);


            // Assert
            result
            .Name
            .Should()
            .Equals("changed");
        }
Beispiel #3
0
        public async Task GetCategoriesAsync_WithSomeCategories_ShouldReturnAll()
        {
            //Arrange
            this.DbContext.Categories.Add(new Category()
            {
                Id = 1, Name = "First category"
            });
            this.DbContext.Categories.Add(new Category()
            {
                Id = 2, Name = "Second category"
            });
            this.DbContext.Categories.Add(new Category()
            {
                Id = 3, Name = "Third category"
            });
            this.DbContext.SaveChanges();

            var service = new AdminCategoryService(this.DbContext, this.Mapper, null);

            //Act
            var categories = await service.GetCategoriesAsync();

            //Assert
            Assert.IsNotNull(categories);
            Assert.AreEqual(3, categories.Count());
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, categories.Select(c => c.Id).ToArray());
        }
Beispiel #4
0
        public async Task CreateProduct()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstProduct = new Product {
                Id = 5, Name = "First"
            };
            var secondProduct = new Product {
                Id = 6, Name = "Second"
            };
            var thirdProduct = new Product {
                Id = 7, Name = "Third"
            };
            var category = new Category {
                Id = 1, Name = "category"
            };

            db.AddRange(firstProduct, secondProduct, thirdProduct, category);

            await db.SaveChangesAsync();

            var categoriesService       = new AdminCategoryService(db);
            var moderatorProductService = new ModeratorProductService(db, categoriesService);
            // Act
            await moderatorProductService.CreateAsync("http://test", "test", 2.0m, "test description", 5, 1);

            var result = db.Products.Count();


            // Assert
            result
            .Should()
            .Equals(4);
        }
Beispiel #5
0
        public async Task EditShouldReturnDbWithEditedItem()
        {
            // Arrange
            var db = this.Context;

            this.PopulateData(db);

            var categoriesService = new AdminCategoryService(db);
            var categoryId        = 1;
            var newName           = "newoneboiiiiii";

            // Act
            await categoriesService.Edit(categoryId, newName);

            // Assert
            db
            .Categories
            .Where(c => c.Id == categoryId)
            .FirstOrDefault()
            .Should()
            .NotBe(null);

            db
            .Categories
            .Where(c => c.Id == categoryId)
            .Select(c => c.Name)
            .FirstOrDefault()
            .Should()
            .Be(newName);
        }
Beispiel #6
0
        public async Task DeleteProduct()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstProduct = new Product {
                Id = 5, Name = "First"
            };
            var secondProduct = new Product {
                Id = 6, Name = "Second"
            };
            var thirdProduct = new Product {
                Id = 7, Name = "Third"
            };

            db.AddRange(firstProduct, secondProduct, thirdProduct);

            await db.SaveChangesAsync();

            var categoriesService       = new AdminCategoryService(db);
            var moderatorProductService = new ModeratorProductService(db, categoriesService);
            // Act
            await moderatorProductService.Delete(5);

            var result = db.Products.Count();


            // Assert
            result
            .Should()
            .Equals(3);
        }
Beispiel #7
0
        public async Task ShowingAllCategories()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstCategory = new Category {
                Id = 1, Name = "First"
            };
            var secondCategory = new Category {
                Id = 2, Name = "Second"
            };
            var thirdCategory = new Category {
                Id = 3, Name = "Third"
            };

            db.AddRange(firstCategory, secondCategory, thirdCategory);

            await db.SaveChangesAsync();

            var adminCategoryService = new AdminCategoryService(db);
            // Act
            var result = await adminCategoryService.AllAsync();


            // Assert
            result
            .Should()
            .HaveCount(3);
        }
Beispiel #8
0
        public async Task EditCategory()
        {
            // Arrange
            var db = this.GetDatabase();

            var category = new Category {
                Id = 1, Name = "test", PictureUrl = "https://test"
            };

            db.Add(category);

            await db.SaveChangesAsync();

            var adminCategoryService = new AdminCategoryService(db);
            // Act

            await adminCategoryService.EditAsync(1, "changed", "https://changed");

            await db.SaveChangesAsync();

            var result = adminCategoryService.ById(1);


            // Assert
            result
            .Name
            .Should()
            .Equals("changed");
        }
Beispiel #9
0
        public async Task CategoryById()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstCategory = new Category {
                Id = 1, Name = "First"
            };
            var secondCategory = new Category {
                Id = 2, Name = "Second"
            };
            var thirdCategory = new Category {
                Id = 3, Name = "Third"
            };

            db.AddRange(firstCategory, secondCategory, thirdCategory);

            await db.SaveChangesAsync();

            var adminCategoryService = new AdminCategoryService(db);
            // Act
            var result = adminCategoryService.ById(3);


            // Assert
            result
            .Name
            .Should()
            .Equals("Third");
        }
Beispiel #10
0
        public async Task DeleteCategory()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstCategory = new Category {
                Id = 1, Name = "test1"
            };
            var secondCategory = new Category {
                Id = 2, Name = "test2"
            };
            var thirdCategory = new Category {
                Id = 3, Name = "test3"
            };

            db.AddRange(firstCategory, secondCategory, thirdCategory);

            await db.SaveChangesAsync();

            var adminCategoryService = new AdminCategoryService(db);
            // Act

            await adminCategoryService.Delete(1);

            await db.SaveChangesAsync();

            var result = await adminCategoryService.AllAsync();


            // Assert
            result
            .Should()
            .HaveCount(2);
        }
Beispiel #11
0
        public async Task DeleteShouldReturnDbWithoutThatItem()
        {
            // Arrange
            var db = this.Context;

            this.PopulateData(db);

            var categoriesService = new AdminCategoryService(db);
            var categoryId        = 1;

            // Act
            await categoriesService.Delete(categoryId);

            // Assert
            db
            .Categories
            .Where(c => c.Id == categoryId)
            .FirstOrDefault()
            .Should()
            .Be(null);

            db
            .Categories
            .Count()
            .Should()
            .Be(2);
        }
Beispiel #12
0
        public async Task CreateShouldReturnDbWithThatItem()
        {
            // Arrange
            var db = this.Context;

            var categoriesService = new AdminCategoryService(db);
            var newName           = "forthetestname";

            // Act
            await categoriesService.Create(newName);

            // Assert
            db
            .Categories
            .Where(c => c.Name == newName)
            .FirstOrDefault()
            .Should()
            .NotBe(null);

            db
            .Categories
            .Where(c => c.Name == newName)
            .Select(c => c.Id)
            .FirstOrDefault()
            .Should()
            .Be(1);
        }
        public async Task DeleteShouldReturnFalseWithInvalidId()
        {
            // Arrange
            //Tests.Initialize();
            var adminCategoryService = new AdminCategoryService(this.db);

            // Act
            var result = await adminCategoryService.Delete(10);

            // Assert
            result.Should().Be(false);
        }
Beispiel #14
0
        public async Task GetCategoriesAsync_WithZeroCategories_ShouldReturnNone()
        {
            //Arrange
            var service = new AdminCategoryService(this.DbContext, this.Mapper, null);

            //Act
            var categories = await service.GetCategoriesAsync();

            //Assert
            Assert.IsNotNull(categories);
            Assert.AreEqual(0, categories.Count());
        }
Beispiel #15
0
        public void NameExists_WithExistingName_ShouldReturnTrue()
        {
            //Arrange
            this.DbContext.Categories.Add(new Category()
            {
                Id = 1, Name = "First category"
            });
            this.DbContext.SaveChanges();
            var service = new AdminCategoryService(this.DbContext, this.Mapper, null);

            //Act
            bool result = service.NameExits("First category");

            //Assert
            Assert.IsTrue(result);
        }
        public async Task DeleteShouldReturnCorrectResults()
        {
            // Arrange
            //Tests.Initialize();
            var adminCategoryService = new AdminCategoryService(this.db);

            // Act
            var categoriesCountBefore = this.db.Categories.Count();
            var result = await adminCategoryService.Delete(1);
            var categoriesCountAfter = this.db.Categories.Count();

            // Assert
            result.Should().Be(true);
            categoriesCountBefore.Should().Be(1);
            categoriesCountAfter.Should().Be(0);
        }
Beispiel #17
0
        public async Task CreatingCategories()
        {
            // Arrange
            var db = this.GetDatabase();


            var adminCategoryService = new AdminCategoryService(db);
            // Act
            await adminCategoryService.CreateAsync("test", "https://test");

            var result = await adminCategoryService.AllAsync();


            // Assert
            result
            .Should()
            .HaveCount(1);
        }
Beispiel #18
0
        public async Task FindNameShouldReturnNameOfTheCategory()
        {
            // Arrange
            var db = this.Context;

            this.PopulateData(db);

            var categoriesService = new AdminCategoryService(db);
            var categoryId        = 1;

            // Act
            var result = await categoriesService.FindName(categoryId);

            // Assert
            result
            .Should()
            .Be("firstOne");
        }
Beispiel #19
0
        public async Task ExistsShouldReturnBooleanDependsIfItemIsInDb()
        {
            // Arrange
            var db = this.Context;

            this.PopulateData(db);

            var categoriesService = new AdminCategoryService(db);
            var categoryId        = 1;

            // Act
            var result = await categoriesService.Exists(categoryId);

            // Assert
            result
            .Should()
            .Be(true);
        }
Beispiel #20
0
        public void AllShouldReturnCollectionOfAllItems()
        {
            // Arrange
            Mapper.Initialize(config => config.AddProfile <AutoMapperProfile>());
            var db = this.Context;

            this.PopulateData(db);

            var categoriesService = new AdminCategoryService(db);

            // Act
            var result = categoriesService.All();

            // Assert
            result
            .Should()
            .Match(r => r.ElementAt(0).Id == 1 &&
                   r.ElementAt(1).Id == 2 &&
                   r.ElementAt(2).Id == 3)
            .And
            .HaveCount(3);
        }
Beispiel #21
0
        public async Task ByIdShouldReturnTheItemThatIsCalled()
        {
            // Arrange
            //Mapper.Initialize(config => config.AddProfile<AutoMapperProfile>());
            var db = this.Context;

            this.PopulateData(db);

            var categoriesService = new AdminCategoryService(db);
            var categoryId        = 1;

            // Act
            var result = await categoriesService.ById(categoryId);

            // Assert
            result
            .Should()
            .NotBe(null);

            result
            .Name
            .Should()
            .Be("firstOne");
        }
 public void InitializeTests()
 {
     this.dbContext = MockDbContext.GetContext();
     this.service   = new AdminCategoryService(dbContext, MockAutoMapper.GetMapper());
 }