private static void AssertSerializableAssessmentSection(string expectedId,
                                                         string expectedAssessmentSectionName,
                                                         IEnumerable <Point2D> expectedGeometry,
                                                         SerializableAssessmentSection actualAssessmentSection)
 {
     Assert.AreEqual(expectedId, actualAssessmentSection.Id);
     Assert.AreEqual(expectedAssessmentSectionName, actualAssessmentSection.Name);
     Assert.AreEqual(GeometrySerializationFormatter.Format(expectedGeometry), actualAssessmentSection.ReferenceLineGeometry.LineString.Geometry);
 }
        /// <summary>
        /// Creates a new instance of <see cref="SerializableLineString"/>.
        /// </summary>
        /// <param name="geometry">The geometry of the line.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="geometry"/>
        /// is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="geometry"/> contains no elements.</exception>
        public SerializableLineString(IEnumerable <Point2D> geometry) : this()
        {
            if (geometry == null)
            {
                throw new ArgumentNullException(nameof(geometry));
            }

            Geometry = GeometrySerializationFormatter.Format(geometry);
        }
Beispiel #3
0
        public void Format_PointNull_ThrowsArgumentNullException()
        {
            // Call
            TestDelegate call = () => GeometrySerializationFormatter.Format((Point2D)null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(call);

            Assert.AreEqual("point", exception.ParamName);
        }
Beispiel #4
0
        public void Format_GeometryEmpty_ThrowsArgumentException()
        {
            // Call
            TestDelegate call = () => GeometrySerializationFormatter.Format(Enumerable.Empty <Point2D>());

            // Assert
            const string message = "Geometry cannot be empty.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message);
        }
Beispiel #5
0
        public void Format_WithPoint_ReturnsFormattedString()
        {
            // Setup
            var random = new Random(39);
            var point  = new Point2D(random.NextDouble(), random.NextDouble());

            // Call
            string formattedPoint = GeometrySerializationFormatter.Format(point);

            // Assert
            Assert.AreEqual(point.X.ToString(CultureInfo.InvariantCulture) + " " + point.Y.ToString(CultureInfo.InvariantCulture),
                            formattedPoint);
        }
        public void Constructor_WithCorners_ReturnsExpectedValues()
        {
            // Setup
            var random      = new Random(39);
            var lowerCorner = new Point2D(random.NextDouble(), random.NextDouble());
            var upperCorner = new Point2D(random.NextDouble(), random.NextDouble());

            // Call
            var boundary = new SerializableBoundary(lowerCorner, upperCorner);

            // Assert
            Assert.AreEqual(GeometrySerializationFormatter.Format(lowerCorner), boundary.Envelope.LowerCorner);
            Assert.AreEqual(GeometrySerializationFormatter.Format(upperCorner), boundary.Envelope.UpperCorner);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new instance of <see cref="SerializableEnvelope"/>.
        /// </summary>
        /// <param name="lowerCorner">The lower corner of the envelope.</param>
        /// <param name="upperCorner">The upper corner of the envelope.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public SerializableEnvelope(Point2D lowerCorner, Point2D upperCorner)
        {
            if (lowerCorner == null)
            {
                throw new ArgumentNullException(nameof(lowerCorner));
            }

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

            LowerCorner = GeometrySerializationFormatter.Format(lowerCorner);
            UpperCorner = GeometrySerializationFormatter.Format(upperCorner);
        }
        /// <summary>
        /// Asserts a <see cref="SerializableFailureMechanismSection"/> against
        /// an <see cref="ExportableFailureMechanismSection"/>.
        /// </summary>
        /// <param name="expectedSection">The <see cref="ExportableFailureMechanismSection"/> to assert against.</param>
        /// <param name="expectedCollection">The <see cref="SerializableFailureMechanismSectionCollection"/> the section belongs to.</param>
        /// <param name="actualSerializableSection">The <see cref="SerializableFailureMechanismSection"/> to assert.</param>
        /// <param name="expectedId">The expected id for the <see cref="SerializableFailureMechanismSection"/>.</param>
        /// <exception cref="AssertionException">Thrown when:
        /// <list type="bullet">
        /// <item>The id does not match with the expected id.</item>
        /// <item>The id of the failure mechanism section collection does not match.</item>
        /// <item>The geometry, start distance or the end distance of the failure mechanism section does not match.</item>
        /// <item>The failure mechanism section type does not match.</item>
        /// <item>The used assembly method to obtain the section does not match.</item>
        /// </list>
        /// </exception>
        public static void AssertFailureMechanismSection(ExportableFailureMechanismSection expectedSection,
                                                         SerializableFailureMechanismSectionCollection expectedCollection,
                                                         SerializableFailureMechanismSection actualSerializableSection,
                                                         int expectedId = 0)
        {
            Assert.AreEqual($"Bv.{expectedId}", actualSerializableSection.Id);
            Assert.AreEqual(expectedCollection.Id, actualSerializableSection.FailureMechanismSectionCollectionId);

            Assert.AreEqual(GeometrySerializationFormatter.Format(expectedSection.Geometry),
                            actualSerializableSection.Geometry.LineString.Geometry);
            Assert.AreEqual(expectedSection.StartDistance, actualSerializableSection.StartDistance.Value);
            Assert.AreEqual(expectedSection.EndDistance, actualSerializableSection.EndDistance.Value);
            Assert.AreEqual(SerializableFailureMechanismSectionType.FailureMechanism,
                            actualSerializableSection.FailureMechanismSectionType);
            Assert.IsNull(actualSerializableSection.AssemblyMethod);
        }
Beispiel #9
0
        public void Constructor_WithValidData_ReturnsExpectedValues()
        {
            // Setup
            var random = new Random(39);
            var geometry = new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble()),
                new Point2D(random.NextDouble(), random.NextDouble())
            };

            // Call
            var line = new SerializableLine(geometry);

            // Assert
            Assert.AreEqual(GeometrySerializationFormatter.Format(geometry), line.LineString.Geometry);
        }
        private static void AssertSerializableBoundary(IEnumerable <Point2D> geometry,
                                                       SerializableBoundary actualBoundary)
        {
            var expectedLowerCorner = new Point2D(geometry.Select(p => p.X).Min(),
                                                  geometry.Select(p => p.Y).Min());

            var expectedUpperCorner = new Point2D(geometry.Select(p => p.X).Max(),
                                                  geometry.Select(p => p.Y).Max());

            string expectedLowerCornerFormat = GeometrySerializationFormatter.Format(expectedLowerCorner);
            string expectedUpperCornerFormat = GeometrySerializationFormatter.Format(expectedUpperCorner);

            SerializableEnvelope envelope = actualBoundary.Envelope;

            Assert.AreEqual(expectedLowerCornerFormat, envelope.LowerCorner);
            Assert.AreEqual(expectedUpperCornerFormat, envelope.UpperCorner);
        }
Beispiel #11
0
        public void Format_WithGeometry_ReturnsFormattedString()
        {
            // Setup
            var random   = new Random(39);
            var geometry = new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble()),
                new Point2D(random.NextDouble(), random.NextDouble())
            };

            // Call
            string formattedPoint = GeometrySerializationFormatter.Format(geometry);

            // Assert
            Assert.AreEqual(geometry.Select(point => point.X.ToString(CultureInfo.InvariantCulture) + " " + point.Y.ToString(CultureInfo.InvariantCulture))
                            .Aggregate((p1, p2) => p1 + " " + p2),
                            formattedPoint);
        }
        public void Create_WithAssessmentSection_ReturnsSerializableAssessmentSection()
        {
            // Setup
            const string assessmentSectionName = "Assessment Section Name";
            const string assessmentSectionId   = "assessmentSectionId";

            ExportableAssessmentSection assessmentSection = CreateAssessmentSection(assessmentSectionName,
                                                                                    assessmentSectionId);

            // Call
            SerializableAssessmentSection serializableAssessmentSection =
                SerializableAssessmentSectionCreator.Create(assessmentSection);

            // Assert
            Assert.AreEqual($"Wks.{assessmentSection.Id}", serializableAssessmentSection.Id);
            Assert.AreEqual(assessmentSectionName, serializableAssessmentSection.Name);

            IEnumerable <Point2D> expectedGeometry = assessmentSection.Geometry;

            Assert.AreEqual(Math2D.Length(expectedGeometry), serializableAssessmentSection.ReferenceLineLength.Value);
            Assert.AreEqual(GeometrySerializationFormatter.Format(expectedGeometry),
                            serializableAssessmentSection.ReferenceLineGeometry.LineString.Geometry);
        }
Beispiel #13
0
        public void Constructor_WithValidData_ReturnsExpectedValues()
        {
            // Setup
            const string id = "sectionId";

            var    random            = new Random(39);
            var    sectionCollection = new SerializableFailureMechanismSectionCollection("sectionCollectionId");
            double startDistance     = random.NextDouble();
            double endDistance       = random.NextDouble();
            var    assemblyMethod    = random.NextEnumValue <SerializableAssemblyMethod>();
            var    sectionType       = random.NextEnumValue <SerializableFailureMechanismSectionType>();
            var    geometry          = new[]
            {
                new Point2D(random.NextDouble(), random.NextDouble()),
                new Point2D(random.NextDouble(), random.NextDouble())
            };

            // Call
            var section = new SerializableFailureMechanismSection(id,
                                                                  sectionCollection,
                                                                  startDistance,
                                                                  endDistance,
                                                                  geometry,
                                                                  sectionType,
                                                                  assemblyMethod);

            // Assert
            Assert.AreEqual(id, section.Id);
            Assert.AreEqual(sectionCollection.Id, section.FailureMechanismSectionCollectionId);
            Assert.AreEqual(startDistance, section.StartDistance.Value);
            Assert.AreEqual(endDistance, section.EndDistance.Value);
            Assert.AreEqual(GeometrySerializationFormatter.Format(geometry), section.Geometry.LineString.Geometry);
            Assert.AreEqual(Math2D.Length(geometry), section.Length.Value);
            Assert.AreEqual(assemblyMethod, section.AssemblyMethod);
            Assert.AreEqual(sectionType, section.FailureMechanismSectionType);
        }