Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2176 Data importer: error when "Reload under the same settings" #2251

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/OSPSuite.Presentation/Services/DataImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,22 @@ public override ReloadDataSets CalculateReloadDataSetsFromConfiguration(IReadOnl

public override bool AreFromSameMetaDataCombination(DataRepository sourceDataRepository, DataRepository targetDataRepository)
{
return targetDataRepository.ExtendedProperties.KeyValues.All(keyValuePair =>
keyValuePair.Key == Constants.FILE || //Ignore source file
Equals(sourceDataRepository.ExtendedProperties[keyValuePair.Key].ValueAsObject, keyValuePair.Value.ValueAsObject)
return compareMetaData(sourceDataRepository, targetDataRepository) && compareMetaData(targetDataRepository, sourceDataRepository);
}

private static bool compareMetaData(DataRepository firstRepository, DataRepository secondRepository)
{
// do not compare the file name when checking for equivalent metadata
return secondRepository.ExtendedProperties.KeyValues.Where(x => !Equals(x.Key, Constants.FILE)).All(keyValuePair =>
hasEquivalentMetaData(firstRepository.ExtendedProperties, keyValuePair)
);
}

private static bool hasEquivalentMetaData(ExtendedProperties sourceExtendedProperties, KeyValuePair<string, IExtendedProperty> keyValuePair)
{
return sourceExtendedProperties.Contains(keyValuePair.Key) && Equals(sourceExtendedProperties[keyValuePair.Key].ValueAsObject, keyValuePair.Value.ValueAsObject);
}

private bool repositoryExistsInList(IEnumerable<DataRepository> dataRepositoryList, DataRepository targetDataRepository)
{
return dataRepositoryList.Any(dataRepo => AreFromSameMetaDataCombination(dataRepo, targetDataRepository));
Expand Down
113 changes: 90 additions & 23 deletions tests/OSPSuite.UI.Tests/Services/DataImporterSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public abstract class concern_for_DataImporter : ContextSpecification<IDataImpor
protected IReadOnlyList<DataRepository> _existingDataSets;
protected IReadOnlyList<DataRepository> _dataSetsToImport;



public override void GlobalContext()
{
base.GlobalContext();
Expand All @@ -38,62 +36,64 @@ public override void GlobalContext()

A.CallTo(() => _applicationController.Start<IImporterReloadPresenter>()).Returns(_reloadPresenter);
A.CallTo(() => _reloadPresenter.Canceled()).Returns(false);

}

protected override void Context()
{
_existingDataSets = new List<DataRepository>()
_existingDataSets = new List<DataRepository>
{
new DataRepository()
new DataRepository
{
Name = "repo1",
ExtendedProperties =
{
new ExtendedProperty<string>() {Name = "Sheet", Value = "Sheet1"},
new ExtendedProperty<string>() {Name = "Organ", Value = "Organ1"},
new ExtendedProperty<string>() {Name = "Patient", Value = "Patient1"},
new ExtendedProperty<string> { Name = "Sheet", Value = "Sheet1" },
new ExtendedProperty<string> { Name = "Organ", Value = "Organ1" },
new ExtendedProperty<string> { Name = "Patient", Value = "Patient1" },
new ExtendedProperty<string> { Name = Constants.FILE, Value = "File1" }
}
},
new DataRepository()
new DataRepository
{
Name = "repo2",
ExtendedProperties =
{
new ExtendedProperty<string>() {Name = "Sheet", Value = "Sheet2"},
new ExtendedProperty<string>() {Name = "Organ", Value = "Organ2"},
new ExtendedProperty<string>() {Name = "Patient", Value = "Patient2"},
new ExtendedProperty<string> { Name = "Sheet", Value = "Sheet2" },
new ExtendedProperty<string> { Name = "Organ", Value = "Organ2" },
new ExtendedProperty<string> { Name = "Patient", Value = "Patient2" },
new ExtendedProperty<string> { Name = Constants.FILE, Value = "File2" }
}
}
};
_dataSetsToImport = new List<DataRepository>()
_dataSetsToImport = new List<DataRepository>
{
new DataRepository()
new DataRepository
{
Name = "repo1",
ExtendedProperties =
{
new ExtendedProperty<string>() {Name = "Sheet", Value = "Sheet1"},
new ExtendedProperty<string>() {Name = "Organ", Value = "Organ1"},
new ExtendedProperty<string>() {Name = "Patient", Value = "Patient1"},
new ExtendedProperty<string> { Name = "Sheet", Value = "Sheet1" },
new ExtendedProperty<string> { Name = "Organ", Value = "Organ1" },
new ExtendedProperty<string> { Name = "Patient", Value = "Patient1" },
new ExtendedProperty<string> { Name = Constants.FILE, Value = "File1" }
}
},
new DataRepository()
{
Name = "repo2",
ExtendedProperties =
{
new ExtendedProperty<string>() {Name = "Sheet", Value = "Sheet2"},
new ExtendedProperty<string>() {Name = "Organ", Value = "Organ2"},
new ExtendedProperty<string>() {Name = "Patient", Value = "Patient2"},
new ExtendedProperty<string> { Name = "Sheet", Value = "Sheet2" },
new ExtendedProperty<string> { Name = "Organ", Value = "Organ2" },
new ExtendedProperty<string> { Name = "Patient", Value = "Patient2" },
new ExtendedProperty<string> { Name = Constants.FILE, Value = "File2" }
}
}
};
sut = new DataImporter(_dialogCreator, _importer , _applicationController, _dimensionFactory);
sut = new DataImporter(_dialogCreator, _importer, _applicationController, _dimensionFactory);
}
}


public class When_reloading_only_existing_data_sets : concern_for_DataImporter
{
private ReloadDataSets _result;
Expand Down Expand Up @@ -124,6 +124,74 @@ public void should_return_empty_deleted_data_sets()
}
}

public class When_reloading_a_data_set_with_only_file_name_changed : concern_for_DataImporter
{
private ReloadDataSets _result;

protected override void Context()
{
base.Context();
_existingDataSets.FirstOrDefault(x => x.Name == "repo2").ExtendedProperties[Constants.FILE].ValueAsObject = "Another file";
}

protected override void Because()
{
_result = sut.CalculateReloadDataSetsFromConfiguration(_dataSetsToImport, _existingDataSets);
}

[Test]
public void should_return_no_new_data_sets()
{
_result.NewDataSets.Count().ShouldBeEqualTo(0);
}
}

public class When_reloading_a_data_set_with_new_meta_data : concern_for_DataImporter
{
private ReloadDataSets _result;

protected override void Context()
{
base.Context();
_existingDataSets.FirstOrDefault(x => x.Name == "repo2").ExtendedProperties.Remove("Organ");
}

protected override void Because()
{
_result = sut.CalculateReloadDataSetsFromConfiguration(_dataSetsToImport, _existingDataSets);
}

[Test]
public void should_return_one_new_data_set()
{
_result.NewDataSets.Count().ShouldBeEqualTo(1);
_result.NewDataSets.Any(x => x.Name == "repo2").ShouldBeTrue();
}
}

public class When_reloading_a_data_set_with_removed_meta_data : concern_for_DataImporter
{
private ReloadDataSets _result;

protected override void Context()
{
base.Context();
_dataSetsToImport.FirstOrDefault(x => x.Name == "repo2").ExtendedProperties.Remove("Organ");
}

protected override void Because()
{
_result = sut.CalculateReloadDataSetsFromConfiguration(_dataSetsToImport, _existingDataSets);
}

[Test]
public void should_return_one_new_data_set()
{
_result.NewDataSets.Count().ShouldBeEqualTo(1);
_result.NewDataSets.Any(x => x.Name == "repo2").ShouldBeTrue();
}
}

public class When_reloading_one_new_data_set_one_data_set_to_be_deleted : concern_for_DataImporter
{
private ReloadDataSets _result;
Expand All @@ -133,7 +201,6 @@ protected override void Context()
base.Context();
_dataSetsToImport.FirstOrDefault(x => x.Name == "repo2").ExtendedProperties["Organ"].ValueAsObject = "Organ3";
_dataSetsToImport.FirstOrDefault(x => x.Name == "repo2").Name = "repo3";

}

protected override void Because()
Expand Down