Exemple #1
0
        public async Task Test07()
        {
            // Prepare a DTO for save, that contains leading and
            // trailing spaces in some string properties
            var dtoForSave = new AccountClassificationForSave
            {
                Name  = "  Child Account 2", // Leading space
                Name2 = "حساب فرعي 2",
                Code  = "1102  ",            // Trailing space
            };

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

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

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

            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("CustomClassification_Child2", responseDto);
        }
Exemple #2
0
        public async Task Test04()
        {
            // Prepare a well formed entity
            var dtoForSaveParent = new AccountClassificationForSave
            {
                Name  = "Parent Account",
                Name2 = "الحساب الأصل",
                Code  = "110"
            };

            // Prepare a well formed entity
            var dtoForSaveChild = new AccountClassificationForSave
            {
                Name  = "Child Account",
                Name2 = "حساب فرعي",
                Code  = "1101"
            };

            // Save it
            var dtosForSave = new List <AccountClassificationForSave> {
                dtoForSaveParent, dtoForSaveChild
            };
            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 CustomClassification
            var responseData = await response.Content.ReadAsAsync <EntitiesResponse <AccountClassification> >();

            Assert.Equal(2, responseData.Result.Count());

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

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

            Assert.NotNull(responseDtoParent?.Id);
            Assert.Equal(dtoForSaveParent.Name, responseDtoParent.Name);
            Assert.Equal(dtoForSaveParent.Name2, responseDtoParent.Name2);
            Assert.Equal(dtoForSaveParent.Code, responseDtoParent.Code);


            var responseDtoChild = responseData.Result.LastOrDefault();

            Assert.NotNull(responseDtoParent?.Id);
            Assert.Equal(dtoForSaveChild.Name, responseDtoChild.Name);
            Assert.Equal(dtoForSaveChild.Name2, responseDtoChild.Name2);
            Assert.Equal(dtoForSaveChild.Code, responseDtoChild.Code);


            Shared.Set("CustomClassification_Parent", responseDtoParent);
            Shared.Set("CustomClassification_Child", responseDtoChild);
        }