Ejemplo n.º 1
0
        public async Task Test08()
        {
            // Prepare a DTO for save, that contains leading and
            // trailing spaces in some string properties
            var dtoForSave = new RelationForSave
            {
                Name      = "  Matilda", // Leading space
                Name2     = "ماتيلدا",
                Code      = "MA  ",      // Trailing space
                IsRelated = false,
            };

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

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

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

            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("Contract_Matilda", responseDto);
        }
Ejemplo n.º 2
0
        public async Task Test05()
        {
            // Prepare a well formed entity
            var dtoForSave = new RelationForSave
            {
                Name  = "John Wick",
                Name2 = "جون ويك",
                Code  = "JW",
                TaxIdentificationNumber = "13345",
                IsRelated = false
            };

            var dtoForSave2 = new RelationForSave
            {
                Name  = "Jason Bourne",
                Name2 = "جيسن بورن",
                Code  = "JB",
                TaxIdentificationNumber = "13346",
                IsRelated = false
            };

            // Save it
            var dtosForSave = new List <RelationForSave> {
                dtoForSave, dtoForSave2
            };
            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 Contract
            var responseData = await response.Content.ReadAsAsync <EntitiesResponse <Relation> >();

            Assert.Collection(responseData.Result,
                              e => Assert.NotEqual(0, e.Id),
                              e => Assert.NotEqual(0, e.Id));

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

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

            Assert.Equal(dtoForSave.Name, responseDto.Name);
            Assert.Equal(dtoForSave.Name2, responseDto.Name2);
            Assert.Equal(dtoForSave.Name3, responseDto.Name3);
            Assert.Equal(dtoForSave.Code, responseDto.Code);
            Assert.Equal(dtoForSave.TaxIdentificationNumber, responseDto.TaxIdentificationNumber);


            var responseDto2 = responseData.Result.LastOrDefault();

            Assert.Equal(dtoForSave2.Name, responseDto2.Name);
            Assert.Equal(dtoForSave2.Name2, responseDto2.Name2);
            Assert.Equal(dtoForSave2.Name3, responseDto2.Name3);
            Assert.Equal(dtoForSave2.Code, responseDto2.Code);
            Assert.Equal(dtoForSave2.TaxIdentificationNumber, responseDto2.TaxIdentificationNumber);

            Shared.Set("Contract_JohnWick", responseDto);
            Shared.Set("Contract_JasonBourne", responseDto2);
        }