public void VenueCorrector_WithCorrections_SetsVenueIdAndAudit() { // Arrange var clock = new FixedClock(); var venueCorrector = new VenueCorrector(clock); var venueCorrection = new VenueBuilder().Build(); var locationToFix = new ApprenticeshipLocation { Id = new Guid("30146B96-F1FC-4B16-A046-D6A3B59CF1CE"), VenueId = Guid.Empty, }; var decoy1 = new ApprenticeshipLocation // decoy { Id = new Guid("E08B4EE9-9AA3-41EC-BAF5-7961416E9A82"), VenueId = Guid.Empty, }; var decoy2 = new ApprenticeshipLocation // decoy { Id = new Guid("E129D3CC-D141-49B9-94FC-E472A2F93A56"), VenueId = Guid.Empty, }; var apprenticeshipVenueCorrection = new ApprenticeshipVenueCorrection { Apprenticeship = new Apprenticeship { ApprenticeshipLocations = new List <ApprenticeshipLocation> { decoy1, locationToFix, decoy2, }, }, ApprenticeshipLocationVenueCorrections = new List <ApprenticeshipLocationVenueCorrection> { new ApprenticeshipLocationVenueCorrection { LocationId = locationToFix.Id, VenueCorrection = venueCorrection, } } }; // Act var applyReturnValue = venueCorrector.Apply(apprenticeshipVenueCorrection); // Assert apprenticeshipVenueCorrection.Apprenticeship.ApprenticeshipLocations.Should().BeEquivalentTo(decoy1, locationToFix, decoy2); locationToFix.VenueId.Should().Be(venueCorrection.Id); locationToFix.UpdatedBy.Should().Be("VenueCorrector"); locationToFix.UpdatedDate.Should().Be(clock.UtcNow); decoy1.VenueId.Should().Be(Guid.Empty); decoy1.UpdatedBy.Should().BeNull(); decoy1.UpdatedDate.Should().BeNull(); decoy2.VenueId.Should().Be(Guid.Empty); decoy2.UpdatedBy.Should().BeNull(); decoy2.UpdatedDate.Should().BeNull(); apprenticeshipVenueCorrection.Apprenticeship.UpdatedBy.Should().Be("VenueCorrector"); apprenticeshipVenueCorrection.Apprenticeship.UpdatedDate.Should().Be(clock.UtcNow); applyReturnValue.Should().BeTrue("changes were applied"); }
public void FindsCorrectVenues(VenueTestCase venueTestCase) { var corruptVenueIds = new List <Guid?> { null, Guid.Empty, new Guid("7A518C84-77F7-4D29-B579-DA08C4B0EDA4"), new Guid("3FBDE15F-3E40-498B-AAA0-A3B8A7225B5D"), }; var potentialMatch = new VenueBuilder() .WithLatitude(60) // fixed value to avoid randomly matching .WithLongitude(-1) // fixed value to avoid randomly matching .Build(); var locationVenueName = venueTestCase.MatchingName ? potentialMatch.VenueName : "no-match"; var locationAddress = new ApprenticeshipLocationAddress { Address1 = venueTestCase.MatchingAddress1 ? potentialMatch.AddressLine1 : "no-match", Address2 = venueTestCase.MatchingAddress2 ? potentialMatch.AddressLine2 : "no-match", Town = venueTestCase.MatchingTown ? potentialMatch.Town : "no-match", County = venueTestCase.MatchingCounty ? potentialMatch.County : "no-match", Postcode = venueTestCase.MatchingPostcode ? potentialMatch.Postcode : "no-match", Latitude = venueTestCase.MatchingLatLong ? potentialMatch.Latitude : 50, Longitude = venueTestCase.MatchingLatLong ? potentialMatch.Longitude : 2, Email = venueTestCase.MatchingEmail ? potentialMatch.Email : "no-match", Phone = venueTestCase.MatchingPhone ? potentialMatch.PHONE : "no-match", Website = venueTestCase.MatchingWebsite ? potentialMatch.Website : "no-match", }; foreach (var corruptVenueId in corruptVenueIds) { TestVenueMatch(locationVenueName, locationAddress, corruptVenueId, potentialMatch, venueTestCase.ShouldReturnVenueCorrection, venueTestCase.Reason); } }
public void TestVenueAnalyser_ValidLocation_ReturnsCorrectAnalysis() { // Arrange var venue = new VenueBuilder().Build(); var apprenticeshipLocation = new ApprenticeshipLocation { RecordStatus = (int)ApprenticeshipStatus.Live, LocationType = LocationType.Venue, ApprenticeshipLocationType = ApprenticeshipLocationType.ClassroomBased, VenueId = venue.Id, Address = AddressFromVenue(venue), }; var apprenticeship = new Apprenticeship { Id = new Guid("80D875B3-3A2C-41C0-96D5-39DADB84CF0D"), ApprenticeshipLocations = new List <ApprenticeshipLocation> { apprenticeshipLocation }, }; // Act var apprenticeshipVenueCorrections = _venueAnalyser.AnalyseApprenticeship(apprenticeship, new List <Venue> { venue }); // Assert apprenticeshipVenueCorrections.Apprenticeship.Should().Be(apprenticeship); apprenticeshipVenueCorrections.UnfixableVenueReason.Should().BeNull(); apprenticeshipVenueCorrections.ApprenticeshipLocationVenueCorrections.Should().BeEmpty("the record isn't corrupt"); }
public void TestVenueAnalyser_WithDuplicateVenues_ReturnsCorrectAnalysis() { // Arrange var potentialMatch = new VenueBuilder() .WithLatitude(60) // fixed value to avoid randomly matching .WithLongitude(-1) // fixed value to avoid randomly matching .Build(); var duplicateMatch = VenueCloner.CloneVenue(potentialMatch); var availableVenues = new List <Venue> { new VenueBuilder().Build(), // decoy venue to make sure it doesn't pick the wrong one potentialMatch, duplicateMatch, }; var apprenticeshipLocation = new ApprenticeshipLocation { RecordStatus = (int)ApprenticeshipStatus.Live, LocationType = LocationType.Venue, ApprenticeshipLocationType = ApprenticeshipLocationType.ClassroomBased, VenueId = new Guid("F1724123-CCBA-4811-A816-128542299F87"), Address = AddressFromVenue(potentialMatch), }; var apprenticeship = new Apprenticeship { Id = new Guid("4E75B9D5-CC97-42EE-B891-5420F84EBAE9"), ApprenticeshipLocations = new List <ApprenticeshipLocation> { apprenticeshipLocation }, }; // Act var apprenticeshipVenueCorrections = _venueAnalyser.AnalyseApprenticeship(apprenticeship, availableVenues); // Assert apprenticeshipVenueCorrections.Apprenticeship.Should().Be(apprenticeship); apprenticeshipVenueCorrections.UnfixableVenueReason.Should().Be(null); var apprenticeshipLocationVenueCorrection = apprenticeshipVenueCorrections.ApprenticeshipLocationVenueCorrections.Should().ContainSingle().Subject; apprenticeshipLocationVenueCorrection.LocationId.Should().Be(apprenticeshipLocation.Id); apprenticeshipLocationVenueCorrection.VenueIdOriginal.Should().Be(apprenticeshipLocation.VenueId); apprenticeshipLocationVenueCorrection.CorruptionType.Should().Be(CorruptionType.VenueNotInProvidersLiveVenueList); apprenticeshipLocationVenueCorrection.UnfixableLocationVenueReason.Should().Be(UnfixableLocationVenueReasons.DuplicateMatchingVenues); apprenticeshipLocationVenueCorrection.DuplicateVenues.Should().BeEquivalentTo(potentialMatch, duplicateMatch); }
public void FindsMatchingDuplicateVenues() // seen in dev data { var potentialMatch = new VenueBuilder() .WithLatitude(60) // fixed value to avoid randomly matching .WithLongitude(-1) // fixed value to avoid randomly matching .Build(); var duplicateMatch = VenueCloner.CloneVenue(potentialMatch); var availableVenues = new List <Venue> { new VenueBuilder().Build(), // decoy venue to make sure it doesn't pick the wrong one potentialMatch, duplicateMatch, }; var locationVenueName = potentialMatch.VenueName; var locationAddress = new ApprenticeshipLocationAddress { Address1 = potentialMatch.AddressLine1, Address2 = potentialMatch.AddressLine2, Town = potentialMatch.Town, County = potentialMatch.County, Postcode = potentialMatch.Postcode, Latitude = potentialMatch.Latitude, Longitude = potentialMatch.Longitude, Email = potentialMatch.Email, Phone = potentialMatch.PHONE, Website = potentialMatch.Website, }; var location = new ApprenticeshipLocation { VenueId = Guid.Empty, RecordStatus = (int)ApprenticeshipStatus.Live, Name = locationVenueName, Address = locationAddress, }; // act var matchingVenues = new VenueCorrectionFinder().GetMatchingVenues(location, availableVenues); matchingVenues.Should().BeEquivalentTo(duplicateMatch, potentialMatch); }
public void TestVenueAnalyser_LocationWithMatchingVenue_ReturnsCorrectAnalysis() { // Arrange var venue = new VenueBuilder().Build(); var apprenticeshipLocation = new ApprenticeshipLocation { RecordStatus = (int)ApprenticeshipStatus.Live, LocationType = LocationType.Venue, ApprenticeshipLocationType = ApprenticeshipLocationType.ClassroomBased, VenueId = new Guid("62915572-18E1-4780-849A-6050E78B5008"), Address = AddressFromVenue(venue) }; var apprenticeship = new Apprenticeship { Id = new Guid("80D875B3-3A2C-41C0-96D5-39DADB84CF0D"), ApprenticeshipLocations = new List <ApprenticeshipLocation> { apprenticeshipLocation }, }; // Act var apprenticeshipVenueCorrections = _venueAnalyser.AnalyseApprenticeship(apprenticeship, new List <Venue> { venue }); // Assert apprenticeshipVenueCorrections.Apprenticeship.Should().Be(apprenticeship); apprenticeshipVenueCorrections.UnfixableVenueReason.Should().BeNull(); var apprenticeshipLocationVenueCorrection = apprenticeshipVenueCorrections.ApprenticeshipLocationVenueCorrections.Should().ContainSingle().Subject; apprenticeshipLocationVenueCorrection.LocationId.Should().Be(apprenticeshipLocation.Id); apprenticeshipLocationVenueCorrection.VenueIdOriginal.Should().Be(apprenticeshipLocation.VenueId); apprenticeshipLocationVenueCorrection.CorruptionType.Should().Be(CorruptionType.VenueNotInProvidersLiveVenueList); apprenticeshipLocationVenueCorrection.UnfixableLocationVenueReason.Should().BeNull(); apprenticeshipLocationVenueCorrection.VenueCorrection.Should().Be(venue); }