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); }
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()); }
public void GetByIdReturnsBadRequest() { var comment = CommentBuilder.New().Build(); var result = controller.Get(comment.Id); Assert.IsType <BadRequestObjectResult>(result.Result); }
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); }
public void GetByIdReturnsOk() { var comment = CommentBuilder.New().Build(); creator.CreateNewRegister(comment); var result = controller.Get(comment.Id); Assert.IsType <OkObjectResult>(result.Result); }
public void PutReturnsBadRequest_CommentInvalid() { var comment = CommentBuilder.New().Build(); creator.CreateNewRegister(comment); var result = controller.Put(comment.Id, ""); Assert.IsType <BadRequestObjectResult>(result.Result); }
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); }
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); }
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); }
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>())); }
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); }
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); }
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")); }
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); }
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); }
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); }