public async Task Test07() { // Prepare a DTO for save, that contains leading and // trailing spaces in some string properties var dtoForSave = new AccountTypeForSave { Name = " Hollow Section", // Leading space Name2 = "مقطع أجوف", Code = "HS ", // Trailing space ParentId = null, IsAssignable = false }; // Call the API var response = await Client.PostAsJsonAsync(Url, new List <AccountTypeForSave> { dtoForSave }); Output.WriteLine(await response.Content.ReadAsStringAsync()); // Confirm that the response is well-formed var responseData = await response.Content.ReadAsAsync <EntitiesResponse <AccountType> >(); 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("AccountType_HS", responseDto); }
public async Task Test04() { var parentId = (await(await Client.GetAsync($"{Url}?filter=Code eq 'AccountsPayable'")).Content.ReadAsAsync <GetResponse <AccountType> >()).Result.Single().Id; // Prepare a well formed entity var dtoForSave = new AccountTypeForSave { Name = "Sheet Metals", Name2 = "صفائح المعدن", Code = "SM", ParentId = parentId, IsAssignable = true, Description = "Sheet Metals", Description2 = "صفائح المعدن", IsCurrent = true, IsReal = true, IsPersonal = false, IsResourceClassification = true }; // Save it var dtosForSave = new List <AccountTypeForSave> { dtoForSave }; var response = await Client.PostAsJsonAsync(Url, 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 AccountType var responseData = await response.Content.ReadAsAsync <EntitiesResponse <AccountType> >(); Assert.Single(responseData.Result); // Assert that the result matches the saved entity Assert.Equal("AccountType", responseData.CollectionName); // Retreve the entity from the entities var responseDto = responseData.Result.SingleOrDefault(); Assert.NotNull(responseDto?.Id); Assert.Equal(dtoForSave.Name, responseDto.Name); Assert.Equal(dtoForSave.Name2, responseDto.Name2); Assert.Equal(dtoForSave.Description, responseDto.Description); Assert.Equal(dtoForSave.Description2, responseDto.Description2); Assert.Equal(dtoForSave.Code, responseDto.Code); Assert.Equal(dtoForSave.ParentId, responseDto.ParentId); Assert.Equal(dtoForSave.IsAssignable, responseDto.IsAssignable); Assert.Equal(dtoForSave.IsCurrent, responseDto.IsCurrent); Assert.Equal(dtoForSave.IsReal, responseDto.IsReal); Assert.Equal(dtoForSave.IsPersonal, responseDto.IsPersonal); Assert.Equal(dtoForSave.IsResourceClassification, responseDto.IsResourceClassification); Shared.Set("AccountType_SM", responseDto); }