public async Task TestGetAllFireplaces_WithoutGivenType_ShouldReturnAllFireplaces()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplacesRepository   = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);

            var groupService   = new GroupService(groupRepository);
            var prodcutService = new ProductService(productRepository, groupService);
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var cloudinaryService            = new FakeCloudinary();
            var fireplaceService             = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(AllFireplaceViewModel).Assembly);
            var result = fireplaceService.GetAllFireplace <AllFireplaceViewModel>();
            var count  = result.ToList().Count;
            var actual = context.Fireplace_Chambers.Count();

            // Assert
            Assert.True(count == actual, string.Format(ErrorMessage, "Get all user with data"));
        }
        public async Task AddSuggestProduct_ToNoneExistingFireplaceId_ShouldThrowException()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplacesRepository   = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);

            var groupService   = new GroupService(groupRepository);
            var prodcutService = new ProductService(productRepository, groupService);
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var cloudinaryService            = new FakeCloudinary();
            var fireplaceService             = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            string[] selectedFireplace = new string[] { "Гк Оливия" };

            // Act and Asseart
            AutoMapperConfig.RegisterMappings(typeof(DeleteFireplaceViewModel).Assembly);
            await Assert.ThrowsAsync <NullReferenceException>(() => fireplaceService.AddSuggestionToFireplaceAsync("Гк Мая", "Test id", selectedFireplace, null, null, null));
        }
        public async Task TestGetCountOfPageByTypeOfChamber_WithCorrectDate_ShouldReturenCorrectCount()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplacesRepository   = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);

            var groupService   = new GroupService(groupRepository);
            var prodcutService = new ProductService(productRepository, groupService);
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var cloudinaryService            = new FakeCloudinary();
            var fireplaceService             = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            // Act
            var result = fireplaceService.GetCountByTypeOfChamber(TypeOfChamber.Basic.ToString());

            // Assert
            Assert.True(result == 2, string.Format(ErrorMessage, string.Format(ErrorMessage, "GetCountByTypeOfChamber")));
        }
        public async Task TestGetFireplaceById_WithNoneExistingireplaceId_ShouldReturnNull()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplacesRepository   = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);

            var groupService   = new GroupService(groupRepository);
            var prodcutService = new ProductService(productRepository, groupService);
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var cloudinaryService            = new FakeCloudinary();
            var fireplaceService             = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

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

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => fireplaceService.GetById <DetailsFireplaceViewModel>("Тестово id"));
        }
        public async Task DeleteFireplace_WithNonExistingFireplace_ShouldThrowException()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplacesRepository   = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);

            var groupService   = new GroupService(groupRepository);
            var prodcutService = new ProductService(productRepository, groupService);
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var cloudinaryService            = new FakeCloudinary();
            var fireplaceService             = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);

            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 fireplace = new DeleteFireplaceViewModel
            {
                Id            = "Test Id",
                Power         = "10w",
                Chimney       = "200Ф",
                Description   = "Some description test 1",
                ImagePath     = "Some dummy data",
                Price         = 1800.00M,
                Size          = "60 / 40 / h50",
                TypeOfChamber = TypeOfChamber.Basic.ToString(),
                Name          = "Гк Мая",
            };

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(DeleteFireplaceViewModel).Assembly);
            await Assert.ThrowsAsync <NullReferenceException>(() => fireplaceService.DeleteAsync <DeleteFireplaceViewModel>(fireplace));
        }
        public async Task AddComment_WithNoneExistingProduct_ShouldThrowException()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplaceRepository    = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);
            var commentsRepository     = new EfDeletableEntityRepository <Comment>(context);

            var groupService                 = new GroupService(groupRepository);
            var prodcutService               = new ProductService(productRepository, groupService);
            var cloudinaryService            = new FakeCloudinary();
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var emailSender      = new FakeEmailSender();
            var fireplaceService = new FireplaceService(fireplaceRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);
            var commentServices  = new CommentService(commentsRepository, prodcutService, fireplaceService, emailSender);

            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 comment = new CreateCommentInputModel()
            {
                FullName    = "Павлина Якимова",
                Email       = "*****@*****.**",
                Content     = "Тестов коментар",
                ProductId   = "abc1",
                ProductName = "Тестово име",
            };

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(CreateCommentInputModel).Assembly);
            await Assert.ThrowsAsync <ArgumentNullException>(() => commentServices.Create(comment));
        }
        public async Task EditFinishedModel_WithNonExistingFireplace_ShouldThrowException()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository          = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository        = new EfDeletableEntityRepository <Product>(context);
            var finishedModelsRepository = new EfDeletableEntityRepository <Finished_Model>(context);

            var groupService          = new GroupService(groupRepository);
            var prodcutService        = new ProductService(productRepository, groupService);
            var cloudinaryService     = new FakeCloudinary();
            var finishedModelsService = new FinishedModelService(finishedModelsRepository, 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 finishedModel = new EditFinishedModelViewModel
            {
                Id          = "Test Id",
                Description = "Some description test 1",
                TypeProject = TypeProject.Classic.ToString(),
                Name        = "Model 1",
            };

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(EditFinishedModelViewModel).Assembly);
            await Assert.ThrowsAsync <NullReferenceException>(() => finishedModelsService.EditAsync <EditFinishedModelViewModel>(finishedModel));
        }
        public async Task TestGetFireplace_WithExistingFireplaceName_ShouldReturnFireplace()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplacesRepository   = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);

            var groupService   = new GroupService(groupRepository);
            var prodcutService = new ProductService(productRepository, groupService);
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var cloudinaryService            = new FakeCloudinary();
            var fireplaceService             = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(DetailsFireplaceViewModel).Assembly);
            var expected     = context.Fireplace_Chambers.SingleOrDefault(fireplace => fireplace.Product.Name == "Гк Мая");
            var actualResult = fireplaceService.GetByName <DetailsFireplaceViewModel>("Гк Мая");

            // Assert
            AssertExtension.EqualsWithMessage(expected.Product.Name, actualResult.Name, string.Format(ErrorMessage, "GetFireplace with name, returns name"));
            AssertExtension.EqualsWithMessage(expected.Power, actualResult.Power, string.Format(ErrorMessage, "GetFireplace with name, returns power"));
            AssertExtension.EqualsWithMessage(expected.Chimney, actualResult.Chimney, string.Format(ErrorMessage, "GetFireplace with name, returns chimney"));
            Assert.Equal(expected.Price, actualResult.Price);
            AssertExtension.EqualsWithMessage(expected.Description, actualResult.Description, string.Format(ErrorMessage, "GetFireplace with name, returns description"));
            AssertExtension.EqualsWithMessage(expected.ImagePath, actualResult.ImagePath, string.Format(ErrorMessage, "GetFireplace with name, returns ImagePath"));
        }
        public async Task AddSuggestProduct_WithCorrectData_ShouldSuccessfullyAddSuggestion()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplacesRepository   = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);

            var groupService   = new GroupService(groupRepository);
            var prodcutService = new ProductService(productRepository, groupService);
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var cloudinaryService            = new FakeCloudinary();
            var fireplaceService             = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            string[] selectedFireplace = new string[] { "Гк Оливия" };

            // Act
            AutoMapperConfig.RegisterMappings(typeof(FireplaceInputModel).Assembly);
            await fireplaceService.AddSuggestionToFireplaceAsync("Гк Мая", "abc1", selectedFireplace, null, null, null);

            var count = context.SuggestProducts.Count();

            // Assert
            Assert.True(count == 1, string.Format(ErrorMessage, "Add suggestion method"));
        }
        public async Task EditFireplace_WithCorrectData_ShouldSuccessfullyEdit()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var groupRepository        = new EfDeletableEntityRepository <Product_Group>(context);
            var productRepository      = new EfDeletableEntityRepository <Product>(context);
            var fireplacesRepository   = new EfDeletableEntityRepository <Fireplace_chamber>(context);
            var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context);

            var groupService   = new GroupService(groupRepository);
            var prodcutService = new ProductService(productRepository, groupService);
            var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory);
            var cloudinaryService            = new FakeCloudinary();
            var fireplaceService             = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService);

            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 fireplace = new EditFireplaceViewModel
            {
                Id            = "abc1",
                Power         = "10w",
                Chimney       = "200Ф",
                Description   = "Some description test 1",
                ImagePath     = file,
                Price         = 1800.00M,
                Size          = "60 / 40 / h50",
                TypeOfChamber = TypeOfChamber.Basic.ToString(),
                Name          = "Гк Мая сменено",
            };

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

            await seeder.SeedGroupAsync(context);

            await seeder.SeedProdcutAsync(context);

            await seeder.SeedFireplacesAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(EditFireplaceViewModel).Assembly);
            var result = await fireplaceService.EditAsync <EditFireplaceViewModel>(fireplace);

            var actual = context.Fireplace_Chambers.FirstOrDefault(x => x.Product.Name == "Гк Мая сменено");

            var expectedName          = "Гк Мая сменено";
            var expectedPower         = "10w";
            var expectedChimney       = "200Ф";
            var expectedPrice         = 1800.00M;
            var expectedSize          = "60 / 40 / h50";
            var expectedTypeOfChamber = TypeOfChamber.Basic.ToString();

            // Assert
            AssertExtension.EqualsWithMessage(expectedName, actual.Product.Name, string.Format(ErrorMessage, "AddFireplace returns correct Name"));
            AssertExtension.EqualsWithMessage(expectedPower, actual.Power, string.Format(ErrorMessage, "AddFireplace returns correct Power"));
            AssertExtension.EqualsWithMessage(expectedChimney, actual.Chimney, string.Format(ErrorMessage, "AddFireplace returns correct Chimney"));
            Assert.Equal(expectedPrice, actual.Price);
            AssertExtension.EqualsWithMessage(expectedSize, actual.Size, string.Format(ErrorMessage, "AddFireplace returns correct Size"));
            AssertExtension.EqualsWithMessage(expectedTypeOfChamber, actual.TypeOfChamber.ToString(), string.Format(ErrorMessage, "AddFireplace returns correct TypeOfChamber"));
        }