Exemple #1
0
        public void UpdateStructuresWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism();

            failureMechanism.HeightStructures.AddRange(new[]
            {
                new TestHeightStructure("id", "Original")
            }, sourceFilePath);

            var importedStructure = new TestHeightStructure("Different id", "Imported");

            var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[]
            {
                importedStructure
            }, sourceFilePath);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                failureMechanism.HeightStructures
            }, affectedObjects);

            TestHeightStructure[] expected =
            {
                importedStructure
            };
            CollectionAssert.AreEqual(expected, failureMechanism.HeightStructures);
        }
Exemple #2
0
        public void UpdateStructuresWithImportedData_NoCurrentStructuresWithImportedData_AddsNewStructure()
        {
            // Setup
            var importedStructures = new[]
            {
                new TestHeightStructure()
            };

            var failureMechanism = new HeightStructuresFailureMechanism();
            var strategy         = new HeightStructureReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(importedStructures,
                                                                                                  sourceFilePath);

            // Assert
            StructureCollection <HeightStructure> actualCollection = failureMechanism.HeightStructures;

            CollectionAssert.AreEqual(importedStructures, actualCollection);
            CollectionAssert.AreEqual(new[]
            {
                actualCollection
            }, affectedObjects);
            Assert.AreEqual(sourceFilePath, actualCollection.SourcePath);
        }
Exemple #3
0
        public void Constructor_ValidFailureMechanism_CreatesNewInstance()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism();

            // Call
            var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);

            // Assert
            Assert.IsInstanceOf <IStructureUpdateStrategy <HeightStructure> >(strategy);
            Assert.IsInstanceOf <ReplaceDataStrategyBase <HeightStructure, HeightStructuresFailureMechanism> >(strategy);
        }
Exemple #4
0
        public void UpdateStructuresWithImportedData_SourceFilePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism());

            // Call
            void Call() => strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(), null);

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

            Assert.AreEqual("sourceFilePath", exception.ParamName);
        }
Exemple #5
0
        public void UpdateStructuresWithImportedData_ReadHeightStructuresNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism());

            // Call
            TestDelegate test = () => strategy.UpdateStructuresWithImportedData(null,
                                                                                string.Empty);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(test).ParamName;

            Assert.AreEqual("importedDataCollection", paramName);
        }
        public void Constructor_Always_ExpectedValues()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();

            mocks.ReplayAll();

            var replaceDataStrategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism());

            // Call
            var importer = new HeightStructuresImporter(testImportTarget, testReferenceLine, testFilePath,
                                                        messageProvider, replaceDataStrategy);

            // Assert
            Assert.IsInstanceOf <StructuresImporter <HeightStructure> >(importer);
        }
Exemple #7
0
        public void UpdateStructuresWithImportedData_CalculationWithOutputAndStructure_CalculationUpdatedAndReturnsAffectedObject()
        {
            // Setup
            var structure = new TestHeightStructure();

            var calculation = new TestHeightStructuresCalculationScenario
            {
                InputParameters =
                {
                    Structure = structure
                },
                Output = new TestStructuresOutput()
            };

            var failureMechanism = new HeightStructuresFailureMechanism
            {
                CalculationsGroup =
                {
                    Children =
                    {
                        calculation
                    }
                }
            };

            failureMechanism.HeightStructures.AddRange(new[]
            {
                structure
            }, sourceFilePath);

            var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(),
                                                                                                  sourceFilePath).ToArray();

            // Assert
            Assert.IsFalse(calculation.HasOutput);
            Assert.IsNull(calculation.InputParameters.Structure);
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                calculation,
                calculation.InputParameters,
                failureMechanism.HeightStructures
            }, affectedObjects);
        }
Exemple #8
0
        public void UpdateStructuresWithImportedData_NoCurrentStructures_SetsSourcePath()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism();
            StructureCollection <HeightStructure> targetCollection = failureMechanism.HeightStructures;

            var strategy = new HeightStructureReplaceDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(),
                                                                                                  sourceFilePath);

            // Assert
            CollectionAssert.IsEmpty(targetCollection);
            CollectionAssert.AreEqual(new[]
            {
                targetCollection
            }, affectedObjects);
            Assert.AreEqual(sourceFilePath, targetCollection.SourcePath);
        }
Exemple #9
0
        public void UpdateStructuresWithImportedData_DifferentSourcePath_UpdatesSourcePathOfTargetCollection()
        {
            // Setup
            var failureMechanism = new HeightStructuresFailureMechanism();
            StructureCollection <HeightStructure> targetCollection = failureMechanism.HeightStructures;

            var          strategy      = new HeightStructureReplaceDataStrategy(failureMechanism);
            const string newSourcePath = "some/other/path";

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(Enumerable.Empty <HeightStructure>(),
                                                                                                  newSourcePath);

            // Assert
            CollectionAssert.AreEqual(new IObservable[]
            {
                targetCollection
            }, affectedObjects);
            CollectionAssert.IsEmpty(targetCollection);
            Assert.AreEqual(newSourcePath, targetCollection.SourcePath);
        }
Exemple #10
0
        public void UpdateStructuresWithImportedData_ImportedDataContainsDuplicateIds_ThrowsUpdateDataException()
        {
            // Setup
            const string duplicateId = "I am a duplicate id";

            HeightStructure[] importedHeightStructures =
            {
                new TestHeightStructure(duplicateId, "name"),
                new TestHeightStructure(duplicateId, "Other name")
            };

            var strategy = new HeightStructureReplaceDataStrategy(new HeightStructuresFailureMechanism());

            // Call
            TestDelegate call = () => strategy.UpdateStructuresWithImportedData(importedHeightStructures,
                                                                                sourceFilePath);

            // Assert
            var    exception       = Assert.Throws <UpdateDataException>(call);
            string expectedMessage = "Kunstwerken moeten een unieke id hebben. " +
                                     $"Gevonden dubbele elementen: {duplicateId}.";

            Assert.AreEqual(expectedMessage, exception.Message);
        }