예제 #1
0
        public void TestCreate()
        {
            Topic topic = TopicBuilder.New().WithName("Nome teste").Build();

            Assert.True(topic.Id != Guid.Empty && topic.Id != null);
            Assert.True(topic.Name == "Nome teste");
        }
예제 #2
0
        public void GetByIdReturnsBadRequest()
        {
            var topic = TopicBuilder.New().Build();

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

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
예제 #3
0
        public void TestValidationBadTopicNameNull()
        {
            var badTopic = TopicBuilder.New().WithName(null).Build();

            var resultValidation = new TopicValidator().Validate(badTopic);

            Assert.False(resultValidation.IsValid);
        }
예제 #4
0
        public void TestValidationTopic()
        {
            var okTopic = TopicBuilder.New().Build();

            var resultValidation1 = new TopicValidator().Validate(okTopic);

            Assert.True(resultValidation1.IsValid);
        }
예제 #5
0
        public void TestGetAll()
        {
            Topic topic = TopicBuilder.New().WithName("Skate").Build();

            new CreateTopic().CreateNewRegister(topic);
            var idGet = new GetTopic().GetRegisterById(topic.Id);

            Assert.IsNotNull(idGet);
        }
예제 #6
0
        public void PostReturnsBadRequest_UserInvalid()
        {
            var topic = TopicBuilder.New().Build();

            new CreateTopic().CreateNewRegister(topic);

            var result = controller.Post(Guid.NewGuid(), "Titulo", "Conteudo", topic.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
예제 #7
0
        public void PutReturnsBadRequest_PublicationNotExistOnDatabase()
        {
            var topic = TopicBuilder.New().Build();

            new CreateTopic().CreateNewRegister(topic);

            var result = controller.Put(Guid.NewGuid(), "Nome put", "Conteudo", topic.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
예제 #8
0
        public void PutReturnsBadRequest_TopicNotValid()
        {
            var topic = TopicBuilder.New().Build();

            creator.CreateNewRegister(topic);

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

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
예제 #9
0
        public void GetByIdReturnsOk()
        {
            var topic = TopicBuilder.New().Build();

            creator.CreateNewRegister(topic);

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

            Assert.IsType <OkObjectResult>(result.Result);
        }
예제 #10
0
        public void TestValidationPublicationBadTopic()
        {
            var badTopic = TopicBuilder.New().WithName("  ").Build();

            var badPublication = PublicationBuilder.New().WithTopic(badTopic).Build();

            var resultValidation = new PublicationValidator().Validate(badPublication);

            Assert.False(resultValidation.IsValid);
        }
예제 #11
0
        public void TestValidationTopicExist()
        {
            var topic = TopicBuilder.New().WithName("Nome teste").Build();

            new TopicRepository().Create(topic);

            var resultValidation = new TopicExistValidator().Validate(topic.Id);

            Assert.True(resultValidation.IsValid);
        }
예제 #12
0
        public void TestValidationBadTopicNameExistsOnDatabase()
        {
            var topic = TopicBuilder.New().WithName("Nome").Build();

            new TopicRepository().Create(topic);

            var badTopic = new Topic("Nome");

            var resultValidation = new TopicValidator().Validate(badTopic);

            Assert.False(resultValidation.IsValid);
        }
예제 #13
0
        public void PostReturnsBadRequest_PublicationInvalid()
        {
            var user = UserBuilder.New().Build();

            new CreateUser().CreateNewRegister(user);

            var topic = TopicBuilder.New().Build();

            new CreateTopic().CreateNewRegister(topic);

            var result = controller.Post(user.Id, "", "Conteudo", topic.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
예제 #14
0
        public void PostReturnsOk()
        {
            var user = UserBuilder.New().Build();

            new CreateUser().CreateNewRegister(user);

            var topic = TopicBuilder.New().Build();

            new CreateTopic().CreateNewRegister(topic);

            var result = controller.Post(user.Id, "Titulo", "Conteudo", topic.Id);

            Assert.IsType <CreatedAtActionResult>(result.Result);
        }
예제 #15
0
        public void TestCreate()
        {
            Topic topic            = TopicBuilder.New().WithName("Skate").Build();
            var   resultValidation = new TopicValidator().Validate(topic);

            if (resultValidation.IsValid)
            {
                // Conhecimento MemoryCache
                CacheItemPolicy policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60);
                Assert.IsTrue(memoryCache.Add("topic", topic, policy));

                // Produção através dos métodos
                new CreateTopic().CreateNewRegister(topic);
                var idGet = new GetTopic().GetRegisterById(topic.Id);
                Assert.IsNotNull(idGet);
            }
        }
예제 #16
0
    public static PublicationBuilder New()
    {
        var user = UserBuilder.New().Build();

        new CreateUser().CreateNewRegister(user);

        var topic = TopicBuilder.New().Build();

        new CreateTopic().CreateNewRegister(topic);

        return(new PublicationBuilder()
        {
            Id = Guid.NewGuid(),
            Autor = user,
            Title = "TestPost",
            Content = "Test Post Builder",
            DateCreated = DateTime.Now,
            Comments = new List <Comment>(),
            Topic = topic
        });
    }