Esempio n. 1
0
        public async Task CanGetPeopleById()
        {
            var factory = new TestWebApplicationFactory();
            var client  = factory.CreateClient();

            factory.AddTestData(TestData.CreateTestPeople());
            var httpRepo  = new PersonClientRepository(client);
            var idsToFind = new ParametersList <Guid>
            {
                TestData.JohnDoe.Id,
                TestData.JaneSmith.Id
            };

            var people = await httpRepo.GetPeople(new QueryPersonParameters
            {
                Id = idsToFind
            }).ConfigureAwait(false);

            var peopleArray = people?.ToArray();

            // Ensure that we got something back from GetPeople.
            Assert.IsNotNull(peopleArray);
            // Ensure that we received the count we expected.
            Assert.AreEqual(idsToFind.Count, peopleArray.Length);
        }
Esempio n. 2
0
        public async Task CanGetPerson()
        {
            var factory = new TestWebApplicationFactory();
            var client  = factory.CreateClient();

            factory.AddTestData(TestData.CreateTestPeople());
            var httpRepo = new PersonClientRepository(client);

            var person = await httpRepo.GetPerson(TestData.JohnDoe.Id)
                         .ConfigureAwait(false);

            // Ensure that we received something from GetPerson.
            Assert.IsNotNull(person);
            // Ensure that the person we received is the one we asked for based on the identifier.
            Assert.AreEqual(TestData.JohnDoe.Id, person.Id);
        }
Esempio n. 3
0
        public async Task CanEditPerson()
        {
            var factory = new TestWebApplicationFactory();
            var client  = factory.CreateClient();

            factory.AddTestData(TestData.CreateTestPeople());
            var httpRepo = new PersonClientRepository(client);

            var person = await httpRepo.EditPerson(TestData.JaneSmith.Id,
                                                   new EditPersonParameters
            {
                LastName = TestData.JohnDoe.LastName
            }).ConfigureAwait(false);

            // Ensure that we received an instance of Person.
            Assert.IsNotNull(person);
            // Ensure that the last name has changed to the expected value.
            Assert.AreEqual(TestData.JohnDoe.LastName, person.LastName);
        }
Esempio n. 4
0
        public async Task CanCreatePerson()
        {
            var factory  = new TestWebApplicationFactory();
            var client   = factory.CreateClient();
            var httpRepo = new PersonClientRepository(client);

            var person = await httpRepo.CreatePerson(new EditPersonParameters
            {
                FirstName = TestData.JohnDoe.FirstName,
                LastName  = TestData.JohnDoe.LastName
            }).ConfigureAwait(false);

            // Ensure that we received an instance of Person.
            Assert.IsNotNull(person);
            // Test that the first name is correct.
            Assert.AreEqual(TestData.JohnDoe.FirstName, person.FirstName);
            // Test that the last name is correct.
            Assert.AreEqual(TestData.JohnDoe.LastName, person.LastName);
        }
Esempio n. 5
0
        public async Task CanGetPeople()
        {
            var factory    = new TestWebApplicationFactory();
            var client     = factory.CreateClient();
            var testPeople = TestData.CreateTestPeople();

            factory.AddTestData(testPeople);
            var httpRepo = new PersonClientRepository(client);

            var people = await httpRepo.GetPeople(new QueryPersonParameters())
                         .ConfigureAwait(false);

            var peopleArray = people?.ToArray();

            // Ensure that we received something from GetPeople.
            Assert.IsNotNull(peopleArray);
            // Ensure that we received the expected number of people.
            Assert.AreEqual(testPeople.Length, peopleArray.Length);
            // Ensure that the people we received were in our test data set.
            Assert.IsTrue(peopleArray.All(p => testPeople.Select(x => x.Id).Contains(p.Id)));
        }
Esempio n. 6
0
        public async Task CanEditPersonAndSetNullProperty()
        {
            var factory = new TestWebApplicationFactory();
            var client  = factory.CreateClient();

            factory.AddTestData(TestData.CreateTestPeople());
            var httpRepo = new PersonClientRepository(client);

            var person = await httpRepo.EditPerson(TestData.JaneSmith.Id,
                                                   new EditPersonParameters
            {
                LastName = null
            }).ConfigureAwait(false);

            // Ensure that we received an instance of Person.
            Assert.IsNotNull(person);
            // Ensure that the last name was removed (set to null).
            Assert.IsNull(person.LastName);
            // Ensure that the other field was unmodified.
            Assert.AreEqual(TestData.JaneSmith.FirstName, person.FirstName);
        }
Esempio n. 7
0
        public async Task CanGetPeopleByLastName()
        {
            var factory = new TestWebApplicationFactory();
            var client  = factory.CreateClient();

            factory.AddTestData(TestData.CreateTestPeople());
            var httpRepo = new PersonClientRepository(client);

            var people = await httpRepo.GetPeople(new QueryPersonParameters
            {
                LastName = TestData.JohnDoe.LastName
            }).ConfigureAwait(false);

            var peopleArray = people?.ToArray();

            // Ensure that we received an instance from GetPeople.
            Assert.IsNotNull(peopleArray);
            // Ensure that we only received one result from our filter.
            Assert.AreEqual(1, peopleArray.Length);
            // Test that the person we received was the one we wanted.
            Assert.AreEqual(TestData.JohnDoe.Id, peopleArray[0].Id);
        }
Esempio n. 8
0
        public async Task CanDeletePerson()
        {
            var factory    = new TestWebApplicationFactory();
            var client     = factory.CreateClient();
            var testPeople = TestData.CreateTestPeople();

            factory.AddTestData(testPeople);
            var httpRepo = new PersonClientRepository(client);

            await httpRepo.DeletePerson(TestData.JohnDoe.Id)
            .ConfigureAwait(false);

            var people = await httpRepo.GetPeople(new QueryPersonParameters())
                         .ConfigureAwait(false);

            var peopleArray = people?.ToArray();

            // Ensure that something was returned from GetPeople.
            Assert.IsNotNull(peopleArray);
            // Since we deleted one person, our people count should reflect that.
            Assert.AreEqual(testPeople.Length - 1, peopleArray.Length);
            // Ensure that none of the remaining identifiers belong to John Doe because he was deleted.
            Assert.IsTrue(peopleArray.All(p => p.Id != TestData.JohnDoe.Id));
        }