Esempio 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 CurrencyForSave
            {
                Id           = "AED",
                Name         = "  AED",                          // Leading space
                Name2        = "درهم",
                Description  = "United Arab Emirates Dirham   ", // Trailing space
                Description2 = "درهم إماراتي",
                E            = 2
            };

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

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

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

            var responseDto = responseData.Result.FirstOrDefault();

            // Confirm that the leading and trailing spaces have been trimmed
            Assert.Equal(dtoForSave.Id?.Trim(), responseDto.Id);
            Assert.Equal(dtoForSave.Name?.Trim(), responseDto.Name);
            Assert.Equal(dtoForSave.Description?.Trim(), responseDto.Description);

            // share the entity, for the subsequent delete test
            Shared.Set("Currency_AED", responseDto);
        }
Esempio n. 2
0
        public async Task Test04()
        {
            // Prepare a well formed entity
            var dtoForSave = new CurrencyForSave
            {
                Id           = "EUR",
                Name         = "EUR",
                Name2        = "يورو",
                Description  = "Euro",
                Description2 = "يورو",
                E            = 2
            };

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

            Assert.Single(responseData.Result);

            // Assert that the result matches the saved entity
            Assert.Equal("Currency", responseData.CollectionName);

            // Retreve the entity from the entities
            var responseDto = responseData.Result.SingleOrDefault();

            Assert.Equal(dtoForSave.Id, 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);


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