public void SaveMatch_InputAndMatchAreSameButDifferentCase_NotSaved() { // Arrange const string inputName1 = "P1"; const string inputName2 = "T1"; const string inputName3 = "V1"; const string gazName1 = "p1"; // same as input, case different const string gazName2 = "t1"; // same as input, case different const string gazName3 = "v1"; // same as input, case different // Arrange // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); //match provider var mock = MockRepository.GenerateMock<IMatchProvider>(); MatchedNames matchedNames = new MatchedNames(mock); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match from gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); // Assert AssertNoSavesCalled(mock); }
private void SubstituteMainForAltNames( MatchedName match, GazetteerNames gazetteerNames) { SubstituteAltGazetteerName(match.GazetteerLocation, gazetteerNames); SubstituteAltInputName(match.InputLocation, gazetteerNames); }
private static void SubstituteAltInputName( Location location, GazetteerNames gazetteerNames) { if (!string.IsNullOrEmpty(location.Name1)) { string main = gazetteerNames.GetMainLevel1(location.Name1); if (!string.IsNullOrEmpty(main)) { location.Name1 = main; } } if (!string.IsNullOrEmpty(location.Name2)) { string main = gazetteerNames.GetMainLevel2(location.Name1, location.Name2); if (!string.IsNullOrEmpty(main)) { location.Name2 = main; } } if (!string.IsNullOrEmpty(location.Name3)) { string main = gazetteerNames.GetMainLevel3( location.Name1, location.Name2, location.Name3); if (!string.IsNullOrEmpty(main)) { location.Name3 = main; } } }
public void Level1AllLocationNames_LeadingAndTrailingSpacesRemoved() { // arrange GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // act IList<string> result = gazetteerNames.Level1AllLocationNames(); // assert // no leading or trailing spaces Assert.IsFalse(result.Any(x => x.StartsWith(" "))); Assert.IsFalse(result.Any(x => x.EndsWith(" "))); }
public void Level1AllLocationNames_NoBlankOrNullReturned() { // arrange GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // act IList<string> result = gazetteerNames.Level1AllLocationNames(); // assert // no null or empty strings Assert.IsFalse(result.Contains("")); Assert.IsFalse(result.Contains(null)); }
private static void SubstituteAltGazetteerName( Location location, GazetteerNames gazetteerNames) { if (!string.IsNullOrEmpty(location.Name1)) { string main = gazetteerNames.GetMainLevel1(location.Name1); if (main == null) { throw new ArgumentException( string.Format( "Location match not in in the gazetteer[{0}", location.Name1), "location"); } location.Name1 = main; } if (!string.IsNullOrEmpty(location.Name2)) { string main = gazetteerNames.GetMainLevel2(location.Name1, location.Name2); if (main == null) { throw new ArgumentException( string.Format( "Location match not in in the gazetteer[{0}", location.Name2), "location"); } location.Name2 = main; } if (!string.IsNullOrEmpty(location.Name3)) { string main = gazetteerNames.GetMainLevel3( location.Name1, location.Name2, location.Name3); if (main == null) { throw new ArgumentException( string.Format( "Location match not in in the gazetteer[{0}", location.Name3), "location"); } location.Name3 = main; } }
private static void ValidateLevel1Match( MatchedName match, GazetteerNames gazetteerNames, StringBuilder stringBuilder) { if (gazetteerNames.IsInLevel1Names(match.InputLocation.Name1)) { if (match.Level1NotSame()) { // The input value is in the gazetteer but is not the same as the selected match stringBuilder.Append(match.OriginalInput.Name1); } } }
public void Level2AllLocationNames_MainLevel1Name_MainAndAltNamesReturned() { // arrange GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // act IList<string> result = gazetteerNames.Level2AllLocationNames("P1"); // assert // expected T1,T2, T1A, T2A Assert.AreEqual(4, result.Count); List<string> expected = new List<string> {"T1", "T2", "T1A", "T2A"}; IEnumerable<string> dif = result.Except(expected); Assert.AreEqual(0, dif.Count()); }
private static void ValidateLevel3Match( MatchedName match, GazetteerNames gazetteerNames, StringBuilder errorMessage) { if (gazetteerNames.IsInLevel3Names( match.InputLocation.Name3, match.InputLocation.Name1, match.InputLocation.Name2)) { if (match.Level3NotSame()) { // The input value is in the gazetteer but is not the same as the selected match errorMessage.Append(match.OriginalInput.Name3); } } }
private static void ValidateMatch(MatchedName match, GazetteerNames gazetteerNames) { StringBuilder errorMessage = new StringBuilder(); // We do not allow saved matches for input names that already exist in the gazetteer // as this would result in conflicting information so throw ex if the input // is in the gazetteer and is not the same as the selection. ValidateLevel1Match(match, gazetteerNames, errorMessage); ValidateLevel2Match(match, gazetteerNames, errorMessage); ValidateLevel3Match(match, gazetteerNames, errorMessage); if (errorMessage.Length > 0) { string message = string.Format( "Input name is already in the gazetteer, cannot save match: {0} ", errorMessage); throw new NameInGazetteerException(message); } }
public void SaveMatch( Location inputLocation, Location gazetteerLocation, GazetteerNames gazetteerNames) { Validate(inputLocation); Validate(gazetteerLocation); MatchedName match = new MatchedName(inputLocation, gazetteerLocation); // Don't save alts to the db SubstituteMainForAltNames(match, gazetteerNames); // Throw ex if the input already exists in the gazetteer ValidateMatch(match, gazetteerNames); SaveMatchLevel1(match); SaveMatchLevel2(match); SaveMatchLevel3(match); }
public void SaveMatch_MatchIsAltEquivalentToInput_NotSaved() { // Arrange const string inputName1 = "P1"; const string inputName2 = "T1"; const string inputName3 = "V1"; const string gazName1 = "P1A"; // ignore as is equivalent const string gazName2 = "T1A"; // ignore as is equivalent const string gazName3 = "V1A"; // ignore as is equivalent // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // no existing saved matches var mock = MockRepository.GenerateMock<IMatchProvider>(); MatchedNames matchedNames = new MatchedNames(mock); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match to gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); // Assert AssertNoSavesCalled(mock); }
private static void SaveMatchWithGazetteerTestData1( string inputName1, string inputName2, string inputName3, string gazName1, string gazName2, string gazName3) { // Arrange // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // no existing saved matches MatchedNames matchedNames = new MatchedNames(MatchProviderStub.EmptyStub()); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match from gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); }
public void SaveMatch_InputContains1ValidLevel_MatchSaved() { // Arrange const string inputName1 = "P1x"; const string gazName1 = "P1"; // main value in gaz // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); //match provider var mock = MockRepository.GenerateMock<IMatchProvider>(); MatchedNames matchedNames = new MatchedNames(mock); // input Location inputLocation = new Location(inputName1); // match from gazetteer Location gazetteerLocation = new Location(gazName1); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); // Assert mock.AssertWasCalled(x => x.SaveMatchLevel1(inputName1, gazName1)); mock.AssertWasNotCalled( x => x.SaveMatchLevel2( Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything)); mock.AssertWasNotCalled( x => x.SaveMatchLevel3( Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything)); }
public void Level3AllLocationNames_SearchNamesCaseDiffToGaz_ListIsSame() { // arrange GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // act IList<string> result1 = gazetteerNames.Level3AllLocationNames("P2A", "T2A"); IList<string> result2 = gazetteerNames.Level3AllLocationNames("p2a", "t2a"); // assert // expected that the results are the same Assert.AreEqual(result1.Count, result2.Count); IEnumerable<string> dif = result1.Except(result2); Assert.AreEqual(0, dif.Count()); }
public void Level3AllLocationNames_MainLevel1And2Names_MainAndAltNamesReturned() { // arrange GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // act IList<string> result = gazetteerNames.Level3AllLocationNames("P2", "T2"); // assert // expected V1,V2, V3, V1A Assert.AreEqual(4, result.Count); List<string> expected = new List<string> {"V1", "V2", "V3", "V1A"}; IEnumerable<string> dif = result.Except(expected); Assert.AreEqual(0, dif.Count()); }
public void SaveMatch_InputLevel3IsBlank_OnlyLevel1And2Saved() { // Arrange const string inputName1 = "P1x"; const string inputName2 = "T1x"; const string inputName3 = ""; const string gazName1 = "P1"; const string gazName2 = "T1"; const string gazName3 = "V1"; // Arrange // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); //match provider var mock = MockRepository.GenerateMock<IMatchProvider>(); MatchedNames matchedNames = new MatchedNames(mock); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match from gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); // Assert // level 1 and 2 save called mock.AssertWasCalled( x => x.SaveMatchLevel1(inputName1, gazName1)); mock.AssertWasCalled( x => x.SaveMatchLevel2( inputName2, gazName1, gazName2)); mock.AssertWasNotCalled( x => x.SaveMatchLevel3( Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything, Arg<string>.Is.Anything)); }
public void SaveMatch_MatchIsBlank_NotSaved() { // Arrange const string inputName1 = "P1x"; const string inputName2 = "T1x"; const string inputName3 = "V1x"; const string gazName1 = ""; const string gazName2 = ""; const string gazName3 = ""; // Arrange // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); //match provider var mock = MockRepository.GenerateMock<IMatchProvider>(); MatchedNames matchedNames = new MatchedNames(mock); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match from gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); // Assert AssertNoSavesCalled(mock); }
public void SaveMatch_InputLevel3ExistsInGazAsMain_ExceptionThrown() { // Arrange const string inputName1 = "P1"; const string inputName2 = "T1"; const string inputName3 = "V2"; // in gaz const string gazName1 = "P1"; const string gazName2 = "T1"; const string gazName3 = "V1"; // not allowed // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // no existing saved matches MatchedNames matchedNames = new MatchedNames(MatchProviderStub.EmptyStub()); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match from gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); // Assert // exception thrown }
internal SuggestedMatch(GazetteerNames gazetteerNames) { this.gazetteerNames = gazetteerNames; }
public void SaveMatch_InputAndMatchAreValid_MatchSaved() { // Arrange const string inputName1 = "P1x"; const string inputName2 = "T1x"; const string inputName3 = "V1x"; const string gazName1 = "P1"; // main value in gaz const string gazName2 = "T1"; // main value in gaz const string gazName3 = "V1"; // main value in gaz // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); //match provider var mock = MockRepository.GenerateMock<IMatchProvider>(); MatchedNames matchedNames = new MatchedNames(mock); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match from gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); // Assert mock.AssertWasCalled(x => x.SaveMatchLevel1(inputName1, gazName1)); mock.AssertWasCalled(x => x.SaveMatchLevel2(inputName2, gazName1, gazName2)); mock.AssertWasCalled( x => x.SaveMatchLevel3(inputName3, gazName1, gazName2, gazName3)); }
public void SaveMatch_InputLevel1IsAltEquivalentToMatch_Level2And3Saved() { // Arrange const string inputName1 = "P1A"; const string inputName2 = "T1x"; const string inputName3 = "V1x"; const string gazName1 = "P1"; // ignore as is equivalent const string gazName2 = "T1"; // valid match const string gazName3 = "V1"; // valid match // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // no existing saved matches var mock = MockRepository.GenerateMock<IMatchProvider>(); MatchedNames matchedNames = new MatchedNames(mock); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match from gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); // Assert mock.AssertWasNotCalled( x => x.SaveMatchLevel1(Arg<string>.Is.Anything, Arg<string>.Is.Anything)); mock.AssertWasCalled(x => x.SaveMatchLevel2(inputName2, gazName1, gazName2)); mock.AssertWasCalled( x => x.SaveMatchLevel3(inputName3, gazName1, gazName2, gazName3)); }
public void SaveMatch_InputLevel3ExistsInGazAsMain_NotSaved() { // Arrange const string inputName1 = "P1"; const string inputName2 = "T1"; const string inputName3 = "V2"; // in gaz const string gazName1 = "P1"; const string gazName2 = "T1"; const string gazName3 = "V1"; // not allowed // gazetteer data - use test data 1 GazetteerNames gazetteerNames = new GazetteerNames( GazetteerTestData.TestData1()); // no existing saved matches var mock = MockRepository.GenerateMock<IMatchProvider>(); MatchedNames matchedNames = new MatchedNames(mock); // input Location inputLocation = new Location(inputName1, inputName2, inputName3); // match from gazetteer Location gazetteerLocation = new Location(gazName1, gazName2, gazName3); // Act try { matchedNames.SaveMatch(inputLocation, gazetteerLocation, gazetteerNames); } catch (Exception) { //ignore the exception for this test } // Assert AssertNoSavesCalled(mock); }