private static PersistableCalculationSettings Create(IdFactory idFactory, MacroStabilityInwardsExportRegistry registry,
                                                             MacroStabilityInwardsExportStageType stageType)
        {
            var settings = new PersistableCalculationSettings
            {
                Id = idFactory.Create()
            };

            registry.AddSettings(stageType, settings.Id);
            return(settings);
        }
        /// <summary>
        /// Creates a collection of <see cref="PersistableCalculationSettings"/>.
        /// </summary>
        /// <param name="slidingCurve">The sliding curve to use.</param>
        /// <param name="idFactory">The factory for creating IDs.</param>
        /// <param name="registry">The persistence registry.</param>
        /// <returns>A collection of <see cref="PersistableCalculationSettings"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static IEnumerable <PersistableCalculationSettings> Create(MacroStabilityInwardsSlidingCurve slidingCurve, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry)
        {
            if (slidingCurve == null)
            {
                throw new ArgumentNullException(nameof(slidingCurve));
            }

            if (idFactory == null)
            {
                throw new ArgumentNullException(nameof(idFactory));
            }

            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            PersistableCalculationSettings dailySettings   = Create(idFactory, registry, MacroStabilityInwardsExportStageType.Daily);
            PersistableCalculationSettings extremeSettings = Create(idFactory, registry, MacroStabilityInwardsExportStageType.Extreme);

            dailySettings.AnalysisType   = PersistableAnalysisType.UpliftVan;
            extremeSettings.AnalysisType = PersistableAnalysisType.UpliftVan;
            extremeSettings.UpliftVan    = new PersistableUpliftVanSettings
            {
                SlipPlane = new PersistableTwoCirclesOnTangentLine
                {
                    FirstCircleCenter = new PersistablePoint(slidingCurve.LeftCircle.Center.X,
                                                             slidingCurve.LeftCircle.Center.Y),
                    FirstCircleRadius  = slidingCurve.LeftCircle.Radius,
                    SecondCircleCenter = new PersistablePoint(slidingCurve.RightCircle.Center.X,
                                                              slidingCurve.RightCircle.Center.Y)
                }
            };
            extremeSettings.CalculationType = PersistableCalculationType.Deterministic;

            return(new[]
            {
                dailySettings,
                extremeSettings
            });
        }
        /// <summary>
        /// Asserts whether the <see cref="PersistableCalculationSettings"/> contains the data
        /// that is representative for the <paramref name="slidingCurve"/>.
        /// </summary>
        /// <param name="slidingCurve">The sliding curve that contains the original data.</param>
        /// <param name="calculationSettings">The collection of <see cref="PersistableCalculationSettings"/>
        /// that needs to be asserted.</param>
        /// <exception cref="AssertionException">Thrown when the data in <paramref name="calculationSettings"/>
        /// is not correct.</exception>
        public static void AssertCalculationSettings(MacroStabilityInwardsSlidingCurve slidingCurve, IEnumerable <PersistableCalculationSettings> calculationSettings)
        {
            Assert.AreEqual(2, calculationSettings.Count());
            PersistableCalculationSettings dailyCalculationSettings = calculationSettings.First();

            Assert.IsNotNull(dailyCalculationSettings.Id);
            Assert.AreEqual(PersistableAnalysisType.UpliftVan, dailyCalculationSettings.AnalysisType);
            Assert.IsNull(dailyCalculationSettings.CalculationType);
            Assert.IsNull(dailyCalculationSettings.UpliftVan);

            PersistableCalculationSettings extremeCalculationSettings = calculationSettings.Last();

            Assert.IsNotNull(extremeCalculationSettings.Id);
            Assert.AreEqual(PersistableAnalysisType.UpliftVan, extremeCalculationSettings.AnalysisType);
            Assert.AreEqual(PersistableCalculationType.Deterministic, extremeCalculationSettings.CalculationType);
            Assert.AreEqual(slidingCurve.LeftCircle.Center.X, extremeCalculationSettings.UpliftVan.SlipPlane.FirstCircleCenter.Value.X);
            Assert.AreEqual(slidingCurve.LeftCircle.Center.Y, extremeCalculationSettings.UpliftVan.SlipPlane.FirstCircleCenter.Value.Z);
            Assert.AreEqual(slidingCurve.LeftCircle.Radius, extremeCalculationSettings.UpliftVan.SlipPlane.FirstCircleRadius);
            Assert.AreEqual(slidingCurve.RightCircle.Center.X, extremeCalculationSettings.UpliftVan.SlipPlane.SecondCircleCenter.Value.X);
            Assert.AreEqual(slidingCurve.RightCircle.Center.Y, extremeCalculationSettings.UpliftVan.SlipPlane.SecondCircleCenter.Value.Z);
        }
        public void Create_WithValidData_ReturnsStages()
        {
            // Setup
            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            var stageTypes = new[]
            {
                MacroStabilityInwardsExportStageType.Daily,
                MacroStabilityInwardsExportStageType.Extreme
            };

            var settingsList   = new List <PersistableCalculationSettings>();
            var geometryList   = new List <PersistableGeometry>();
            var soilLayersList = new List <PersistableSoilLayerCollection>();
            var waternetList   = new List <PersistableWaternet>();
            var waternetCreatorSettingsList = new List <PersistableWaternetCreatorSettings>();
            var stateList = new List <PersistableState>();

            foreach (MacroStabilityInwardsExportStageType stageType in stageTypes)
            {
                var settings = new PersistableCalculationSettings
                {
                    Id = idFactory.Create()
                };
                settingsList.Add(settings);

                var geometry = new PersistableGeometry
                {
                    Id = idFactory.Create()
                };
                geometryList.Add(geometry);

                var persistableSoilLayerCollection = new PersistableSoilLayerCollection
                {
                    Id = idFactory.Create()
                };
                soilLayersList.Add(persistableSoilLayerCollection);

                var waternet = new PersistableWaternet
                {
                    Id = idFactory.Create()
                };
                waternetList.Add(waternet);

                var waternetCreatorSettings = new PersistableWaternetCreatorSettings
                {
                    Id = idFactory.Create()
                };
                waternetCreatorSettingsList.Add(waternetCreatorSettings);

                var state = new PersistableState
                {
                    Id = idFactory.Create()
                };
                stateList.Add(state);

                registry.AddSettings(stageType, settings.Id);
                registry.AddGeometry(stageType, geometry.Id);
                registry.AddSoilLayer(stageType, persistableSoilLayerCollection.Id);
                registry.AddWaternet(stageType, waternet.Id);
                registry.AddWaternetCreatorSettings(stageType, waternetCreatorSettings.Id);
                registry.AddState(stageType, state.Id);
            }

            // Call
            IEnumerable <PersistableStage> stages = PersistableStageFactory.Create(idFactory, registry);

            // Assert
            PersistableDataModelTestHelper.AssertStages(stages, settingsList, geometryList, soilLayersList, waternetList, waternetCreatorSettingsList, stateList);
        }