public async Task Handle_ShouldPersistRuleItem()
        {
            var command = new CreateRuleItemCommand
            {
                Description = "Description",
                Json        = "Json",
                Name        = "Name",
                SqlPart     = "Sql",
                SqlStr      = "Sqlstr",
                Template    = "Template"
            };

            var handler = new CreateRuleItemCommand.CreateRuleItemCommandHandler(dbContext, mapper);

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

            var entity = dbContext.RuleName.Last();

            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 GivenInvalidCreateRuleItem_ReturnsBadRequest()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new CreateRuleItemCommand
            {
                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.PostAsync("/api/rule", content);

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

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

            var content = IntegrationTestHelper.GetRequestContent(command);

            var response = await client.PostAsync("api/rule", content);

            response.EnsureSuccessStatusCode();
        }
Exemplo n.º 4
0
 public async Task <ActionResult <int> > Create(CreateRuleItemCommand command)
 {
     return(await Mediator.Send(command));
 }