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); }
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); }
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(); }
public async Task <ActionResult <int> > Create(CreateRuleItemCommand command) { return(await Mediator.Send(command)); }