Esempio 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 AgentForSave
            {
                Name      = "  Matilda", // Leading space
                Name2     = "ماتيلدا",
                Code      = "MA  ",      // Trailing space
                IsRelated = false,
            };

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

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

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

            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("Agent_Matilda", responseDto);
        }
        public async Task Test2002()
        {
            // Prepare a well formed entity
            var dtoForSave = new AgentForSave
            {
                EntityState             = "Inserted",
                Name                    = "World Health Organization",
                Name2                   = "منظمة الصحة العالمية",
                Code                    = "O0001",
                Address                 = "13 Huntington Rd.",
                BirthDateTime           = new System.DateTime(1948, 7, 4),
                Gender                  = 'M',
                IsRelated               = false,
                TaxIdentificationNumber = "12340643",
                Title                   = "Mr.",
                Title2                  = "السيد",
            };

            // Save it
            var dtosForSave = new List <AgentForSave> {
                dtoForSave
            };
            var response = await _client.PostAsJsonAsync(organizationAgentsURL, 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 Agent
            var responseData = await response.Content.ReadAsAsync <EntitiesResponse <Agent> >();

            Assert.Single(responseData.Data);

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

            var responseDto = responseData.Data.FirstOrDefault();

            Assert.NotNull(responseDto?.Id);
            Assert.Equal(dtoForSave.Name, responseDto.Name);
            Assert.Equal(dtoForSave.Name2, responseDto.Name2);
            Assert.Equal(dtoForSave.Code, responseDto.Code);
            Assert.Equal(dtoForSave.Address, responseDto.Address);
            Assert.Equal(dtoForSave.BirthDateTime, responseDto.BirthDateTime);
            Assert.Equal(dtoForSave.IsRelated, responseDto.IsRelated);
            Assert.Equal(dtoForSave.TaxIdentificationNumber, responseDto.TaxIdentificationNumber);

            // These should always be null for organizations
            Assert.Null(responseDto.Gender);
            Assert.Null(responseDto.Title);
            Assert.Null(responseDto.Title2);


            _shared.SetItem("Agent_WHO", responseDto);
        }
Esempio n. 3
0
        public async Task Test1005()
        {
            // Prepare a DTO for save, that contains leading and
            // trailing spaces in some string properties
            var dtoForSave = new AgentForSave
            {
                EntityState             = "Inserted",
                Name                    = "Claire  ",
                Name2                   = "كلير",
                Code                    = "  I0002",
                Address                 = "14 Huntington Rd.",
                BirthDateTime           = new System.DateTime(1981, 6, 11),
                Gender                  = 'F',
                IsRelated               = false,
                TaxIdentificationNumber = "9527272",
                Title                   = "Mrs.",
                Title2                  = "السيدة",

                // TODO: Add User Id
            };

            // Call the API
            var response = await _client.PostAsJsonAsync(individualAgentsURL, new List <AgentForSave> {
                dtoForSave
            });

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

            var responseDto = responseData.Data.FirstOrDefault();

            // Confirm the entity was saved
            Assert.NotNull(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.SetItem("Agent_Claire", responseDto);
        }
Esempio n. 4
0
        public async Task Test05()
        {
            // Prepare a well formed entity
            var dtoForSave = new AgentForSave
            {
                Name  = "John Wick",
                Name2 = "جون ويك",
                Code  = "JW",
                TaxIdentificationNumber = "13345",
                IsRelated = false
            };

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

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

            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("Agent", 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("Agent_JohnWick", responseDto);
            Shared.Set("Agent_JasonBourne", responseDto2);
        }