コード例 #1
0
        public async Task TestGetCountOfPage_WithCorrectDate_ShouldReturenCorrectCount()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository      = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository    = new EfDeletableEntityRepository <Product>(context);
            var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService);

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedAccessorieAsync(context);

            // Act
            var expected = accessorieService.GetCount();
            var actual   = context.Accessories.Count();

            // Assert
            Assert.True(expected == actual, string.Format(ErrorMessage, string.Format(ErrorMessage, "GetCount")));
        }
コード例 #2
0
        public async Task TestGetAccessorie_WithExistingAccessorieName_ShouldReturnAccessorie()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository      = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository    = new EfDeletableEntityRepository <Product>(context);
            var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService);

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedAccessorieAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(DetailsAccessorieViewModel).Assembly);
            var expected     = context.Accessories.SingleOrDefault(accessorie => accessorie.Product.Name == "Аксесоар 1");
            var actualResult = accessorieService.GetByName <DetailsAccessorieViewModel>("Аксесоар 1");

            // Assert
            AssertExtension.EqualsWithMessage(expected.Product.Name, actualResult.Name, string.Format(ErrorMessage, "GetAccessorie with name, returns name"));
            AssertExtension.EqualsWithMessage(expected.Description, actualResult.Description, string.Format(ErrorMessage, "GetAccessorie with name, returns description"));
            AssertExtension.EqualsWithMessage(expected.ImagePath, actualResult.ImagePath, string.Format(ErrorMessage, "GetAccessorie with name, returns ImagePath"));
        }
コード例 #3
0
        public async Task TestGetAccessorieById_WithNoneExistingAccessorieId_ShouldReturnNull()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository      = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository    = new EfDeletableEntityRepository <Product>(context);
            var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService);

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedAccessorieAsync(context);

            AutoMapperConfig.RegisterMappings(typeof(DetailsAccessorieViewModel).Assembly);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => accessorieService.GetById <DetailsAccessorieViewModel>("Тестово id"));
        }
コード例 #4
0
        public async Task TestGetAllAccessorie_WithGivenType_ShouldReturnAllAccessorie()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository      = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository    = new EfDeletableEntityRepository <Product>(context);
            var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService);

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedAccessorieAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(AllAccessorieViewModel).Assembly);
            var result   = accessorieService.GetAllAccessorieAsync <AllAccessorieViewModel>();
            var expected = result.ToList().Count;
            var actual   = context.Accessories.Count();

            // Assert
            Assert.True(expected == actual, string.Format(ErrorMessage, "GetAllAccessorie"));
        }
コード例 #5
0
        public async Task EditProject_WithCorrectData_ShouldSuccessfullyEdit()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository      = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository    = new EfDeletableEntityRepository <Product>(context);
            var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService);

            var user = new ApplicationUser
            {
                Id             = "abc",
                FirstName      = "Nikolay",
                LastName       = "Doychev",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };

            var       fileName = "Img";
            IFormFile file     = new FormFile(
                new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")),
                0,
                0,
                fileName,
                "dummy.png");

            var accessorie = new EditAccessorieViewModel
            {
                Id          = "abc1",
                Description = "Some description test 1",
                ImagePath   = file,
                Name        = "Аксесоар 1 сменено",
            };

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedAccessorieAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(EditAccessorieViewModel).Assembly);
            var result = await accessorieService.EditAsync <EditAccessorieViewModel>(accessorie);

            var actual = context.Accessories.FirstOrDefault(x => x.Product.Name == "Аксесоар 1 сменено");

            var expectedName        = "Аксесоар 1 сменено";
            var expectedDescription = "Some description test 1";

            // Assert
            AssertExtension.EqualsWithMessage(expectedName, actual.Product.Name, string.Format(ErrorMessage, "EditAccessorie returns correct Name"));
            AssertExtension.EqualsWithMessage(expectedDescription, actual.Description, string.Format(ErrorMessage, "EditAccessorie returns correct Description"));
        }
コード例 #6
0
        public async Task DeleteProject_WithCorrectData_ShouldSuccessfullyDelete()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository      = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository    = new EfDeletableEntityRepository <Product>(context);
            var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService);

            var user = new ApplicationUser
            {
                Id             = "abc",
                FirstName      = "Nikolay",
                LastName       = "Doychev",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };

            var       fileName = "Img";
            IFormFile file     = new FormFile(
                new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")),
                0,
                0,
                fileName,
                "dummy.png");

            var project = new DeleteAccessorieViewModel
            {
                Id          = "abc1",
                Description = "Some description test 1",
                Name        = "Проект 1",
                ImagePath   = fileName,
            };

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedAccessorieAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(DeleteAccessorieViewModel).Assembly);
            await accessorieService.DeleteAsync <DeleteAccessorieViewModel>(project);

            int actual = context.Accessories.Count();

            // Assert
            Assert.True(actual == 1, string.Format(ErrorMessage, "DeleteAccessorie method"));
        }
コード例 #7
0
        public async Task DeleteAccessorie_WithNonExistingAccessorie_ShouldThrowException()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository      = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository    = new EfDeletableEntityRepository <Product>(context);
            var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context);

            var groupService      = new GroupService(groupRepository);
            var prodcutService    = new ProductService(productRepository, groupService);
            var cloudinaryService = new FakeCloudinary();
            var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService);

            var user = new ApplicationUser
            {
                Id             = "abc",
                FirstName      = "Nikolay",
                LastName       = "Doychev",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };

            var       fileName = "Img";
            IFormFile file     = new FormFile(
                new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")),
                0,
                0,
                fileName,
                "dummy.png");

            var accessorie = new DeleteAccessorieViewModel
            {
                Id          = "Test Id",
                Description = "Some description test 1",
                ImagePath   = "Some dummy data",
                Name        = "Проект 1",
            };

            var seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedAccessorieAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(DeleteAccessorieViewModel).Assembly);
            await Assert.ThrowsAsync <NullReferenceException>(() => accessorieService.DeleteAsync <DeleteAccessorieViewModel>(accessorie));
        }