Ejemplo n.º 1
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IEmailAddressRepository>();
            var model = new ApiEmailAddressRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <EmailAddress>())).Returns(Task.FromResult(new EmailAddress()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new EmailAddress()));
            var service = new EmailAddressService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.EmailAddressModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLEmailAddressMapperMock,
                                                  mock.DALMapperMockFactory.DALEmailAddressMapperMock);

            UpdateResponse <ApiEmailAddressResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.EmailAddressModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiEmailAddressRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <EmailAddress>()));
        }
        public async Task TestUpdate_PersonEmail_CheckProperties()
        {
            var    personId = 1;
            Person person   = new Person
            {
                PersonId = personId
            };
            EmailAddressType emailAddressType = new EmailAddressType
            {
                EmailAddressTypeId   = EmailAddressType.Home.Id,
                EmailAddressTypeName = EmailAddressType.Home.Value
            };
            var          creatorId            = 1;
            var          updatorId            = 2;
            var          yesterday            = DateTimeOffset.UtcNow.AddDays(-1.0);
            var          emailAddressId       = 1;
            EmailAddress emailAddressToUpdate = null;

            context.SetupActions.Add(() =>
            {
                emailAddressToUpdate = new EmailAddress
                {
                    EmailAddressId = emailAddressId,
                    Person         = person,
                    PersonId       = person.PersonId
                };
                emailAddressToUpdate.History.CreatedBy = creatorId;
                emailAddressToUpdate.History.RevisedBy = creatorId;
                emailAddressToUpdate.History.CreatedOn = yesterday;
                emailAddressToUpdate.History.RevisedOn = yesterday;
                person.EmailAddresses.Add(emailAddressToUpdate);
                context.EmailAddressTypes.Add(emailAddressType);
                context.People.Add(person);
                context.EmailAddresses.Add(emailAddressToUpdate);
            });
            var updatedEmailModel = new UpdatedEmailAddress(new User(updatorId), emailAddressId, "*****@*****.**", emailAddressType.EmailAddressTypeId, true);

            Action beforeTester = () =>
            {
                Assert.AreEqual(1, context.People.Count());
                Assert.AreEqual(1, context.EmailAddresses.Count());
                Assert.IsNull(emailAddressToUpdate.Address);
            };
            Action afterTester = () =>
            {
                Assert.AreEqual(1, context.People.Count());
                Assert.AreEqual(1, context.EmailAddresses.Count());
                Assert.AreEqual(updatedEmailModel.Audit.User.Id, emailAddressToUpdate.History.RevisedBy);
                DateTimeOffset.UtcNow.Should().BeCloseTo(emailAddressToUpdate.History.RevisedOn, 20000);
                Assert.AreEqual(creatorId, emailAddressToUpdate.History.CreatedBy);
                Assert.AreEqual(yesterday, emailAddressToUpdate.History.CreatedOn);
                Assert.AreEqual(updatedEmailModel.Address, emailAddressToUpdate.Address);
                Assert.AreEqual(updatedEmailModel.IsPrimary, emailAddressToUpdate.IsPrimary);
                Assert.AreEqual(emailAddressType.EmailAddressTypeId, emailAddressToUpdate.EmailAddressTypeId);
            };

            context.Revert();
            beforeTester();
            service.Update(updatedEmailModel);
            afterTester();

            context.Revert();
            beforeTester();
            await service.UpdateAsync(updatedEmailModel);

            afterTester();
        }