public async Task TestUpdate_PhoneNumberDoesNotExist() { using (ShimsContext.Create()) { System.Data.Entity.Fakes.ShimDbContext.AllInstances.SetOf1 <Person>((c) => { return(context.People); }); var yesterday = DateTimeOffset.Now.AddDays(-1.0); var user = new User(5); var phoneNumberId = 10; PhoneNumberType type = new PhoneNumberType { PhoneNumberTypeId = PhoneNumberType.Home.Id, PhoneNumberTypeName = PhoneNumberType.Home.Value }; var number = "12345"; var ext = "123"; var isPrimary = true; var updatedPhone = new UpdatedPhoneNumber(user, phoneNumberId, number, ext, type.PhoneNumberTypeId, isPrimary); Action a = () => service.Update(updatedPhone); Func <Task> f = () => service.UpdateAsync(updatedPhone); var message = String.Format("The phone number with id [{0}] was not found.", phoneNumberId); a.ShouldThrow <ModelNotFoundException>().WithMessage(message); f.ShouldThrow <ModelNotFoundException>().WithMessage(message); } }
public void TestConstructor() { var userId = 10; var number = "12345"; var ext = "123"; var numberTypeId = PhoneNumberType.Home.Id; var isPrimary = true; var updator = new User(userId); var id = 1; var model = new UpdatedPhoneNumber(updator, id, number, ext, numberTypeId, isPrimary); Assert.AreEqual(userId, model.Audit.User.Id); Assert.AreEqual(id, model.Id); Assert.AreEqual(number, model.Number); Assert.AreEqual(isPrimary, model.IsPrimary); Assert.AreEqual(numberTypeId, model.PhoneNumberTypeId); Assert.IsInstanceOfType(model.Audit, typeof(Update)); }
public async Task TestUpdate_OtherPhoneNumbersPrimary() { using (ShimsContext.Create()) { System.Data.Entity.Fakes.ShimDbContext.AllInstances.SetOf1 <Person>((c) => { return(context.People); }); var yesterday = DateTimeOffset.Now.AddDays(-1.0); var user = new User(5); var phoneNumberId = 10; Person person = new Person { PersonId = 10, }; Person otherPerson = new Person { PersonId = 20 }; PhoneNumberType type = new PhoneNumberType { PhoneNumberTypeId = PhoneNumberType.Home.Id, PhoneNumberTypeName = PhoneNumberType.Home.Value }; PhoneNumber phoneNumber = null; PhoneNumber primaryPhone1 = null; PhoneNumber primaryPhone2 = null; PhoneNumber otherPersonPrimaryPhoneNumber = null; var number = "12345"; var ext = "123"; var isPrimary = true; var updatedPhone = new UpdatedPhoneNumber(user, phoneNumberId, number, ext, type.PhoneNumberTypeId, isPrimary); Action beforeTester = () => { Assert.IsTrue(primaryPhone1.IsPrimary.Value); Assert.IsTrue(primaryPhone2.IsPrimary.Value); }; Action afterTester = () => { Assert.IsTrue(phoneNumber.IsPrimary.Value); Assert.IsFalse(primaryPhone1.IsPrimary.Value); Assert.IsFalse(primaryPhone2.IsPrimary.Value); Assert.IsTrue(otherPersonPrimaryPhoneNumber.IsPrimary.Value); }; context.SetupActions.Add(() => { otherPersonPrimaryPhoneNumber = new PhoneNumber { PhoneNumberId = 100, IsPrimary = true, Person = otherPerson, PersonId = otherPerson.PersonId }; primaryPhone1 = new PhoneNumber { PhoneNumberId = 20, IsPrimary = true, Person = person, PersonId = person.PersonId }; primaryPhone2 = new PhoneNumber { PhoneNumberId = 30, IsPrimary = true, Person = person, PersonId = person.PersonId }; phoneNumber = new PhoneNumber { PhoneNumberId = phoneNumberId, Person = person, PersonId = person.PersonId }; context.PhoneNumbers.Add(phoneNumber); context.PhoneNumbers.Add(primaryPhone1); context.PhoneNumbers.Add(primaryPhone2); context.PhoneNumbers.Add(otherPersonPrimaryPhoneNumber); context.PhoneNumberTypes.Add(type); }); context.Revert(); beforeTester(); service.Update(updatedPhone); afterTester(); context.Revert(); beforeTester(); await service.UpdateAsync(updatedPhone); afterTester(); } }
public async Task TestUpdate_Contact_CheckProperties() { using (ShimsContext.Create()) { System.Data.Entity.Fakes.ShimDbContext.AllInstances.SetOf1 <Person>((c) => { return(context.People); }); var creatorId = 1; var yesterday = DateTimeOffset.Now.AddDays(-1.0); var user = new User(5); var phoneNumberId = 10; Contact contact = new Contact { ContactId = 10, }; PhoneNumberType type = new PhoneNumberType { PhoneNumberTypeId = PhoneNumberType.Home.Id, PhoneNumberTypeName = PhoneNumberType.Home.Value }; PhoneNumber phoneNumber = null; var number = "12345"; var ext = "123"; var isPrimary = true; var updatedPhone = new UpdatedPhoneNumber(user, phoneNumberId, number, ext, type.PhoneNumberTypeId, isPrimary); Action afterTester = () => { Assert.AreEqual(1, context.PhoneNumbers.Count()); var firstNumber = context.PhoneNumbers.First(); Assert.AreEqual(number, firstNumber.Number); Assert.AreEqual(ext, firstNumber.Extension); Assert.AreEqual(isPrimary, firstNumber.IsPrimary); Assert.AreEqual(type.PhoneNumberTypeId, firstNumber.PhoneNumberTypeId); Assert.AreEqual(phoneNumberId, firstNumber.PhoneNumberId); Assert.AreEqual(creatorId, firstNumber.History.CreatedBy); Assert.AreEqual(user.Id, firstNumber.History.RevisedBy); Assert.AreEqual(yesterday, firstNumber.History.CreatedOn); DateTimeOffset.Now.Should().BeCloseTo(firstNumber.History.RevisedOn, 20000); }; context.SetupActions.Add(() => { phoneNumber = new PhoneNumber { PhoneNumberId = phoneNumberId, Contact = contact, ContactId = contact.ContactId }; phoneNumber.History.CreatedBy = creatorId; phoneNumber.History.RevisedBy = creatorId; phoneNumber.History.CreatedOn = yesterday; phoneNumber.History.RevisedOn = yesterday; context.PhoneNumbers.Add(phoneNumber); context.PhoneNumberTypes.Add(type); }); context.Revert(); service.Update(updatedPhone); afterTester(); context.Revert(); await service.UpdateAsync(updatedPhone); afterTester(); } }