public void GetLocationCodes_GazContainsDuplicateCombinedLevel2And3_CorrectCodesAdded() { // Arrange // gazetteer data GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - string[] inputNames = {"P1", "T1V", "1"}; // names 4 Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // correct codes added (codes 4) Assert.AreEqual(codes4[0], codedLocation.GeoCode1.Code); Assert.AreEqual(codes4[1], codedLocation.GeoCode2.Code); Assert.AreEqual(codes4[2], codedLocation.GeoCode3.Code); }
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); }
public void GetCodes_Leve1And2CorrectAndLevel3HasSavedMatch_AllCodesAdded() { // Arrange // gazetteer data - contains codes for names1 and names2 GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - level 3 miss-spelt string[] inputNames = {"P1", "T1", "V1x"}; Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // saved matches MatchProviderStub matchProviderStub = MatchProviderStubLevel3(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // code 1, 2 and 3 codes added Assert.AreEqual(codes1[0], codedLocation.GeoCode1.Code); Assert.AreEqual(names1[0], codedLocation.GeoCode1.Name); Assert.AreEqual(codes1[1], codedLocation.GeoCode2.Code); Assert.AreEqual(names1[1], codedLocation.GeoCode2.Name); Assert.AreEqual(codes1[2], codedLocation.GeoCode3.Code); Assert.AreEqual(names1[2], codedLocation.GeoCode3.Name); }
public MatchedName(Location inputLocation, Location gazetteerLocation) { InputLocation = inputLocation; // keep a copy OriginalInput = new Location( inputLocation.Name1, inputLocation.Name2, inputLocation.Name3); GazetteerLocation = gazetteerLocation; // keep a copy OriginalGazetteer = new Location( gazetteerLocation.Name1, gazetteerLocation.Name2, gazetteerLocation.Name3); }
public CodedLocation(Location location) { if (location == null) throw new ArgumentNullException("location"); // keep a copy of the input location for comparison inputLocation = new Location(location.Name1, location.Name2, location.Name3); // initialise the names Name1 = string.Copy(inputLocation.Name1); if (inputLocation.Name2 != null) { Name2 = string.Copy(inputLocation.Name2); } if (inputLocation.Name3 != null) { Name3 = string.Copy(inputLocation.Name3); } }
public void GetLocationCodes_Level1And2GazetteerAltName_AllCodesAdded() { // Arrange // gazetteer data - contains codes for names1 and names2 and // an alternate name for name 1 and 2 string[] altNames = {"P1A", "T1A", null}; GazetteerRecords gazetteerRecords = GazetteerTestData(altNames); // gazetteerRecords.AddLine(names2, codes2); // input data - Level 1 and 2 contains alt spelling, the rest are spelt correctly string[] inputNames = {"P1A", "T1A", "V1"}; Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // code 1, 2 and 3 codes added Assert.AreEqual(codes1[0], codedLocation.GeoCode1.Code); Assert.AreEqual(names1[0], codedLocation.GeoCode1.Name); Assert.AreEqual(codes1[1], codedLocation.GeoCode2.Code); Assert.AreEqual(names1[1], codedLocation.GeoCode2.Name); Assert.AreEqual(codes1[2], codedLocation.GeoCode3.Code); Assert.AreEqual(names1[2], codedLocation.GeoCode3.Name); }
private CodedLocation FindCodes( Coder coder, DataRow dataRow, bool useCache) { //create location, use the original name Location location = new Location(); location.Name1 = dataRow[ColumnHeaders.Level1].ToString(); // level 2 is optional if (!string.IsNullOrEmpty(ColumnHeaders.Level2)) { location.Name2 = dataRow[ColumnHeaders.Level2].ToString(); } // level 3 is optional if (!string.IsNullOrEmpty(ColumnHeaders.Level3)) { location.Name3 = dataRow[ColumnHeaders.Level3].ToString(); } // get codes CodedLocation codedLocation = coder.GetCodes(location, useCache); return codedLocation; }
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)); }
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 GetLocationCodes_Level1Correct_Level1CodeAdded() { // Arrange // gazetteer data - contains codes for names1 and names2 GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - no level 3 supplied string[] inputNames = {"P1", null, null}; Location location = new Location( inputNames[0]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // level 1 code only added Assert.AreEqual(codes1[0], codedLocation.GeoCode1.Code); Assert.AreEqual(names1[0], codedLocation.GeoCode1.Name); Assert.AreEqual(null, codedLocation.GeoCode2); Assert.AreEqual(null, codedLocation.GeoCode3); }
public void GetLocationCodes_Level1Incorrect_NoCodesAdded() { // Arrange // gazetteer data - contains codes for names1 and names2 GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - level 2 miss-spelt string[] inputNames = {"P1x", "T1", "V1"}; Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // no codes added Assert.AreEqual(null, codedLocation.GeoCode1); Assert.AreEqual(null, codedLocation.GeoCode2); Assert.AreEqual(null, codedLocation.GeoCode3); }
private void UpdateRow() { string originalLevel1 = txtLevel1Original.Text; string originalLevel2 = txtLevel2Original.Text; string originalLevel3 = txtLevel3Original.Text; Location location2 = new Location( originalLevel1, originalLevel2, originalLevel3); CodedLocation codedLocation = geoCoder.AddLocationCodes(location2); ClearExistingCodes(); AddCodes(codedLocation); int rowCount = dataGridView1.RowCount; DisplayRecords(); if (dataGridView1.RowCount == rowCount) { SelectNextRow(); } }
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 }
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_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_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); }
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_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); }
protected bool Equals(Location other) { return string.Equals( Name1, other.Name1, StringComparison.InvariantCultureIgnoreCase) && string.Equals( Name2, other.Name2, StringComparison.InvariantCultureIgnoreCase) && string.Equals( Name3, other.Name3, StringComparison.InvariantCultureIgnoreCase); }
public void GetLocationCodes_Leve1And2CorrectAndLevel3Incorrect_Level1And2CodeAddedOnly() { // Arrange // gazetteer data - contains codes for names1 and names2 GazetteerRecords gazetteerRecords = GazetteerTestData(); // input data - level 3 miss-spelt string[] inputNames = {"P1", "T1", "V1x"}; Location location = new Location( inputNames[0], inputNames[1], inputNames[2]); // no saved matches MatchProviderStub matchProviderStub = MatchProviderStubEmpty(inputNames); Coder coder = new Coder( gazetteerRecords.GadmList(), matchProviderStub.MatchProvider()); // Act CodedLocation codedLocation = coder.GetCodes(location); // Assert // code 1 and 2 only are added, no level 3 code added Assert.AreEqual(codes1[0], codedLocation.GeoCode1.Code); Assert.AreEqual(names1[0], codedLocation.GeoCode1.Name); Assert.AreEqual(codes1[1], codedLocation.GeoCode2.Code); Assert.AreEqual(names1[1], codedLocation.GeoCode2.Name); Assert.AreEqual(null, codedLocation.GeoCode3); }
private void SaveSelectedMatch(string level1, string level2, string level3) { Location inputLocation = new Location( Level1Original(), Level2Original(), Level3Original()); Location gazetteerLocation = new Location(level1, level2, level3); geoCoder.SaveMatch(inputLocation, gazetteerLocation); }
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)); }