public void UpdateAddressHistories_WithTwoActiveHistories_ChangesInOneHomeAddressOneWorkAddress_ShouldDeactivateBothHistories() { var homeAddress1 = new PersonalAddress { StreetName = "TestStreetHome", StreetNumber = "1", ZipCode = 1234, Town = "TestTown", Latitude = "1234", Longitude = "1234", Type = PersonalAddressType.Home, PersonId = 1 }; var workAddress1 = new WorkAddress { StreetName = "TestStreetWork", StreetNumber = "1", ZipCode = 1234, Town = "TestTown", Latitude = "1234", Longitude = "1234" }; var homeAddress2 = new PersonalAddress { StreetName = "TestStreetHome", StreetNumber = "1", ZipCode = 1234, Town = "TestTown", Latitude = "1234", Longitude = "1234", Type = PersonalAddressType.Home, PersonId = 2 }; var workAddress2 = new WorkAddress { StreetName = "TestStreetWork", StreetNumber = "1", ZipCode = 1234, Town = "TestTown", Latitude = "1234", Longitude = "1234" }; var emplRepoMock = NSubstitute.Substitute.For <IGenericRepository <Employment> >(); emplRepoMock.AsQueryable().ReturnsForAnyArgs(new List <Employment> { new Employment() { Id = 1, PersonId = 1, OrgUnit = new OrgUnit() { Address = workAddress1 } }, new Employment() { Id = 2, PersonId = 2, OrgUnit = new OrgUnit() { Address = new WorkAddress { StreetName = "NewTestStreetWork", StreetNumber = "1", ZipCode = 1234, Town = "TestTown", Latitude = "1234", Longitude = "1234" } } } }.AsQueryable()); var addressHistoryRepoMock = NSubstitute.Substitute.For <IGenericRepository <AddressHistory> >(); var historyList = new List <AddressHistory> { new AddressHistory() { EmploymentId = 1, EndTimestamp = 0, Employment = emplRepoMock.AsQueryable().Single(x => x.Id == 1), WorkAddress = workAddress1, HomeAddress = homeAddress1, }, new AddressHistory() { EmploymentId = 2, EndTimestamp = 0, Employment = emplRepoMock.AsQueryable().Single(x => x.Id == 2), WorkAddress = workAddress2, HomeAddress = homeAddress2, } }; var personalAddressRepoMock = NSubstitute.Substitute.For <IGenericRepository <PersonalAddress> >(); personalAddressRepoMock.AsQueryable().ReturnsForAnyArgs(new List <PersonalAddress> { new PersonalAddress { StreetName = "NewTestStreetHome", StreetNumber = "1", ZipCode = 1234, Town = "TestTown", Latitude = "1234", Longitude = "1234", Type = PersonalAddressType.Home, PersonId = 1 }, homeAddress2 }.AsQueryable()); addressHistoryRepoMock.AsQueryable().ReturnsForAnyArgs(historyList.AsQueryable()); var uut = new AddressHistoryService(emplRepoMock, addressHistoryRepoMock, personalAddressRepoMock); uut.UpdateAddressHistories(); Assert.AreNotEqual(0, historyList.ElementAt(0).EndTimestamp); Assert.AreNotEqual(0, historyList.ElementAt(1).EndTimestamp); }
public void UpdateAddressHistories_WithOneActiveHistory_NoChangesInAddress_ShouldNotDeactivate() { var homeAddress = new PersonalAddress { StreetName = "TestStreetHome", StreetNumber = "1", ZipCode = 1234, Town = "TestTown", Latitude = "1234", Longitude = "1234", Type = PersonalAddressType.Home, PersonId = 1 }; var workAddress = new WorkAddress { StreetName = "TestStreetWork", StreetNumber = "1", ZipCode = 1234, Town = "TestTown", Latitude = "1234", Longitude = "1234" }; var emplRepoMock = NSubstitute.Substitute.For <IGenericRepository <Employment> >(); emplRepoMock.AsQueryable().ReturnsForAnyArgs(new List <Employment> { new Employment() { Id = 1, PersonId = 1, OrgUnit = new OrgUnit() { Address = workAddress } } }.AsQueryable()); var addressHistoryRepoMock = NSubstitute.Substitute.For <IGenericRepository <AddressHistory> >(); var historyList = new List <AddressHistory> { new AddressHistory() { EmploymentId = 1, EndTimestamp = 0, Employment = emplRepoMock.AsQueryable().First(), WorkAddress = workAddress, HomeAddress = homeAddress, } }; var personalAddressRepoMock = NSubstitute.Substitute.For <IGenericRepository <PersonalAddress> >(); personalAddressRepoMock.AsQueryable().ReturnsForAnyArgs(new List <PersonalAddress> { homeAddress }.AsQueryable()); addressHistoryRepoMock.AsQueryable().ReturnsForAnyArgs(historyList.AsQueryable()); var uut = new AddressHistoryService(emplRepoMock, addressHistoryRepoMock, personalAddressRepoMock); uut.UpdateAddressHistories(); Assert.AreEqual(0, historyList.ElementAt(0).EndTimestamp); }