public async Task Test09() { // Prepare a DTO for save, that contains leading and // trailing spaces in some string properties var dtoForSave = new ResourceForSave { AccountTypeId = Shared.Get <AccountType>("AccountType_SM").Id, Name = " HR 1000x0.9", // Leading space Name2 = "HR 1000x0.9", Code = "0HR 1000x0.9 ", // Trailing space }; // Call the API var response = await Client.PostAsJsonAsync(Url, new List <ResourceForSave> { dtoForSave }); Output.WriteLine(await response.Content.ReadAsStringAsync()); // Confirm that the response is well-formed var responseData = await response.Content.ReadAsAsync <EntitiesResponse <Resource> >(); var responseDto = responseData.Result.FirstOrDefault(); // Confirm the entity was saved Assert.NotEqual(0, responseDto.Id); // Confirm that the leading and trailing spaces have been trimmed Assert.Equal(dtoForSave.Name?.Trim(), responseDto.Name); Assert.Equal(dtoForSave.Code?.Trim(), responseDto.Code); // share the entity, for the subsequent delete test Shared.Set("Resource_HR1000x0.9", responseDto); }
public async Task Test06() { // Prepare a well formed entity var dtoForSave = new ResourceForSave { AssetTypeId = Shared.Get <AccountType>("AccountType_SM").Id, Name = "HR 1000x0.8", Name2 = "HR 1000x0.8", Code = "HR 1000x0.8", Units = new List <ResourceUnitForSave> { new ResourceUnitForSave { UnitId = Shared.Get <Unit>("Unit_kg").Id, Multiplier = 1, } } }; // Save it var dtosForSave = new List <ResourceForSave> { dtoForSave }; var response = await Client.PostAsJsonAsync(Url + "?expand=Units", dtosForSave); // Assert that the response status code is a happy 200 OK Output.WriteLine(await response.Content.ReadAsStringAsync()); Assert.Equal(HttpStatusCode.OK, response.StatusCode); // Assert that the response is well-formed singleton of Resource var responseData = await response.Content.ReadAsAsync <EntitiesResponse <Resource> >(); Assert.Single(responseData.Result); // Assert that the result matches the saved entity Assert.Equal("Resource", responseData.CollectionName); // Retreve the entity from the entities var responseDto = responseData.Result.SingleOrDefault(); Assert.NotNull(responseDto?.Id); Assert.Equal(_definitionId, responseDto.DefinitionId); Assert.Equal(dtoForSave.Name, responseDto.Name); Assert.Equal(dtoForSave.Name2, responseDto.Name2); Assert.Equal(dtoForSave.Code, responseDto.Code); Assert.Collection(responseDto.Units, (responseRu) => { Assert.NotNull(responseRu?.Id); var ruForSave = dtoForSave.Units[0]; Assert.Equal(ruForSave.UnitId, responseRu.UnitId); Assert.Equal(ruForSave.Multiplier, responseRu.Multiplier); }); Shared.Set("Resource_HR1000x0.8", responseDto); }