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 CenterForSave
            {
                CenterType = "Profit",
                Name       = "  Best Plastic", // Leading space
                Name2      = "بست بلاستيك",
                Code       = "1102  ",         // Trailing space
                IsLeaf     = true,
            };

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

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

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

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

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

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

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

            // Assert that the result matches the saved entity
            Assert.Equal("Center", 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("Center_Parent", responseDtoParent);
            Shared.Set("Center_Child", responseDtoChild);
        }