Beispiel #1
0
        public void DeleteDeletesCorrectPerson()
        {
            var fakePeopleRepository = new FakePeopleRepository();
            var service = new ContactManagerService(fakePeopleRepository, new FakeUnitOfWorkFactory());

            service.DeletePerson(24);
            fakePeopleRepository.DeletedPerson.Id.Should().Be(24);
        }
Beispiel #2
0
        public void CantUpdateNonExistentPerson()
        {
            var fakePeopleRepository = new FakePeopleRepository();
            var service    = new ContactManagerService(fakePeopleRepository, new FakeUnitOfWorkFactory());
            var peronModel = new PersonModel {
                Id = -1, DateOfBirth = DateTime.Now.AddDays(-1), FirstName = "Something", LastName = "Something Else"
            };
            var result = service.UpdatePerson(peronModel);

            result.Errors.Should().Contain(x => x.ErrorMessage.ToLower().Contains("unknown person id"));
        }
Beispiel #3
0
        public void UpdatePersonRejectsInvalidPerson()
        {
            var fakePeopleRepository = new FakePeopleRepository();
            var service    = new ContactManagerService(fakePeopleRepository, new FakeUnitOfWorkFactory());
            var peronModel = new PersonModel {
                Id = 24, DateOfBirth = DateTime.Now.AddDays(-1), FirstName = "", LastName = ""
            };
            var result = service.UpdatePerson(peronModel);

            result.Errors.Should().Contain(x => x.ErrorMessage.ToLower().Contains("lastname field is required"));
            result.Data.HasValue.Should().BeFalse();
        }
Beispiel #4
0
        public void UpdatePersonUpdatesCorrectPerson()
        {
            var fakePeopleRepository = new FakePeopleRepository();
            var service    = new ContactManagerService(fakePeopleRepository, new FakeUnitOfWorkFactory());
            var peronModel = new PersonModel {
                Id = 24, DateOfBirth = DateTime.Now.AddDays(-1), FirstName = "New First Name", LastName = "New Last Name"
            };
            var result = service.UpdatePerson(peronModel);

            fakePeopleRepository.FindById(24).LastName.Should().Be("New Last Name");
            result.Errors.Should().BeEmpty();
            result.Data.Value.Should().Be(24);
        }
Beispiel #5
0
        public void InsertPersonRejectsInvalidPerson()
        {
            var fakePeopleRepository = new FakePeopleRepository();
            var service    = new ContactManagerService(fakePeopleRepository, new FakeUnitOfWorkFactory());
            var peronModel = new PersonModel {
                DateOfBirth = DateTime.Now.AddDays(+1), FirstName = "Imar", LastName = "Spaanjaars"
            };
            var result = service.InsertPerson(peronModel);

            fakePeopleRepository.InsertedPerson.Should().BeNull();
            result.Errors.Should().Contain(x => x.ErrorMessage.ToLower().Contains("dateofbirth"));
            result.Data.HasValue.Should().BeFalse();
        }
Beispiel #6
0
        public void InsertPersonInsertsValidPerson()
        {
            var fakePeopleRepository = new FakePeopleRepository();
            var service    = new ContactManagerService(fakePeopleRepository, new FakeUnitOfWorkFactory());
            var peronModel = new PersonModel {
                DateOfBirth = DateTime.Now.AddDays(-1), FirstName = "Imar", LastName = "Spaanjaars"
            };
            var result = service.InsertPerson(peronModel);

            fakePeopleRepository.InsertedPerson.FirstName.Should().Be("Imar");
            result.Errors.Should().BeEmpty();
            result.Data.HasValue.Should().BeTrue();
            result.Data.Value.Should().Be(123);
        }