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

Reset mapping before loading configuration #1467

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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ImporterPresenter(
_importerDataPresenter.OnTabChanged += onTabChanged;
_importerDataPresenter.OnDataChanged += onImporterDataChanged;
_columnMappingPresenter.OnMissingMapping += onMissingMapping;
_columnMappingPresenter.OnResetMappingBasedOnCurrentSheet += onResetMappingBasedOnCurrentSheet;
_columnMappingPresenter.OnResetMappingBasedOnCurrentSheet += (o, e) => onResetMappingBasedOnCurrentSheet();
_columnMappingPresenter.OnMappingCompleted += onCompletedMapping;
View.DisableConfirmationView();
}
Expand Down Expand Up @@ -232,7 +232,7 @@ private void onTabChanged(object sender, TabChangedEventArgs e)
_columnMappingPresenter.SetRawData(e.TabData);
}

private void onResetMappingBasedOnCurrentSheet(object sender, EventArgs e)
protected virtual void onResetMappingBasedOnCurrentSheet()
{
if (confirmDroppingOfLoadedSheets())
return;
Expand Down Expand Up @@ -387,7 +387,7 @@ private void loadImportedDataSetsFromConfiguration(ImporterConfiguration configu
_importerDataPresenter.DisableImportedSheets();
}

private bool confirmDroppingOfLoadedSheets()
protected virtual bool confirmDroppingOfLoadedSheets()
{
return _dataSource.DataSets.Count != 0 && _dialogCreator.MessageBoxYesNo(Captions.Importer.ActionWillEraseLoadedData) != ViewResult.Yes;
}
Expand All @@ -404,6 +404,8 @@ public void LoadConfigurationWithoutImporting()
if (confirmDroppingOfLoadedSheets())
return;

onResetMappingBasedOnCurrentSheet();

var fileName = _dialogCreator.AskForFileToOpen(Captions.Importer.ApplyConfiguration, Constants.Filter.XML_FILE_FILTER,
Constants.DirectoryKey.OBSERVED_DATA);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace OSPSuite.Presentation.Importer.Presenters
{
internal class ImporterPresenterForTest : ImporterPresenter
{
public bool OnResetMappingBasedOnCurrentSheetInvoked { get; set; }

public ImporterPresenterForTest(
IImporterView view,
IDataSetToDataRepositoryMapper dataRepositoryMapper,
Expand All @@ -40,6 +42,17 @@ IDataSource dataSource
{
_dataSource = dataSource;
}

protected override void onResetMappingBasedOnCurrentSheet()
{
OnResetMappingBasedOnCurrentSheetInvoked = true;
base.onResetMappingBasedOnCurrentSheet();
}

protected override bool confirmDroppingOfLoadedSheets()
{
return false;
}
}

public abstract class concern_for_ImporterPresenter : ContextSpecification<ImporterPresenter>
Expand Down Expand Up @@ -429,4 +442,19 @@ public void must_filter_empty_mappings()
).MustHaveHappened();
}
}

public class When_loading_configuration_from_button : concern_for_ImporterPresenter
{
protected override void Because()
{
(sut as ImporterPresenterForTest).OnResetMappingBasedOnCurrentSheetInvoked = false;
sut.LoadConfigurationWithoutImporting();
}

[Observation]
public void must_reset_format_based_on_current_sheet()
{
(sut as ImporterPresenterForTest).OnResetMappingBasedOnCurrentSheetInvoked.ShouldBeTrue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat.

}
}
}