public async Task CannotCreatePageDataWithNullKey() { var keyName = Guid.NewGuid().ToString(); var newPageData = new DtoPageData { Key = null, Data = JsonDocument.Parse("{\"key\": \"value1\"}") }; ((await pageDataController.Post(newPageData)).Result as BadRequestObjectResult).StatusCode.Should().Be(400); }
public async Task <DtoPageData> AddAsync(DtoPageData pageData) { var dbPageData = mapper.Map <DbPageData>(pageData); await context.PageData.AddAsync(dbPageData); await context.SaveChangesAsync(); return(mapper.Map <DtoPageData>(dbPageData)); }
public async Task CanGetDifferentPageData() //eventually { var keyName = Guid.NewGuid().ToString(); var newPageData = new DtoPageData { Key = keyName, Data = JsonDocument.Parse("{\"key2\": \"value2\"}") }; var createdPageData = ((await pageDataController.Post(newPageData)).Result as CreatedAtActionResult).Value as DtoPageData; var returnedPageData = (await pageDataController.GetByKey(createdPageData.Key)).Value; returnedPageData.Key.Should().Be(keyName); }
public async Task CanCreatePageData() { var keyName = Guid.NewGuid().ToString(); var newPageData = new DtoPageData { Key = keyName, Data = JsonDocument.Parse("{\"key\": \"value1\"}") }; var dtoPageData = ((await pageDataController.Post(newPageData)).Result as CreatedAtActionResult).Value as DtoPageData; dtoPageData.Key.Should().Be(keyName); dtoPageData.Data.RootElement.GetProperty("key").GetString().Should().Be("value1"); }
public async Task <ActionResult <DtoPageData> > Post(DtoPageData pageData) { log.LogDebug("HttpPost Post PageData"); log.LogInformation("Posting PageData for {PageData}", pageData); if (!ModelState.IsValid || string.IsNullOrWhiteSpace(pageData.Key) || pageData.Data == null) { return(BadRequest(getModelStateErrorMessage())); } var createdPageData = await pageDataRepository.AddAsync(pageData); return(CreatedAtAction(nameof(GetByKey), new { key = createdPageData.Key }, createdPageData)); }
public async Task EditAsync(string key, DtoPageData pageData) { var existingDbPageData = await context.PageData.AsNoTracking().FirstOrDefaultAsync(r => r.Key == key); var mappedPageData = mapper.Map <DbPageData>(pageData); // mappedPageData.ID = existingDbPageData.ID; var alteredPageData = mappedPageData with { ID = existingDbPageData.ID }; context.Update(alteredPageData); await context.SaveChangesAsync(); }
public async Task <IActionResult> Edit(string key, DtoPageData pageData) { log.LogInformation("Editing key {key} for page {pageData}", key, pageData); if (!ModelState.IsValid) { return(BadRequest(getModelStateErrorMessage())); } if (!await pageDataRepository.ExistsAsync(key)) { return(NotFound("Page Data key does not exist")); } try { await pageDataRepository.EditAsync(key, pageData); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }