Exemplo n.º 1
0
        public async Task <IActionResult> PutReportTemplate([FromRoute] int id, [FromBody] ReportTemplateUpdate command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != command.Id)
            {
                return(BadRequest());
            }

            try
            {
                await mediator.Send(command);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReportTemplateExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (ValidationException ex)
            {
                ex.AddToModelState(ModelState);
                return(BadRequest(ModelState));
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task UpdateTheItem()
        {
            var item = new ReportTemplateUpdate
            {
                Id   = 1001,
                Name = "Test",
                Tags = new List <string> {
                    "Tag"
                }.AsEnumerable()
            };

            var result = await Fixture.Controller.PutReportTemplate(1001, item);

            Assert.Contains(Fixture.Context.ReportTemplates, rt => rt.Name == item.Name);
            Assert.Collection(Fixture.Context.ReportTemplates
                              .Include(rt => rt.Tags)
                              .ThenInclude(rtrtt => rtrtt.ReportTemplateTag)
                              .First()
                              .Tags,
                              new Action <ReportTemplateReportTemplateTag>(tag => Assert.Equal("Tag", tag.ReportTemplateTag.Name)));
        }