Exemplo n.º 1
0
        public async Task Handle_ValidId_ShouldUpdatePersistedRuleItem()
        {
            var command = new UpdateRuleItemCommand
            {
                Id          = 1,
                Description = "Descriptions",
                Json        = "Jsons",
                Name        = "Names",
                SqlPart     = "Sqls",
                SqlStr      = "Sqlstrs",
                Template    = "Templates"
            };

            var handler = new UpdateRuleItemCommand.UpdateRuleItemCommandHandler(dbContext, mapper);

            await handler.Handle(command, CancellationToken.None);

            var entity = dbContext.RuleName.Find(command.Id);

            Assert.NotNull(entity);
            Assert.Equal(command.Description, entity.Description);
            Assert.Equal(command.Json, entity.Json);
            Assert.Equal(command.Name, entity.Name);
            Assert.Equal(command.SqlPart, entity.SqlPart);
            Assert.Equal(command.SqlStr, entity.SqlStr);
            Assert.Equal(command.Template, entity.Template);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Update(int id, UpdateRuleItemCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task Handle_InvalidId_ThrowsException()
        {
            var command = new UpdateRuleItemCommand
            {
                Id          = 65,
                Description = "Descriptions",
                Json        = "Jsons",
                Name        = "Names",
                SqlPart     = "Sqls",
                SqlStr      = "Sqlstrs",
                Template    = "Templates"
            };

            var handler = new UpdateRuleItemCommand.UpdateRuleItemCommandHandler(dbContext, mapper);

            await Assert.ThrowsAsync <NotFoundException>(() =>
                                                         handler.Handle(command, CancellationToken.None));
        }
Exemplo n.º 4
0
        public async Task GivenInvalidUpdateRuleItemCommand_ReturnsBadRequest()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new UpdateRuleItemCommand
            {
                Id          = 1,
                Description = "This String Will Exceed The Maximum Lenght. This String Will Exceed The Maximum Lenght. This String Will Exceed The Maximum Lenght.",
                Json        = "Json",
                Name        = "Name",
                SqlPart     = "Sql",
                SqlStr      = "Sqlstr",
                Template    = "Template"
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

            var response = await client.PutAsync($"/api/rule/{command.Id}", content);

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
Exemplo n.º 5
0
        public async Task GivenValidUpdateRuleItemCommand_ReturnsSuccessStatusCode()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new UpdateRuleItemCommand
            {
                Id          = 1,
                Description = "Description",
                Json        = "Json",
                Name        = "Name",
                SqlPart     = "Sql",
                SqlStr      = "Sqlstr",
                Template    = "Template"
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

            var response = await client.PutAsync($"/api/rule/{command.Id}", content);

            response.EnsureSuccessStatusCode();
        }