Ejemplo n.º 1
0
        public async Task Test07()
        {
            // Prepare a DTO for save, that contains leading and
            // trailing spaces in some string properties
            var dtoForSave = new LookupForSave
            {
                Name  = "  Blue", // Leading space
                Name2 = "أزرق",
                Code  = "02  ",   // Trailing space
            };

            // Call the API
            var response = await Client.PostAsJsonAsync(Url, new List <LookupForSave> {
                dtoForSave
            });

            Output.WriteLine(await response.Content.ReadAsStringAsync());

            // Confirm that the response is well-formed
            var responseData = await response.Content.ReadAsAsync <EntitiesResponse <Lookup> >();

            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("Lookup_Blue", responseDto);
        }
Ejemplo n.º 2
0
        public async Task Test04()
        {
            // Prepare a well formed entity
            var dtoForSave = new LookupForSave
            {
                Name  = "Red",
                Name2 = "أحمر",
                Code  = "01",
            };

            // Save it
            var dtosForSave = new List <LookupForSave> {
                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 Lookup
            var responseData = await response.Content.ReadAsAsync <EntitiesResponse <Lookup> >();

            Assert.Single(responseData.Result);

            // Assert that the result matches the saved entity
            Assert.Equal("Lookup", 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);

            Shared.Set("Lookup_Red", responseDto);
        }