Esempio n. 1
0
        public async Task AddComment_WithCorrectData_ShouldSuccessfullyAdd()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var contactRecordsRepository = new EfDeletableEntityRepository <ContactFormRecords>(context);

            var emailSender  = new FakeEmailSender();
            var forUsService = new ForUsService(contactRecordsRepository, emailSender);

            var email = new ContactFormViewModel()
            {
                FullName = "Павлина Якимова",
                Email    = "*****@*****.**",
                Content  = "Some content",
                Subject  = "Random subject",
            };

            // Act
            AutoMapperConfig.RegisterMappings(typeof(CreateCommentInputModel).Assembly);
            await forUsService.SendEmailToAdmin(email);

            var actual = context.ContactForms.Count();

            // Assert
            Assert.True(actual == 1, string.Format(ErrorMessage, "SendEmailToAdmin"));
        }
        public async Task TestGetAllComments_WithoutGivenType_ShouldReturnAllComments()
        {
            // 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 seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedCommentsAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(AllAccessorieViewModel).Assembly);
            var result   = commentServices.GetAllComments <IndexCommentViewModel>("abc");
            var expected = result.ToList().Count;
            var actual   = context.Comments.Count();

            // Assert
            Assert.True(expected == actual, string.Format(ErrorMessage, "GetAllCooments"));
        }
        public async Task AddAnswerToComment_WithCorrectData_ShouldSuccessfullyAdd()
        {
            // 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 seeder = new DbContextTestsSeeder();
            await seeder.SeedUsersAsync(context);

            await seeder.SeedGroupAsync(context);

            await seeder.SeedCommentsAsync(context);

            // Act
            AutoMapperConfig.RegisterMappings(typeof(CreateCommentInputModel).Assembly);
            var result   = commentServices.CreateAnswer("Тестов отговор", "comId1");
            var expected = "Тестов отговор";
            var actual   = context.Comments.SingleOrDefault(c => c.Id == "comId1").Answer;

            // Assert
            AssertExtension.EqualsWithMessage(actual, expected, string.Format(ErrorMessage, "CreateAnswer"));
        }
        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));
        }
Esempio n. 5
0
        public async Task AddAnswerToComment_WithNoneExistingEmailId_ShouldThrowsException()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var contactRecordsRepository = new EfDeletableEntityRepository <ContactFormRecords>(context);

            var emailSender  = new FakeEmailSender();
            var forUsService = new ForUsService(contactRecordsRepository, emailSender);

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

            await Assert.ThrowsAsync <NullReferenceException>(() => forUsService.SendAnswer("Тестов Отговор", "Test Id"));
        }
Esempio n. 6
0
        public async Task AddAnswerToComment_WithCorrectData_ShouldSuccessfullyAdd()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var contactRecordsRepository = new EfDeletableEntityRepository <ContactFormRecords>(context);

            var emailSender  = new FakeEmailSender();
            var forUsService = new ForUsService(contactRecordsRepository, emailSender);

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

            // Act
            var result   = forUsService.SendAnswer("Тестов отговор", "comId1");
            var expected = "Тестов отговор";
            var actual   = context.ContactForms.SingleOrDefault(c => c.Id == "comId1").Answer;

            // Assert
            AssertExtension.EqualsWithMessage(actual, expected, string.Format(ErrorMessage, "CreateAnswer"));
        }
Esempio n. 7
0
        public async Task TestGetAllComments_WithGivenType_ShouldReturnAllComments()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var contactRecordsRepository = new EfDeletableEntityRepository <ContactFormRecords>(context);

            var emailSender  = new FakeEmailSender();
            var forUsService = new ForUsService(contactRecordsRepository, emailSender);

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

            AutoMapperConfig.RegisterMappings(typeof(CreateCommentInputModel).Assembly);
            var result   = forUsService.GetAllSendEmails <ContactFormViewModel>();
            var expected = result.ToList().Count;
            var actual   = context.ContactForms.Count();

            // Assert
            Assert.True(expected == actual, string.Format(ErrorMessage, "GetAllContactForm emails"));
        }