Exemple #1
0
        public void TestGetAll()
        {
            var firstComment  = CommentBuilder.New().WithContent("FirstComment").Build();
            var secondComment = CommentBuilder.New().WithContent("SecondComment").Build();
            var thirdComment  = CommentBuilder.New().WithContent("ThirdComment").Build();

            var resultValidationFirst  = new CommentValidator().Validate(firstComment);
            var resultValidationSecond = new CommentValidator().Validate(secondComment);
            var resultValidationThird  = new CommentValidator().Validate(thirdComment);

            // Conhecimento MemoryCache
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(120);
            memoryCache.Add("firstComment", firstComment, policy);
            memoryCache.Add("secondComment", secondComment, policy);
            memoryCache.Add("thirdComment", thirdComment, policy);
            Assert.IsTrue(3 == memoryCache.GetCount());

            // Produção através dos métodos
            new CreateComment().CreateNewRegister(firstComment);
            new CreateComment().CreateNewRegister(secondComment);
            new CreateComment().CreateNewRegister(thirdComment);
            List <Comment> listComments = new GetComment().GetAllRegister();

            Assert.IsTrue(3 == listComments.Count);
        }
Exemple #2
0
        public void TestUpdate()
        {
            var comment = CommentBuilder.New().Build();

            // Conhecimento MemoryCache
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(120);
            memoryCache.Add("commentUpdate", comment, policy);
            Comment commentGet = (Comment)memoryCache["commentUpdate"];

            Assert.AreEqual(comment.ToString(), commentGet.ToString());

            var secondComment = CommentBuilder.New().WithContent("AnotherContent").Build();

            memoryCache.Set("commentUpdate", secondComment, policy);
            commentGet = (Comment)memoryCache["commentUpdate"];
            Assert.IsTrue(comment.Content.ToString() != commentGet.Content.ToString());

            // Produção através dos métodos
            new CreateComment().CreateNewRegister(comment);
            var commentCopia = new GetComment().GetRegisterById(comment.Id);
            var thirdComment = CommentBuilder.New().WithId(commentCopia.Id).WithContent("SecondContent").Build();

            new UpdateComment().UpdateRegister(thirdComment);
            Assert.IsTrue(thirdComment.Content.ToString() != comment.Content.ToString());
        }
Exemple #3
0
        public void GetByIdReturnsBadRequest()
        {
            var comment = CommentBuilder.New().Build();

            var result = controller.Get(comment.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
Exemple #4
0
        public void TestCreateWithId()
        {
            var comment = CommentBuilder.New().WithId(new Guid()).Build();

            Assert.True(comment.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"));
            Assert.True(comment.Autor.Id != Guid.Empty && comment.Autor.Id != null);
            Assert.True(comment.Content == "TestContent");
            Assert.True(comment.PublicationId != null && comment.PublicationId != Guid.Empty);
        }
Exemple #5
0
        public void GetByIdReturnsOk()
        {
            var comment = CommentBuilder.New().Build();

            creator.CreateNewRegister(comment);

            var result = controller.Get(comment.Id);

            Assert.IsType <OkObjectResult>(result.Result);
        }
Exemple #6
0
        public void PutReturnsBadRequest_CommentInvalid()
        {
            var comment = CommentBuilder.New().Build();

            creator.CreateNewRegister(comment);

            var result = controller.Put(comment.Id, "");

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
Exemple #7
0
        public void PutReturnsBadRequest_CommentNotExistOnDatabase()
        {
            var comment = CommentBuilder.New().Build();

            new CreateComment().CreateNewRegister(comment);

            var result = controller.Put(Guid.NewGuid(), "Conteudo");

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
Exemple #8
0
        public void TestValidationCommentWithInvalidTopic()
        {
            var okUser = UserBuilder.New().Build();

            new UserRepository().Create(okUser);

            var badComment1 = CommentBuilder.New().WithContent("  ").Build();

            var resultValidation2 = new CommentValidator().Validate(badComment1);

            Assert.False(resultValidation2.IsValid);
        }
Exemple #9
0
        public void TestValidationCommentWithValidResult()
        {
            var okUser = UserBuilder.New().Build();

            new UserRepository().Create(okUser);

            var okComment = CommentBuilder.New().Build();

            var resultValidation1 = new CommentValidator().Validate(okComment);

            Assert.True(resultValidation1.IsValid);
        }
Exemple #10
0
        public void TestEntityDelete()
        {
            var comment = CommentBuilder.New().Build();

            var mockTeste = new Mock <IDeleteDB <Comment> >();

            var commentRepository = new CommentRepository(mockTeste.Object);

            commentRepository.Delete(comment);

            mockTeste.Verify(x => x.DeleteRegister(It.IsAny <Comment>()));
        }
Exemple #11
0
        public void TestValidationCommentWithInvalidPublicationId()
        {
            var okUser = UserBuilder.New().Build();

            new UserRepository().Create(okUser);

            var badComment1 = CommentBuilder.New().WithPublicationId(Guid.Parse("00000000-0000-0000-0000-000000000000")).Build();

            var resultValidation2 = new CommentValidator().Validate(badComment1);

            Assert.False(resultValidation2.IsValid);
        }
Exemple #12
0
        public void TestValidationCommentExist()
        {
            var okComment = CommentBuilder.New().Build();

            new CreateComment().CreateNewRegister(okComment);

            var badComment = CommentBuilder.New().WithContent("SomeRandomContent").Build();

            var resultValidation1 = new CommentExistValidator().Validate(okComment.Id);
            var resultValidation2 = new CommentExistValidator().Validate(badComment.Id);

            Assert.True(resultValidation1.IsValid);
            Assert.False(resultValidation2.IsValid);
        }
Exemple #13
0
        public void TestCreateWithoutId()
        {
            var comment = CommentBuilder.New()
                          .WithId(new Guid())
                          .WithAutor(UserBuilder.New().Build())
                          .WithContent("Content")
                          .WithPublicationId(new Guid())
                          .Build();

            new CreateComment().CreateNewRegister(comment);

            Assert.True(comment.Id != Guid.Empty && comment.Id != null);
            Assert.True(comment.Autor.Id != Guid.Empty && comment.Autor.Id != null);
            Assert.True(comment.Content == "Content");
            Assert.True(comment.PublicationId == Guid.Parse("00000000-0000-0000-0000-000000000000"));
        }
Exemple #14
0
        public void TestCreate()
        {
            var comment = CommentBuilder.New().Build();

            // Conhecimento MemoryCache
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60);
            Assert.IsTrue(memoryCache.Add("comment", comment, policy));

            // Produção através dos métodos
            new CreateComment().CreateNewRegister(comment);
            var idGet = new GetComment().GetRegisterById(comment.Id);

            Assert.IsNotNull(idGet);
        }
Exemple #15
0
        public void TestGetById()
        {
            var comment = CommentBuilder.New().WithId(new Guid()).Build();

            var resultValidation = new CommentValidator().Validate(comment);

            // Conhecimento MemoryCache
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60);
            memoryCache.Add("commentGetId", comment, policy);
            Comment commentGet = (Comment)memoryCache["commentGetId"];

            Assert.IsTrue(commentGet.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"));

            // Produção através dos métodos
            new CreateComment().CreateNewRegister(comment);
            var idGet = new GetComment().GetRegisterById(comment.Id);

            Assert.IsNotNull(idGet);
        }
Exemple #16
0
        public void TestDelete()
        {
            var comment = CommentBuilder.New().Build();

            // Conhecimento MemoryCache
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60);
            memoryCache.Add("commentRemove", comment, policy);
            Comment commentGet = (Comment)memoryCache["commentRemove"];

            Assert.AreEqual(comment.ToString(), commentGet.ToString());
            memoryCache.Remove("commentRemove");
            commentGet = (Comment)memoryCache["commentRemove"];
            Assert.IsNull(commentGet);

            // Produção através dos métodos
            new CreateComment().CreateNewRegister(comment);
            new DeleteComment().DeleteRegister(comment);
            var idGet = new GetComment().GetRegisterById(comment.Id);

            Assert.IsNull(idGet);
        }