Index: Riskeer/Storage/src/Riskeer.Storage.Core/Properties/Resources.Designer.cs
===================================================================
diff -u -re35fa47ac631890035c1e409fbc0c63f03fd90ae -r42df00994b8c2385f236f528a619c0303a1df54f
--- Riskeer/Storage/src/Riskeer.Storage.Core/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision e35fa47ac631890035c1e409fbc0c63f03fd90ae)
+++ Riskeer/Storage/src/Riskeer.Storage.Core/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 42df00994b8c2385f236f528a619c0303a1df54f)
@@ -1,4 +1,4 @@
-// Copyright (C) Stichting Deltares 2021. All rights reserved.
+// Copyright (C) Stichting Deltares 2021. All rights reserved.
//
// This file is part of Riskeer.
//
@@ -83,8 +83,8 @@
///
/// Looks up a localized string similar to /* ---------------------------------------------------- */
- ////* Generated by Enterprise Architect Version 12.0 */
- ////* Created On : 15-jan-2019 14:14:43 */
+ ////* Generated by Enterprise Architect Version 14.1 */
+ ////* Created On : 12-nov-2021 10:26:25 */
////* DBMS : SQLite */
////* ---------------------------------------------------- */
///
@@ -93,16 +93,16 @@
///DROP TABLE IF EXISTS 'VersionEntity'
///;
///
- ///DROP TABLE IF EXISTS 'GrassCoverErosionInwardsDikeHeightOutputEntity'
+ ///DROP TABLE IF EXISTS 'ProjectEntity'
///;
///
- ///DROP TABLE IF EXISTS 'ProjectEntity'
+ ///DROP TABLE IF EXISTS 'AssessmentSectionEntity'
///;
///
- ///DROP TABLE IF EXISTS 'MacroStabilityInwardsFailureMechanismMetaEntity'
+ ///DROP TABLE IF EXISTS 'FailureMechanismEntity'
///;
///
- ///DROP TABLE [rest of string was truncated]";.
+ ///DROP TABLE IF EXISTS 'FailureMechanismS [rest of string was truncated]";.
///
public static string DatabaseStructure {
get {
@@ -147,6 +147,25 @@
}
///
+ /// Looks up a localized string similar to Het project bevat meer dan 1 traject..
+ ///
+ public static string ProjectEntityReadExtensions_Read_ProjectEntity_contains_more_than_one_AssessmentSection {
+ get {
+ return ResourceManager.GetString("ProjectEntityReadExtensions_Read_ProjectEntity_contains_more_than_one_AssessmentS" +
+ "ection", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Het project bevat geen traject..
+ ///
+ public static string ProjectEntityReadExtensions_Read_ProjectEntity_contains_no_AssessmentSection {
+ get {
+ return ResourceManager.GetString("ProjectEntityReadExtensions_Read_ProjectEntity_contains_no_AssessmentSection", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to Riskeerproject (*.risk)|*.risk.
///
public static string RiskeerProject_FileFilter {
Index: Riskeer/Storage/src/Riskeer.Storage.Core/Properties/Resources.resx
===================================================================
diff -u -re35fa47ac631890035c1e409fbc0c63f03fd90ae -r42df00994b8c2385f236f528a619c0303a1df54f
--- Riskeer/Storage/src/Riskeer.Storage.Core/Properties/Resources.resx (.../Resources.resx) (revision e35fa47ac631890035c1e409fbc0c63f03fd90ae)
+++ Riskeer/Storage/src/Riskeer.Storage.Core/Properties/Resources.resx (.../Resources.resx) (revision 42df00994b8c2385f236f528a619c0303a1df54f)
@@ -163,4 +163,10 @@
Riskeerproject (*.risk)|*.risk
+
+ Het project bevat meer dan 1 traject.
+
+
+ Het project bevat geen traject.
+
\ No newline at end of file
Index: Riskeer/Storage/src/Riskeer.Storage.Core/Read/ProjectEntityReadExtensions.cs
===================================================================
diff -u -r4f362dabd411ea7a47f0c603d36de0b9bf293ff8 -r42df00994b8c2385f236f528a619c0303a1df54f
--- Riskeer/Storage/src/Riskeer.Storage.Core/Read/ProjectEntityReadExtensions.cs (.../ProjectEntityReadExtensions.cs) (revision 4f362dabd411ea7a47f0c603d36de0b9bf293ff8)
+++ Riskeer/Storage/src/Riskeer.Storage.Core/Read/ProjectEntityReadExtensions.cs (.../ProjectEntityReadExtensions.cs) (revision 42df00994b8c2385f236f528a619c0303a1df54f)
@@ -23,6 +23,8 @@
using System.Linq;
using Riskeer.Integration.Data;
using Riskeer.Storage.Core.DbContext;
+using Riskeer.Storage.Core.Exceptions;
+using Riskeer.Storage.Core.Properties;
namespace Riskeer.Storage.Core.Read
{
@@ -39,13 +41,25 @@
/// The object keeping track of read operations.
/// A new .
/// Thrown when is null.
+ /// Thrown when could not be read successfully.
internal static RiskeerProject Read(this ProjectEntity entity, ReadConversionCollector collector)
{
if (collector == null)
{
throw new ArgumentNullException(nameof(collector));
}
+ int nrOfAssessmentSectionEntities = entity.AssessmentSectionEntities.Count;
+ if (nrOfAssessmentSectionEntities > 1)
+ {
+ throw new EntityReadException(Resources.ProjectEntityReadExtensions_Read_ProjectEntity_contains_more_than_one_AssessmentSection);
+ }
+
+ if (nrOfAssessmentSectionEntities == 0)
+ {
+ throw new EntityReadException(Resources.ProjectEntityReadExtensions_Read_ProjectEntity_contains_no_AssessmentSection);
+ }
+
AssessmentSection assessmentSection = ReadAssessmentSection(entity, collector);
var project = new RiskeerProject(assessmentSection)
{
@@ -57,10 +71,9 @@
private static AssessmentSection ReadAssessmentSection(ProjectEntity entity, ReadConversionCollector collector)
{
- AssessmentSectionEntity assessmentSectionEntity = entity.AssessmentSectionEntities
- .OrderBy(ase => ase.Order)
- .FirstOrDefault();
- return assessmentSectionEntity?.Read(collector);
+ return entity.AssessmentSectionEntities
+ .Single()
+ .Read(collector);
}
}
}
\ No newline at end of file
Index: Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/ProjectEntityReadExtensionsTest.cs
===================================================================
diff -u -r4a5af5ce261876bdbf2739c251810e2de0e65986 -r42df00994b8c2385f236f528a619c0303a1df54f
--- Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/ProjectEntityReadExtensionsTest.cs (.../ProjectEntityReadExtensionsTest.cs) (revision 4a5af5ce261876bdbf2739c251810e2de0e65986)
+++ Riskeer/Storage/test/Riskeer.Storage.Core.Test/Read/ProjectEntityReadExtensionsTest.cs (.../ProjectEntityReadExtensionsTest.cs) (revision 42df00994b8c2385f236f528a619c0303a1df54f)
@@ -26,6 +26,7 @@
using Riskeer.Common.Data.Contribution;
using Riskeer.Integration.Data;
using Riskeer.Storage.Core.DbContext;
+using Riskeer.Storage.Core.Exceptions;
using Riskeer.Storage.Core.Read;
namespace Riskeer.Storage.Core.Test.Read
@@ -48,102 +49,97 @@
}
[Test]
- public void Read_WithCollector_ReturnsNewProjectWithPropertiesSet()
+ public void Read_EntityWithMultipleAssessmentSections_ThrowsEntityReadException()
{
// Setup
- const string testDescription = "testName";
-
- var random = new Random(21);
var entity = new ProjectEntity
{
- Description = testDescription,
AssessmentSectionEntities =
{
- new AssessmentSectionEntity
- {
- SignalingNorm = random.NextDouble(0.000001, 0.1),
- LowerLimitNorm = random.NextDouble(0.000001, 0.1),
- NormativeNormType = Convert.ToByte(NormType.Signaling),
- Name = "A",
- Composition = Convert.ToByte(AssessmentSectionComposition.Dike),
- BackgroundDataEntities = new[]
- {
- new BackgroundDataEntity
- {
- Name = "Background A",
- Transparency = 0.0,
- IsVisible = 1,
- BackgroundDataType = 1,
- BackgroundDataMetaEntities = new[]
- {
- new BackgroundDataMetaEntity
- {
- Key = BackgroundDataIdentifiers.IsConfigured,
- Value = "0"
- }
- }
- }
- }
- }
+ CreateAssessmentSectionEntity(1),
+ CreateAssessmentSectionEntity(2)
}
};
+ var collector = new ReadConversionCollector();
+
// Call
- RiskeerProject project = entity.Read(new ReadConversionCollector());
+ void Call() => entity.Read(collector);
// Assert
- Assert.IsNotNull(project);
- Assert.AreEqual(testDescription, project.Description);
- Assert.IsNotNull(project.AssessmentSection);
+ var exception = Assert.Throws(Call);
+ const string message = "Het project bevat meer dan 1 traject.";
+ Assert.AreEqual(message, exception.Message);
}
[Test]
- public void Read_WithAssessmentSection_ReturnsNewProjectWithAssessmentSections()
+ public void Read_EntityWithNoAssessmentSections_ThrowsEntityReadException()
{
// Setup
- const double lowerLimitNorm = 0.0001;
- const double signalingNorm = 0.00001;
+ var entity = new ProjectEntity();
+ var collector = new ReadConversionCollector();
+
+ // Call
+ void Call() => entity.Read(collector);
+ // Assert
+ var exception = Assert.Throws(Call);
+ const string message = "Het project bevat geen traject.";
+ Assert.AreEqual(message, exception.Message);
+ }
+
+ [Test]
+ public void Read_WithAssessmentSection_ReturnsNewProjectWithAssessmentSection()
+ {
+ // Setup
+ AssessmentSectionEntity assessmentSectionEntity = CreateAssessmentSectionEntity(1);
var entity = new ProjectEntity
{
Description = "testName",
AssessmentSectionEntities =
{
- new AssessmentSectionEntity
+ assessmentSectionEntity
+ }
+ };
+
+ // Call
+ RiskeerProject project = entity.Read(new ReadConversionCollector());
+
+ // Assert
+ Assert.AreEqual(entity.Description, project.Description);
+ Assert.AreEqual(assessmentSectionEntity.Name, project.AssessmentSection.Name);
+ }
+
+ private static AssessmentSectionEntity CreateAssessmentSectionEntity(int seed)
+ {
+ var random = new Random(seed);
+
+ return new AssessmentSectionEntity
+ {
+ SignalingNorm = 0.00001,
+ LowerLimitNorm = 0.0001,
+ NormativeNormType = Convert.ToByte(random.NextEnumValue()),
+ Name = "Just a name",
+ Composition = Convert.ToByte(random.NextEnumValue()),
+ BackgroundDataEntities = new[]
+ {
+ new BackgroundDataEntity
{
- SignalingNorm = signalingNorm,
- LowerLimitNorm = lowerLimitNorm,
- NormativeNormType = Convert.ToByte(NormType.Signaling),
- Name = "A",
- Order = 56,
- Composition = Convert.ToByte(AssessmentSectionComposition.Dike),
- BackgroundDataEntities = new[]
+ Name = "Background A",
+ Transparency = 0.0,
+ IsVisible = 1,
+ BackgroundDataType = 1,
+ BackgroundDataMetaEntities = new[]
{
- new BackgroundDataEntity
+ new BackgroundDataMetaEntity
{
- Name = "Background A",
- Transparency = 0.0,
- IsVisible = 1,
- BackgroundDataType = 1,
- BackgroundDataMetaEntities = new[]
- {
- new BackgroundDataMetaEntity
- {
- Key = BackgroundDataIdentifiers.IsConfigured,
- Value = "0"
- }
- }
+ Key = BackgroundDataIdentifiers.IsConfigured,
+ Value = "0"
}
}
}
}
};
-
- // Call
- RiskeerProject project = entity.Read(new ReadConversionCollector());
-
- // Assert
- Assert.AreEqual("A", project.AssessmentSection.Name);
}
}
}
\ No newline at end of file