public void Constructor_ExpectedValues()
        {
            // Setup
            const string waternetLineName = "<some name>";
            const string phreaticLineName = "PL1";
            var          geometry         = new List <Point2D>
            {
                new Point2D(0.0, 0.0),
                new Point2D(15.0, 15.0)
            };

            // Call
            var waternetLine = new MacroStabilityInwardsWaternetLine(waternetLineName,
                                                                     geometry,
                                                                     new MacroStabilityInwardsPhreaticLine(phreaticLineName, Enumerable.Empty <Point2D>()));

            // Assert
            Assert.AreEqual(waternetLineName, waternetLine.Name);
            CollectionAssert.AreEqual(new List <Point2D>
            {
                new Point2D(0.0, 0.0),
                new Point2D(15.0, 15.0)
            }, waternetLine.Geometry);
            Assert.AreEqual(phreaticLineName, waternetLine.PhreaticLine.Name);
            CollectionAssert.IsEmpty(waternetLine.PhreaticLine.Geometry);
        }
        /// <summary>
        /// Asserts whether <paramref name="actual"/> corresponds to <paramref name="original"/>.
        /// </summary>
        /// <param name="original">The original <see cref="MacroStabilityInwardsWaternet"/>.</param>
        /// <param name="expectedVisibility">The expected visibility of the chart data.</param>
        /// <param name="actual">The actual <see cref="ChartDataCollection"/>.</param>
        /// <exception cref="AssertionException">Thrown when <paramref name="actual"/>
        /// does not correspond to <paramref name="original"/>.</exception>
        public static void AssertWaternetChartData(MacroStabilityInwardsWaternet original, bool expectedVisibility, ChartDataCollection actual)
        {
            ChartData[] waternetChartData = actual.Collection.ToArray();
            MacroStabilityInwardsWaternetLine[] waternetLines = original.WaternetLines.ToArray();
            MacroStabilityInwardsPhreaticLine[] phreaticLines = original.PhreaticLines.ToArray();

            CollectionAssert.IsNotEmpty(waternetLines);
            CollectionAssert.IsNotEmpty(phreaticLines);

            Assert.AreEqual(waternetLines.Length + phreaticLines.Length, waternetChartData.Length);

            for (var i = 0; i < waternetChartData.Length; i++)
            {
                if (i < phreaticLines.Length)
                {
                    var phreaticLineChartData = (ChartLineData)waternetChartData[i];
                    Assert.AreEqual(phreaticLines[i].Name, phreaticLineChartData.Name);
                    Assert.AreEqual(phreaticLines[i].Geometry, phreaticLineChartData.Points);
                    Assert.AreEqual(expectedVisibility, phreaticLineChartData.IsVisible);
                }
                else
                {
                    var waternetLineChartData = (ChartMultipleAreaData)waternetChartData[i];
                    MacroStabilityInwardsWaternetLine waternetLine = waternetLines[i - waternetLines.Length];
                    Assert.AreEqual(waternetLine.Name, waternetLineChartData.Name);
                    Assert.IsTrue(waternetLineChartData.HasData);
                    Assert.AreEqual(expectedVisibility, waternetLineChartData.IsVisible);
                }
            }
        }
Esempio n. 3
0
        public void Constructor_ValidWaternetLine_ExpectedValues()
        {
            // Setup
            MacroStabilityInwardsWaternetLine waternetLine = MacroStabilityInwardsTestDataFactory.CreateMacroStabilityInwardsWaternetLine();

            // Call
            var properties = new MacroStabilityInwardsWaternetLineProperties(waternetLine);

            // Assert
            Assert.IsInstanceOf <ObjectProperties <MacroStabilityInwardsWaternetLine> >(properties);
            TestHelper.AssertTypeConverter <MacroStabilityInwardsWaternetLineProperties, ExpandableReadOnlyArrayConverter>(
                nameof(MacroStabilityInwardsWaternetLineProperties.Geometry));
            Assert.AreSame(waternetLine, properties.Data);
        }
Esempio n. 4
0
        public void Create_WithValidData_ReturnsPersistableWaternetCollection()
        {
            // Setup
            var phreaticLine1 = new MacroStabilityInwardsPhreaticLine("Phreatic Line", Enumerable.Empty <Point2D>());
            var waternetLine1 = new MacroStabilityInwardsWaternetLine("Waternet Line", Enumerable.Empty <Point2D>(), phreaticLine1);
            var phreaticLine2 = new MacroStabilityInwardsPhreaticLine("Phreatic Line", Enumerable.Empty <Point2D>());
            var waternetLine2 = new MacroStabilityInwardsWaternetLine("Waternet Line", Enumerable.Empty <Point2D>(), phreaticLine2);

            var dailyWaternet = new MacroStabilityInwardsWaternet(new[]
            {
                phreaticLine1
            }, new[]
            {
                waternetLine1
            });

            var extremeWaternet = new MacroStabilityInwardsWaternet(new[]
            {
                phreaticLine2
            }, new[]
            {
                waternetLine2
            });

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            // Call
            IEnumerable <PersistableWaternet> persistableWaternets = PersistableWaternetFactory.Create(dailyWaternet, extremeWaternet, new GeneralMacroStabilityInwardsInput(), idFactory, registry);

            // Assert
            PersistableDataModelTestHelper.AssertWaternets(new[]
            {
                dailyWaternet,
                extremeWaternet
            }, persistableWaternets);

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

            Assert.AreEqual(2, registry.Waternets.Count);

            for (var i = 0; i < stages.Length; i++)
            {
                Assert.AreEqual(registry.Waternets[stages[i]], persistableWaternets.ElementAt(i).Id);
            }
        }
Esempio n. 5
0
        private static PersistableReferenceLine Create(MacroStabilityInwardsWaternetLine waternetLine, IdFactory idFactory)
        {
            string headLineId = createdHeadLines[waternetLine.PhreaticLine].Id;

            var referenceLine = new PersistableReferenceLine
            {
                Id               = idFactory.Create(),
                Label            = waternetLine.Name,
                Points           = waternetLine.Geometry.Select(point => new PersistablePoint(point.X, point.Y)).ToArray(),
                TopHeadLineId    = headLineId,
                BottomHeadLineId = headLineId
            };

            return(referenceLine);
        }
Esempio n. 6
0
        public void ToString_Always_ReturnsName()
        {
            // Setup
            const string expectedName = "PL2";
            var          waternetLine = new MacroStabilityInwardsWaternetLine(expectedName,
                                                                              Enumerable.Empty <Point2D>(),
                                                                              MacroStabilityInwardsTestDataFactory.CreateMacroStabilityInwardsPhreaticLine());
            var properties = new MacroStabilityInwardsWaternetLineProperties(waternetLine);

            // Call
            var name = properties.ToString();

            // Assert
            Assert.AreEqual(name, expectedName);
        }
Esempio n. 7
0
        /// <summary>
        /// Create points of the Waternet zone in 2D space based on the provide <paramref name="waternetLine"/>.
        /// </summary>
        /// <param name="waternetLine">The Waternet line to create the zone for.</param>
        /// <param name="surfaceLine">The <see cref="MacroStabilityInwardsSurfaceLine"/> that may intersect with
        /// the <see cref="MacroStabilityInwardsWaternetLine.PhreaticLine"/> and by doing that restricts the
        /// drawn height of it.</param>
        /// <returns>A collection of points in 2D space or an empty collection when:
        /// <list type="bullet">
        /// <item><paramref name="waternetLine"/> is <c>null</c>;</item>
        /// <item><paramref name="surfaceLine"/> is <c>null</c>;</item>
        /// <item>The geometry of the <see cref="MacroStabilityInwardsWaternetLine"/> is <c>empty</c>;</item>
        /// <item>The geometry of the <see cref="MacroStabilityInwardsWaternetLine.PhreaticLine"/> is <c>empty</c>.</item>
        /// </list>
        /// </returns>
        public static IEnumerable <IEnumerable <Point2D> > CreateWaternetZonePoints(MacroStabilityInwardsWaternetLine waternetLine,
                                                                                    MacroStabilityInwardsSurfaceLine surfaceLine)
        {
            if (waternetLine == null || surfaceLine == null ||
                !waternetLine.Geometry.Any() || !waternetLine.PhreaticLine.Geometry.Any())
            {
                return(new Point2D[0][]);
            }

            IEnumerable <Point2D> surfaceLineLocalGeometry = surfaceLine.LocalGeometry.ToArray();
            IEnumerable <Point2D> phreaticLineGeometry     = new RoundedPoint2DCollection(2, waternetLine.PhreaticLine.Geometry).ToArray();
            IEnumerable <Point2D> waternetLineGeometry     = new RoundedPoint2DCollection(2, waternetLine.Geometry).ToArray();

            return(IsSurfaceLineAboveWaternetZone(surfaceLineLocalGeometry, waternetLineGeometry, phreaticLineGeometry)
                       ? CreateZoneAreas(waternetLineGeometry, phreaticLineGeometry)
                       : GetWaternetZoneWithSurfaceLineIntersection(surfaceLineLocalGeometry, waternetLineGeometry, phreaticLineGeometry).ToArray());
        }
        /// <summary>
        /// Asserts whether the <see cref="MacroStabilityInwardsWaternet"/> contains the data
        /// that is representative for the <paramref name="originalWaternets"/>.
        /// </summary>
        /// <param name="originalWaternets">The Waternets that contain the original data.</param>
        /// <param name="actualWaternets">The <see cref="PersistableWaternet"/>
        /// that needs to be asserted.</param>
        /// <exception cref="AssertionException">Thrown when the data in <paramref name="actualWaternets"/>
        /// is not correct.</exception>
        public static void AssertWaternets(IEnumerable <MacroStabilityInwardsWaternet> originalWaternets, IEnumerable <PersistableWaternet> actualWaternets)
        {
            Assert.AreEqual(originalWaternets.Count(), actualWaternets.Count());

            for (var i = 0; i < originalWaternets.Count(); i++)
            {
                MacroStabilityInwardsWaternet originalWaternet = originalWaternets.ElementAt(i);
                PersistableWaternet           actualWaternet   = actualWaternets.ElementAt(i);

                Assert.IsNotNull(actualWaternet.Id);
                Assert.AreEqual(9.81, actualWaternet.UnitWeightWater);

                PersistableHeadLine firstHeadLine = actualWaternet.HeadLines.FirstOrDefault();
                Assert.AreEqual(actualWaternet.PhreaticLineId, firstHeadLine?.Id);

                Assert.AreEqual(originalWaternet.PhreaticLines.Count(), actualWaternet.HeadLines.Count());

                for (var j = 0; j < originalWaternet.PhreaticLines.Count(); j++)
                {
                    MacroStabilityInwardsPhreaticLine phreaticLine = originalWaternet.PhreaticLines.ElementAt(j);
                    PersistableHeadLine headLine = actualWaternet.HeadLines.ElementAt(j);

                    Assert.IsNotNull(headLine.Id);
                    Assert.AreEqual(phreaticLine.Name, headLine.Label);
                    CollectionAssert.AreEqual(phreaticLine.Geometry.Select(p => new PersistablePoint(p.X, p.Y)), headLine.Points);
                }

                Assert.AreEqual(originalWaternet.WaternetLines.Count(), actualWaternet.ReferenceLines.Count());

                for (var j = 0; j < originalWaternet.WaternetLines.Count(); j++)
                {
                    MacroStabilityInwardsWaternetLine waternetLine  = originalWaternet.WaternetLines.ElementAt(j);
                    PersistableReferenceLine          referenceLine = actualWaternet.ReferenceLines.ElementAt(j);

                    Assert.IsNotNull(referenceLine.Id);
                    Assert.AreEqual(waternetLine.Name, referenceLine.Label);
                    CollectionAssert.AreEqual(waternetLine.Geometry.Select(p => new PersistablePoint(p.X, p.Y)), referenceLine.Points);

                    Assert.AreEqual(firstHeadLine.Id, referenceLine.TopHeadLineId);
                    Assert.AreEqual(firstHeadLine.Id, referenceLine.BottomHeadLineId);
                }
            }
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var phreaticLine = new MacroStabilityInwardsPhreaticLine("Phreatic Line", Enumerable.Empty <Point2D>());
            var waternetLine = new MacroStabilityInwardsWaternetLine("Waternet Line", Enumerable.Empty <Point2D>(), phreaticLine);

            // Call
            var waternet = new MacroStabilityInwardsWaternet(new[]
            {
                phreaticLine
            }, new[]
            {
                waternetLine
            });

            // Assert
            Assert.AreSame(phreaticLine, waternet.PhreaticLines.Single());
            Assert.AreSame(waternetLine, waternet.WaternetLines.Single());
        }
Esempio n. 10
0
        public void GetProperties_WithData_ReturnExpectedValues()
        {
            // Setup
            var random       = new Random(21);
            var waternetLine = new MacroStabilityInwardsWaternetLine("Zone A",
                                                                     new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble()),
                new Point2D(random.NextDouble(), random.NextDouble())
            },
                                                                     new MacroStabilityInwardsPhreaticLine("PL1", Enumerable.Empty <Point2D>()));

            // Call
            var properties = new MacroStabilityInwardsWaternetLineProperties(waternetLine);

            // Assert
            Assert.AreEqual(waternetLine.Name, properties.Name);
            CollectionAssert.AreEqual(waternetLine.Geometry, properties.Geometry);
            Assert.AreEqual(waternetLine.PhreaticLine.Name, properties.PhreaticLineName);
        }
Esempio n. 11
0
        public void Constructor_ValidData_PropertiesHaveExpectedAttributeValues()
        {
            // Setup
            MacroStabilityInwardsWaternetLine waternetLine = MacroStabilityInwardsTestDataFactory.CreateMacroStabilityInwardsWaternetLine();

            // Call
            var properties = new MacroStabilityInwardsWaternetLineProperties(waternetLine);

            // Assert
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);

            Assert.AreEqual(3, dynamicProperties.Count);

            const string waterStressesCategoryName = "Waterspanningen";

            PropertyDescriptor nameProperty = dynamicProperties[0];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty,
                                                                            waterStressesCategoryName,
                                                                            "Naam",
                                                                            "De naam van de zone.",
                                                                            true);

            PropertyDescriptor geometryProperty = dynamicProperties[1];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(geometryProperty,
                                                                            waterStressesCategoryName,
                                                                            "Geometrie",
                                                                            "De geometrie van de zone.",
                                                                            true);

            PropertyDescriptor phreaticLineNameProperty = dynamicProperties[2];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(phreaticLineNameProperty,
                                                                            waterStressesCategoryName,
                                                                            "Stijghoogtelijn",
                                                                            "De stijghoogtelijn behorend bij de zone.",
                                                                            true);
        }