Пример #1
0
        public void UpdateStructuresWithImportedData_WithCurrentAndImportedDataAreDifferent_ReplacesCurrentWithImportedData()
        {
            // Setup
            var failureMechanism = new ClosingStructuresFailureMechanism();

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

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

            var strategy = new ClosingStructureReplaceDataStrategy(failureMechanism);

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

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

            TestClosingStructure[] expected =
            {
                importedStructure
            };
            CollectionAssert.AreEqual(expected, failureMechanism.ClosingStructures);
        }
Пример #2
0
        public void UpdateStructuresWithImportedData_NoCurrentStructuresWithImportedData_AddsNewStructure()
        {
            // Setup
            var importedStructures = new[]
            {
                new TestClosingStructure()
            };

            var failureMechanism = new ClosingStructuresFailureMechanism();
            var strategy         = new ClosingStructureReplaceDataStrategy(failureMechanism);

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

            // Assert
            StructureCollection <ClosingStructure> actualCollection = failureMechanism.ClosingStructures;

            CollectionAssert.AreEqual(importedStructures, actualCollection);
            CollectionAssert.AreEqual(new[]
            {
                actualCollection
            }, affectedObjects);
            Assert.AreEqual(sourceFilePath, actualCollection.SourcePath);
        }
Пример #3
0
        public void Constructor_ValidFailureMechanism_CreatesNewInstance()
        {
            // Setup
            var failureMechanism = new ClosingStructuresFailureMechanism();

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

            // Assert
            Assert.IsInstanceOf <IStructureUpdateStrategy <ClosingStructure> >(strategy);
            Assert.IsInstanceOf <ReplaceDataStrategyBase <ClosingStructure, ClosingStructuresFailureMechanism> >(strategy);
        }
Пример #4
0
        public void UpdateStructuresWithImportedData_SourceFilePathNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new ClosingStructureReplaceDataStrategy(new ClosingStructuresFailureMechanism());

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

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

            Assert.AreEqual("sourceFilePath", exception.ParamName);
        }
Пример #5
0
        public void UpdateStructuresWithImportedData_ReadClosingStructuresNull_ThrowsArgumentNullException()
        {
            // Setup
            var strategy = new ClosingStructureReplaceDataStrategy(new ClosingStructuresFailureMechanism());

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

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

            Assert.AreEqual("importedDataCollection", exception.ParamName);
        }
Пример #6
0
        public void UpdateStructuresWithImportedData_CalculationWithOutputAndStructure_CalculationUpdatedAndReturnsAffectedObject()
        {
            // Setup
            var structure = new TestClosingStructure();

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

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

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

            var strategy = new ClosingStructureReplaceDataStrategy(failureMechanism);

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

            // Assert
            Assert.IsFalse(calculation.HasOutput);
            Assert.IsNull(calculation.InputParameters.Structure);
            CollectionAssert.AreEquivalent(new IObservable[]
            {
                calculation,
                calculation.InputParameters,
                failureMechanism.ClosingStructures
            }, affectedObjects);
        }
Пример #7
0
        public void UpdateStructuresWithImportedData_NoCurrentStructures_SetsSourcePath()
        {
            // Setup
            var failureMechanism = new ClosingStructuresFailureMechanism();
            StructureCollection <ClosingStructure> targetCollection = failureMechanism.ClosingStructures;

            var strategy = new ClosingStructureReplaceDataStrategy(failureMechanism);

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

            // Assert
            CollectionAssert.IsEmpty(targetCollection);
            CollectionAssert.AreEqual(new[]
            {
                targetCollection
            }, affectedObjects);
            Assert.AreEqual(sourceFilePath, targetCollection.SourcePath);
        }
Пример #8
0
        public void UpdateStructuresWithImportedData_DifferentSourcePath_UpdatesSourcePathOfTargetCollection()
        {
            // Setup
            var failureMechanism = new ClosingStructuresFailureMechanism();
            StructureCollection <ClosingStructure> targetCollection = failureMechanism.ClosingStructures;

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

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

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

            ClosingStructure[] importedClosingStructures =
            {
                new TestClosingStructure(duplicateId, "name"),
                new TestClosingStructure(duplicateId, "Other name")
            };

            var strategy = new ClosingStructureReplaceDataStrategy(new ClosingStructuresFailureMechanism());

            // Call
            void Call() => strategy.UpdateStructuresWithImportedData(importedClosingStructures, 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);
        }