public void SetSections_ValidSections_SectionsAndSourcePathSet()
        {
            // Setup
            string sourcePath        = TestHelper.GetScratchPadPath();
            var    sectionCollection = new FailureMechanismSectionCollection();

            const int matchingX = 1;
            const int matchingY = 2;

            var section1 = new FailureMechanismSection("A", new[]
            {
                new Point2D(3, 4),
                new Point2D(matchingX, matchingY)
            });
            var section2 = new FailureMechanismSection("B", new[]
            {
                new Point2D(matchingX, matchingY),
                new Point2D(-2, -1)
            });

            // Call
            sectionCollection.SetSections(new[]
            {
                section1,
                section2
            }, sourcePath);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                section1,
                section2
            }, sectionCollection);
            Assert.AreEqual(sourcePath, sectionCollection.SourcePath);
        }
        public void GivenCollectionWithSections_WhenArgumentExceptionThrown_ThenOldDataRemains()
        {
            // Given
            var    sectionCollection           = new FailureMechanismSectionCollection();
            string oldPath                     = TestHelper.GetScratchPadPath();
            FailureMechanismSection oldSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            sectionCollection.SetSections(new[]
            {
                oldSection
            }, oldPath);

            var section1 = new FailureMechanismSection("A", new[]
            {
                new Point2D(1, 2),
                new Point2D(3, 4)
            });
            var section2 = new FailureMechanismSection("B", new[]
            {
                new Point2D(5, 6),
                new Point2D(7, 8)
            });

            // When
            TestDelegate call = () => sectionCollection.SetSections(new[]
            {
                section1,
                section2
            }, string.Empty);

            // Then
            Assert.Throws <ArgumentException>(call);
            Assert.AreSame(oldSection, sectionCollection.Single());
            Assert.AreEqual(oldPath, sectionCollection.SourcePath);
        }
        public void SetSections_SecondSectionDoesNotConnectToFirst_ThrowsArgumentException()
        {
            // Setup
            var sectionCollection = new FailureMechanismSectionCollection();

            var section1 = new FailureMechanismSection("A", new[]
            {
                new Point2D(1, 2),
                new Point2D(3, 4)
            });
            var section2 = new FailureMechanismSection("B", new[]
            {
                new Point2D(5, 6),
                new Point2D(7, 8)
            });

            // Call
            TestDelegate call = () => sectionCollection.SetSections(new[]
            {
                section1,
                section2
            }, string.Empty);

            // Assert
            const string expectedMessage = "Vak 'B' sluit niet aan op de al gedefinieerde vakken van het faalmechanisme.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);
            CollectionAssert.IsEmpty(sectionCollection);
            Assert.IsNull(sectionCollection.SourcePath);
        }
        public void Constructor_ExpectedValues()
        {
            // Call
            var sectionCollection = new FailureMechanismSectionCollection();

            // Assert
            Assert.IsInstanceOf <IEnumerable <FailureMechanismSection> >(sectionCollection);
            Assert.IsInstanceOf <Observable>(sectionCollection);
            Assert.IsNull(sectionCollection.SourcePath);
            CollectionAssert.IsEmpty(sectionCollection);
        }
        public void SetSections_SourcePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var sectionCollection = new FailureMechanismSectionCollection();

            // Call
            TestDelegate call = () => sectionCollection.SetSections(Enumerable.Empty <FailureMechanismSection>(), null);

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

            Assert.AreEqual("sourcePath", exception.ParamName);
        }
        public void SetSections_FailureMechanismSectionsNull_ThrowsArgumentNullException()
        {
            // Setup
            var sectionCollection = new FailureMechanismSectionCollection();

            // Call
            TestDelegate call = () => sectionCollection.SetSections(null, string.Empty);

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

            Assert.AreEqual("failureMechanismSections", exception.ParamName);
        }
        public void SetSections_WithEmptySectionCollection_SourcePathSet()
        {
            // Setup
            string sourcePath        = TestHelper.GetScratchPadPath();
            var    sectionCollection = new FailureMechanismSectionCollection();

            // Call
            sectionCollection.SetSections(Enumerable.Empty <FailureMechanismSection>(), sourcePath);

            // Assert
            CollectionAssert.IsEmpty(sectionCollection);
            Assert.AreEqual(sourcePath, sectionCollection.SourcePath);
        }
        /// <summary>
        /// Creates a new instance of <see cref="TestFailureMechanism"/>.
        /// </summary>
        public TestFailureMechanism()
        {
            Name = "Faalmechanisme";
            Code = "NIEUW";

            sectionCollection        = new FailureMechanismSectionCollection();
            InAssembly               = true;
            GeneralInput             = new GeneralInput();
            InAssemblyInputComments  = new Comment();
            InAssemblyOutputComments = new Comment();
            NotInAssemblyComments    = new Comment();
            AssemblyResult           = new FailureMechanismAssemblyResult();
            sectionResults           = new ObservableList <TestFailureMechanismSectionResult>();
        }
        public void SetSections_InvalidPath_ThrowsArgumentException()
        {
            // Setup
            const string sourcePath        = "<invalid>";
            var          sectionCollection = new FailureMechanismSectionCollection();

            // Call
            TestDelegate call = () => sectionCollection.SetSections(Enumerable.Empty <FailureMechanismSection>(), sourcePath);

            // Assert
            string expectedMessage = $@"'{sourcePath}' is not a valid file path.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage);
        }
        public void Clear_Always_ClearsSectionsAndSourcePath()
        {
            // Setup
            var sectionCollection = new FailureMechanismSectionCollection();

            sectionCollection.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, TestHelper.GetScratchPadPath());

            // Call
            sectionCollection.Clear();

            // Assert
            CollectionAssert.IsEmpty(sectionCollection);
            Assert.IsNull(sectionCollection.SourcePath);
        }