Пример #1
0
        public async Task Test07()
        {
            // Prepare a DTO for save, that contains leading and
            // trailing spaces in some string properties
            var dtoForSave = new ResponsibilityCenterForSave
            {
                ResponsibilityType = "Profit",
                Name   = "  Best Plastic", // Leading space
                Name2  = "بست بلاستيك",
                Code   = "1102  ",         // Trailing space
                IsLeaf = true,
            };

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

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

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

            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("ResponsibilityCenter_Child2", responseDto);
        }
Пример #2
0
        public async Task Test04()
        {
            // Prepare a well formed entity
            var dtoForSaveParent = new ResponsibilityCenterForSave
            {
                ResponsibilityType = "Cost",
                Name   = "Walia Steel Industry",
                Name2  = "واليا الحديد",
                Code   = "110",
                IsLeaf = false,
            };

            // Prepare a well formed entity
            var dtoForSaveChild = new ResponsibilityCenterForSave
            {
                ResponsibilityType = "Investment",
                Name   = "Best Paint",
                Name2  = "بست بينت",
                Code   = "1101",
                IsLeaf = true
            };

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

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

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


            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);
            Assert.Equal(dtoForSaveParent.IsLeaf, responseDtoParent.IsLeaf);


            Shared.Set("ResponsibilityCenter_Parent", responseDtoParent);
            Shared.Set("ResponsibilityCenter_Child", responseDtoChild);
        }