public async Task TestUpdate_EmailAddressDoesNotExist() { var personId = 1; Person person = new Person { PersonId = personId }; EmailAddressType emailAddressType = new EmailAddressType { EmailAddressTypeId = EmailAddressType.Home.Id, EmailAddressTypeName = EmailAddressType.Home.Value }; var updatorId = 2; var yesterday = DateTimeOffset.UtcNow.AddDays(-1.0); var emailAddressId = 1; context.EmailAddressTypes.Add(emailAddressType); context.People.Add(person); var updatedEmailModel = new UpdatedEmailAddress(new User(updatorId), emailAddressId, "*****@*****.**", emailAddressType.EmailAddressTypeId, true); var message = String.Format("The email address with id [{0}] was not found.", emailAddressId); Action a = () => service.Update(updatedEmailModel); Func <Task> f = () => service.UpdateAsync(updatedEmailModel); a.ShouldThrow <ModelNotFoundException>().WithMessage(message); f.ShouldThrow <ModelNotFoundException>().WithMessage(message); }
public void TestConstructor() { var email = "*****@*****.**"; var id = 1; var user = new User(5); var isPrimary = true; var emailAddressTypeId = EmailAddressType.HostEmergency.Id; var model = new UpdatedEmailAddress(user, id, email, emailAddressTypeId, isPrimary); Assert.AreEqual(id, model.Id); Assert.AreEqual(email, model.Address); Assert.AreEqual(emailAddressTypeId, model.EmailAddressTypeId); Assert.AreEqual(isPrimary, model.IsPrimary); Assert.AreEqual(user.Id, model.Audit.User.Id); Assert.IsInstanceOfType(model.Audit, typeof(Update)); }
public async Task TestUpdate_ContactEmail_CheckProperties() { var contactId = 1; Contact contact = new Contact { ContactId = contactId }; 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, Contact = contact, ContactId = contact.ContactId }; emailAddressToUpdate.History.CreatedBy = creatorId; emailAddressToUpdate.History.RevisedBy = creatorId; emailAddressToUpdate.History.CreatedOn = yesterday; emailAddressToUpdate.History.RevisedOn = yesterday; contact.EmailAddresses.Add(emailAddressToUpdate); context.EmailAddressTypes.Add(emailAddressType); context.Contacts.Add(contact); context.EmailAddresses.Add(emailAddressToUpdate); }); var updatedEmailModel = new UpdatedEmailAddress(new User(updatorId), emailAddressId, "*****@*****.**", emailAddressType.EmailAddressTypeId, true); Action beforeTester = () => { Assert.AreEqual(1, context.Contacts.Count()); Assert.AreEqual(1, context.EmailAddresses.Count()); Assert.IsNull(emailAddressToUpdate.Address); }; Action afterTester = () => { Assert.AreEqual(1, context.Contacts.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(); }
public async Task TestUpdate_OtherEmailsPrimary() { var contactId = 1; Contact contact = new Contact { ContactId = contactId }; Contact otherContact = new Contact { ContactId = 2 }; 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; EmailAddress primaryEmail1 = null; EmailAddress primaryEmail2 = null; EmailAddress otherContactPrimaryEmail = null; context.SetupActions.Add(() => { emailAddressToUpdate = new EmailAddress { EmailAddressId = emailAddressId, Contact = contact, ContactId = contact.ContactId, IsPrimary = false }; primaryEmail1 = new EmailAddress { EmailAddressId = 10, IsPrimary = true, Contact = contact, ContactId = contact.ContactId }; primaryEmail2 = new EmailAddress { EmailAddressId = 20, IsPrimary = true, Contact = contact, ContactId = contact.ContactId }; otherContactPrimaryEmail = new EmailAddress { EmailAddressId = 30, IsPrimary = true, Contact = otherContact, ContactId = otherContact.ContactId }; emailAddressToUpdate.History.CreatedBy = creatorId; emailAddressToUpdate.History.RevisedBy = creatorId; emailAddressToUpdate.History.CreatedOn = yesterday; emailAddressToUpdate.History.RevisedOn = yesterday; contact.EmailAddresses.Add(emailAddressToUpdate); contact.EmailAddresses.Add(primaryEmail1); contact.EmailAddresses.Add(primaryEmail2); otherContact.EmailAddresses.Add(otherContactPrimaryEmail); context.EmailAddressTypes.Add(emailAddressType); context.Contacts.Add(contact); context.EmailAddresses.Add(emailAddressToUpdate); context.EmailAddresses.Add(primaryEmail1); context.EmailAddresses.Add(primaryEmail2); context.EmailAddresses.Add(otherContactPrimaryEmail); }); var updatedEmailModel = new UpdatedEmailAddress(new User(updatorId), emailAddressId, "*****@*****.**", emailAddressType.EmailAddressTypeId, true); Action beforeTester = () => { Assert.AreEqual(1, context.Contacts.Count()); Assert.AreEqual(4, context.EmailAddresses.Count()); Assert.IsNull(emailAddressToUpdate.Address); Assert.IsTrue(primaryEmail1.IsPrimary.Value); Assert.IsTrue(primaryEmail2.IsPrimary.Value); Assert.IsTrue(otherContactPrimaryEmail.IsPrimary.Value); }; Action afterTester = () => { Assert.AreEqual(1, context.Contacts.Count()); Assert.AreEqual(4, context.EmailAddresses.Count()); Assert.IsTrue(emailAddressToUpdate.IsPrimary.Value); Assert.IsFalse(primaryEmail1.IsPrimary.Value); Assert.IsFalse(primaryEmail2.IsPrimary.Value); Assert.IsTrue(otherContactPrimaryEmail.IsPrimary.Value); }; context.Revert(); beforeTester(); service.Update(updatedEmailModel); afterTester(); context.Revert(); beforeTester(); await service.UpdateAsync(updatedEmailModel); afterTester(); }
public async Task TestUpdate_PersonEmail_SevisNotLocked() { var personId = 1; var participantId = 1; Person person = new Person { PersonId = personId }; var participant = new Participant { ParticipantId = participantId, PersonId = person.PersonId, ParticipantStatusId = ParticipantStatus.Active.Id }; List <Participant> participants = new List <Participant>(); participants.Add(participant); person.Participations = participants; var participantPerson = new ParticipantPerson { Participant = participant, ParticipantId = participant.ParticipantId, }; participant.ParticipantPerson = participantPerson; var queuedToSubmitStatus = new SevisCommStatus { SevisCommStatusId = SevisCommStatus.InformationRequired.Id, SevisCommStatusName = SevisCommStatus.InformationRequired.Value }; var commStatus = new ParticipantPersonSevisCommStatus { AddedOn = DateTimeOffset.UtcNow, BatchId = "batch id", Id = 501, ParticipantId = participant.ParticipantId, ParticipantPerson = participantPerson, SevisCommStatus = queuedToSubmitStatus, SevisCommStatusId = queuedToSubmitStatus.SevisCommStatusId, }; participantPerson.ParticipantPersonSevisCommStatuses.Add(commStatus); 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); context.Participants.Add(participant); context.ParticipantPersons.Add(participantPerson); context.ParticipantPersonSevisCommStatuses.Add(commStatus); }); context.Revert(); var updatedEmailModel = new UpdatedEmailAddress(new User(updatorId), emailAddressId, "*****@*****.**", emailAddressType.EmailAddressTypeId, true); var message = String.Format("An update was attempted on participant with id [{0}] but should have failed validation.", participant.ParticipantId); Action a = () => service.Update(updatedEmailModel); Func <Task> f = () => service.UpdateAsync(updatedEmailModel); a.ShouldNotThrow <EcaBusinessException>(); f.ShouldNotThrow <EcaBusinessException>(); }