Index: Core/Common/src/Core.Common.Base/Data/IProjectFactory.cs
===================================================================
diff -u -rc4125b3012678bd098090e0a1dbb5b099fbe2d3d -r7f397d62e5fd14b5202c620c2aed09b79f8f94c8
--- Core/Common/src/Core.Common.Base/Data/IProjectFactory.cs (.../IProjectFactory.cs) (revision c4125b3012678bd098090e0a1dbb5b099fbe2d3d)
+++ Core/Common/src/Core.Common.Base/Data/IProjectFactory.cs (.../IProjectFactory.cs) (revision 7f397d62e5fd14b5202c620c2aed09b79f8f94c8)
@@ -32,8 +32,10 @@
/// Creates a new instance of .
///
/// The func to perform
- /// after the project is created.
+ /// when the project is created.
/// An empty object.
+ /// Thrown when something
+ /// went wrong while creating an object.
IProject CreateNewProject(Func onCreateNewProjectFunc);
}
}
\ No newline at end of file
Index: Core/Common/src/Core.Common.Base/Data/ProjectFactoryException.cs
===================================================================
diff -u
--- Core/Common/src/Core.Common.Base/Data/ProjectFactoryException.cs (revision 0)
+++ Core/Common/src/Core.Common.Base/Data/ProjectFactoryException.cs (revision 7f397d62e5fd14b5202c620c2aed09b79f8f94c8)
@@ -0,0 +1,47 @@
+using System;
+using System.Runtime.Serialization;
+
+namespace Core.Common.Base.Data
+{
+ ///
+ /// Exception thrown when something went wrong while creating an .
+ ///
+ [Serializable]
+ public class ProjectFactoryException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public ProjectFactoryException() {}
+
+ ///
+ /// Initializes a new instance of the class
+ /// with a specified error message.
+ ///
+ /// The message that describes the error.
+ public ProjectFactoryException(string message)
+ : base(message) {}
+
+ ///
+ /// Initializes a new instance of the class with a specified error message
+ /// and a reference to the inner exception that is the cause of this exception.
+ ///
+ /// The error message that explains the reason for the exception.
+ /// The exception that is the cause of the current exception,
+ /// or null if no inner exception is specified.
+ public ProjectFactoryException(string message, Exception innerException) : base(message, innerException) {}
+
+ ///
+ /// Initializes a new instance of with
+ /// serialized data.
+ /// The that holds the serialized
+ /// object data about the exception being thrown.
+ /// The that contains contextual
+ /// information about the source or destination.
+ /// The parameter is
+ /// null .
+ /// The class name is null or
+ /// is zero (0).
+ protected ProjectFactoryException(SerializationInfo info, StreamingContext context) : base(info, context) {}
+ }
+}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj
===================================================================
diff -u -r08e8d26a0715f0f3db57c1d3e86256aa06934db4 -r7f397d62e5fd14b5202c620c2aed09b79f8f94c8
--- Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision 08e8d26a0715f0f3db57c1d3e86256aa06934db4)
+++ Core/Common/test/Core.Common.Base.Test/Core.Common.Base.Test.csproj (.../Core.Common.Base.Test.csproj) (revision 7f397d62e5fd14b5202c620c2aed09b79f8f94c8)
@@ -5,10 +5,10 @@
-
-
-
-
+
+
+
+
Index: Core/Common/test/Core.Common.Base.Test/Data/ProjectFactoryExceptionTest.cs
===================================================================
diff -u
--- Core/Common/test/Core.Common.Base.Test/Data/ProjectFactoryExceptionTest.cs (revision 0)
+++ Core/Common/test/Core.Common.Base.Test/Data/ProjectFactoryExceptionTest.cs (revision 7f397d62e5fd14b5202c620c2aed09b79f8f94c8)
@@ -0,0 +1,11 @@
+using System;
+using Core.Common.Base.Data;
+using Core.Common.TestUtil;
+using NUnit.Framework;
+
+namespace Core.Common.Base.Test.Data
+{
+ [TestFixture]
+ public class ProjectFactoryExceptionTest :
+ CustomExceptionDesignGuidelinesTestFixture {}
+}
\ No newline at end of file
Index: Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerProjectFactory.cs
===================================================================
diff -u -rc4125b3012678bd098090e0a1dbb5b099fbe2d3d -r7f397d62e5fd14b5202c620c2aed09b79f8f94c8
--- Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerProjectFactory.cs (.../RiskeerProjectFactory.cs) (revision c4125b3012678bd098090e0a1dbb5b099fbe2d3d)
+++ Riskeer/Integration/src/Riskeer.Integration.Plugin/RiskeerProjectFactory.cs (.../RiskeerProjectFactory.cs) (revision 7f397d62e5fd14b5202c620c2aed09b79f8f94c8)
@@ -21,6 +21,8 @@
using System;
using Core.Common.Base.Data;
+using Core.Common.Base.IO;
+using Riskeer.Common.IO.Exceptions;
using Riskeer.Integration.Data;
namespace Riskeer.Integration.Plugin
@@ -42,20 +44,27 @@
throw new ArgumentNullException(nameof(onCreateNewProjectFunc));
}
- var assessmentSection = (AssessmentSection) onCreateNewProjectFunc();
-
- if (assessmentSection == null)
+ try
{
- return null;
- }
-
- return new RiskeerProject
- {
- AssessmentSections =
+ var assessmentSection = (AssessmentSection) onCreateNewProjectFunc();
+
+ if (assessmentSection == null)
{
- assessmentSection
+ return null;
}
- };
+
+ return new RiskeerProject
+ {
+ AssessmentSections =
+ {
+ assessmentSection
+ }
+ };
+ }
+ catch (Exception e) when (e is CriticalFileReadException || e is CriticalFileValidationException)
+ {
+ throw new ProjectFactoryException(e.Message, e);
+ }
}
}
}
\ No newline at end of file
Index: Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerProjectFactoryTest.cs
===================================================================
diff -u -rc4125b3012678bd098090e0a1dbb5b099fbe2d3d -r7f397d62e5fd14b5202c620c2aed09b79f8f94c8
--- Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerProjectFactoryTest.cs (.../RiskeerProjectFactoryTest.cs) (revision c4125b3012678bd098090e0a1dbb5b099fbe2d3d)
+++ Riskeer/Integration/test/Riskeer.Integration.Plugin.Test/RiskeerProjectFactoryTest.cs (.../RiskeerProjectFactoryTest.cs) (revision 7f397d62e5fd14b5202c620c2aed09b79f8f94c8)
@@ -77,7 +77,7 @@
}
[Test]
- public void CreateNewProject_WithOnCreateNewProjectFuncThrowsException_ThrowsException()
+ public void CreateNewProject_WithOnCreateNewProjectFuncThrowsException_ThrowsProjectFactoryException()
{
// Setup
var projectFactory = new RiskeerProjectFactory();
@@ -87,8 +87,9 @@
void Call() => projectFactory.CreateNewProject(() => throw new Exception(expectedMessage));
// Assert
- var exception = Assert.Throws(Call);
+ var exception = Assert.Throws(Call);
Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.IsInstanceOf(exception.InnerException);
}
}
}
\ No newline at end of file