private async Task <WordDefinition> Get(Guid id) { return((await WordDefinitionsController.Get(id, new WordDefinitionGet { })).ShouldBeOfType <OkObjectResult>() .Value.ShouldBeOfType <WordDefinition>()); }
public async Task CRUD_Succeeds() { var creationRequest = new WordDefinitionCreate { Word = Word, LanguageCode = "en", Meaning = "Hello", Public = false, }; var creationResult = (await WordDefinitionsController.Create(creationRequest)) .ShouldBeOfType <CreatedAtActionResult>(); var createdId = creationResult.Value.ShouldBeOfType <WordDefinition>().Id; (await List()).Items.Count.ShouldBe(1); using (User(2)) { (await List()).Items.Count.ShouldBe(0); (await WordDefinitionsController.Get(createdId, new WordDefinitionGet { })).ShouldBeOfType <NotFoundResult>(); } await WordDefinitionsController.Update(createdId, new WordDefinitionUpdate { Public = true }); using (User(2)) { var created = await Get(createdId); created.Id.ShouldBe(createdId); created.LanguageCode.ShouldBe(creationRequest.LanguageCode); created.Meaning.ShouldBe(creationRequest.Meaning); (await WordDefinitionsController.Update(createdId, new WordDefinitionUpdate { LanguageCode = "en", Meaning = "Another way to say hello", })).ShouldBeOfType <NotFoundResult>(); } var updateRequest = new WordDefinitionUpdate { LanguageCode = "sv", Meaning = "ett hälsningsord", }; await WordDefinitionsController.Update(createdId, updateRequest); var updated = await Get(createdId); updated.LanguageCode.ShouldBe(updateRequest.LanguageCode); updated.Meaning.ShouldBe(updateRequest.Meaning); using (User(2)) { (await WordDefinitionsController.Delete(createdId, new WordDefinitionDelete { })).ShouldBeOfType <NotFoundResult>(); } (await List()).Items.Count.ShouldBe(1); (await WordDefinitionsController.Delete(createdId, new WordDefinitionDelete { })).ShouldBeOfType <NoContentResult>(); (await List()).Items.Count.ShouldBe(0); (await WordDefinitionsController.Get(createdId, new WordDefinitionGet { })).ShouldBeOfType <NotFoundResult>(); }