Index: Riskeer/Integration/src/Riskeer.Integration.IO/Importers/AssemblyImporter.cs =================================================================== diff -u --- Riskeer/Integration/src/Riskeer.Integration.IO/Importers/AssemblyImporter.cs (revision 0) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Importers/AssemblyImporter.cs (revision 56f43c026e0a30b3000d96fb496924f7d25efda8) @@ -0,0 +1,51 @@ +using Core.Common.Base.IO; +using Core.Common.IO.Readers; +using Riskeer.AssemblyTool.IO; +using Riskeer.AssemblyTool.IO.Model; +using Riskeer.Integration.IO.Assembly; + +namespace Riskeer.Integration.IO.Importers +{ + public class AssemblyImporter : FileImporterBase + { + public AssemblyImporter(ExportableAssessmentSection importTarget, string filePath) + : base(filePath, importTarget) {} + + protected override void LogImportCanceledMessage() + { + } + + protected override bool OnImport() + { + ReadResult readSerializableAssembly = ReadAssembly(); + if (readSerializableAssembly.CriticalErrorOccurred) + { + return false; + } + + return true; + } + + private ReadResult ReadAssembly() + { + try + { + using (var reader = new SerializableAssemblyReader(FilePath)) + { + return new ReadResult(false) + { + Items = new[] + { + reader.Read() + } + }; + } + } + catch (CriticalFileReadException e) + { + Log.Error(e.Message); + return new ReadResult(true); + } + } + } +} Index: Riskeer/Integration/src/Riskeer.Integration.IO/Riskeer.Integration.IO.csproj =================================================================== diff -u -r71cd7f49ce3b31f4989a61a853380c1dfec16344 -r56f43c026e0a30b3000d96fb496924f7d25efda8 --- Riskeer/Integration/src/Riskeer.Integration.IO/Riskeer.Integration.IO.csproj (.../Riskeer.Integration.IO.csproj) (revision 71cd7f49ce3b31f4989a61a853380c1dfec16344) +++ Riskeer/Integration/src/Riskeer.Integration.IO/Riskeer.Integration.IO.csproj (.../Riskeer.Integration.IO.csproj) (revision 56f43c026e0a30b3000d96fb496924f7d25efda8) @@ -88,6 +88,7 @@ + Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Importers/AssemblyImporterTest.cs =================================================================== diff -u --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Importers/AssemblyImporterTest.cs (revision 0) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Importers/AssemblyImporterTest.cs (revision 56f43c026e0a30b3000d96fb496924f7d25efda8) @@ -0,0 +1,56 @@ +using System; +using System.IO; +using Core.Common.Base.Geometry; +using Core.Common.Base.IO; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.Integration.IO.Assembly; +using Riskeer.Integration.IO.Importers; + +namespace Riskeer.Integration.IO.Test.Importers +{ + [TestFixture] + public class AssemblyImporterTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var importer = new AssemblyImporter(CreateExportableAssessmentSection(), ""); + + // Assert + Assert.IsInstanceOf>(importer); + } + + [Test] + public void Import_FilePathIsDirectory_CancelImportWithErrorMessage() + { + // Setup + string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Integration.IO, Path.DirectorySeparatorChar.ToString()); + + var importer = new AssemblyImporter(CreateExportableAssessmentSection(), path); + + // Call + var importSuccessful = true; + Action call = () => importSuccessful = importer.Import(); + + // Assert + string expectedMessage = $"Fout bij het lezen van bestand '{path}': bestandspad mag niet verwijzen naar een lege bestandsnaam."; + TestHelper.AssertLogMessageWithLevelIsGenerated(call, new Tuple(expectedMessage, LogLevelConstant.Error), 1); + Assert.IsFalse(importSuccessful); + } + + private static ExportableAssessmentSection CreateExportableAssessmentSection() + { + var random = new Random(21); + return new ExportableAssessmentSection("", "", new Point2D[0], + new ExportableAssessmentSectionAssemblyResult(random.NextEnumValue(), random.NextEnumValue()), + new ExportableFailureMechanismAssemblyResultWithProbability(random.NextEnumValue(), random.NextEnumValue(), + random.NextDouble()), + new ExportableFailureMechanismAssemblyResult(random.NextEnumValue(), random.NextEnumValue()), + new ExportableFailureMechanism[0], new ExportableFailureMechanism[0], + new ExportableCombinedSectionAssembly[0]); + } + } +} \ No newline at end of file Index: Riskeer/Integration/test/Riskeer.Integration.IO.Test/Riskeer.Integration.IO.Test.csproj =================================================================== diff -u -rcb13014444b07ba845474f6894336d71263413d1 -r56f43c026e0a30b3000d96fb496924f7d25efda8 --- Riskeer/Integration/test/Riskeer.Integration.IO.Test/Riskeer.Integration.IO.Test.csproj (.../Riskeer.Integration.IO.Test.csproj) (revision cb13014444b07ba845474f6894336d71263413d1) +++ Riskeer/Integration/test/Riskeer.Integration.IO.Test/Riskeer.Integration.IO.Test.csproj (.../Riskeer.Integration.IO.Test.csproj) (revision 56f43c026e0a30b3000d96fb496924f7d25efda8) @@ -1,4 +1,4 @@ - + {06C448C6-CBDE-4579-B5B6-1B8074E022ED} @@ -92,6 +92,7 @@ +