public async Task Test0005() { // Prepare a DTO for save, that contains leading and // trailing spaces in some string properties var dtoForSave = new MeasurementUnitForSave { EntityState = "Inserted", Name = " KM", // Leading space Name2 = "كم", Code = "km ", // Trailing space UnitType = "Mass", BaseAmount = 1, UnitAmount = 1 }; // Call the API var response = await _client.PostAsJsonAsync($"/api/measurement-units", new List <MeasurementUnitForSave> { dtoForSave }); // Confirm that the response is well-formed var responseData = await response.Content.ReadAsAsync <EntitiesResponse <MeasurementUnit> >(); var responseDto = responseData.Data.FirstOrDefault(); // Confirm the entity was saved Assert.NotNull(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.SetItem("MeasurementUnit_km", responseDto); }
public async Task Test04() { // Prepare a well formed entity var dtoForSave = new MeasurementUnitForSave { Name = "KG", Name2 = "كج", Description = "Kilogram", Description2 = "كيلوجرام", Code = "kg", UnitType = "Mass", BaseAmount = 1, UnitAmount = 1 }; // Save it var dtosForSave = new List <MeasurementUnitForSave> { 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 MeasurementUnit var responseData = await response.Content.ReadAsAsync <EntitiesResponse <MeasurementUnit> >(); Assert.Single(responseData.Result); // Assert that the result matches the saved entity Assert.Equal("MeasurementUnit", 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.Code, responseDto.Code); Assert.Equal(dtoForSave.UnitType, responseDto.UnitType); Assert.Equal(dtoForSave.BaseAmount, responseDto.BaseAmount); Assert.Equal(dtoForSave.UnitAmount, responseDto.UnitAmount); Shared.Set("MeasurementUnit_kg", responseDto); }
public async Task Test0002() { // Prepare a well formed entity var dtoForSave = new MeasurementUnitForSave { EntityState = "Inserted", Name = "KG", Name2 = "كج", Code = "kg", UnitType = "Mass", BaseAmount = 1, UnitAmount = 1 }; // Save it var dtosForSave = new List <MeasurementUnitForSave> { dtoForSave }; var response = await _client.PostAsJsonAsync($"/api/measurement-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 MeasurementUnit var responseData = await response.Content.ReadAsAsync <EntitiesResponse <MeasurementUnit> >(); Assert.Single(responseData.Data); // Assert that the result matches the saved entity Assert.Equal("MeasurementUnits", responseData.CollectionName); var responseDto = responseData.Data.FirstOrDefault(); Assert.NotNull(responseDto?.Id); Assert.Equal(dtoForSave.Name, responseDto.Name); Assert.Equal(dtoForSave.Name2, responseDto.Name2); Assert.Equal(dtoForSave.Code, responseDto.Code); Assert.Equal(dtoForSave.UnitType, responseDto.UnitType); Assert.Equal(dtoForSave.BaseAmount, responseDto.BaseAmount); Assert.Equal(dtoForSave.UnitAmount, responseDto.UnitAmount); _shared.SetItem("MeasurementUnit_kg", responseDto); }
public async Task Test07() { // Prepare a DTO for save, that contains leading and // trailing spaces in some string properties var dtoForSave = new MeasurementUnitForSave { Name = " KM", // Leading space Name2 = "كم", Code = "km ", // Trailing space Description = "كيلومتر", Description2 = "Kilometer", UnitType = "Mass", BaseAmount = 1, UnitAmount = 1 }; // Call the API var response = await Client.PostAsJsonAsync(Url, new List <MeasurementUnitForSave> { dtoForSave }); Output.WriteLine(await response.Content.ReadAsStringAsync()); // Confirm that the response is well-formed var responseData = await response.Content.ReadAsAsync <EntitiesResponse <MeasurementUnit> >(); 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("MeasurementUnit_km", responseDto); }