public void Read_EntityWithStochasticSoilModelEntityInCollector_CalculationHasAlreadyReadStochasticSoilModel()
        {
            // Setup
            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();
            var stochasticSoilModelEntity = new StochasticSoilModelEntity();

            var stochasticSoilProfile       = new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile());
            var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity
            {
                StochasticSoilModelEntity = stochasticSoilModelEntity
            };

            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity,
                EntryPointL           = 1,
                ExitPointL            = 2,
                DampingFactorExitMean = 1,
                ScenarioContribution  = 0
            };

            var collector = new ReadConversionCollector();

            collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile);
            collector.Read(stochasticSoilModelEntity, stochasticSoilModel);

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(stochasticSoilProfile, calculation.InputParameters.StochasticSoilProfile);
            Assert.AreSame(stochasticSoilModel, calculation.InputParameters.StochasticSoilModel);
        }
        public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem()
        {
            // Setup
            var mockRepository           = new MockRepository();
            var provider                 = mockRepository.DynamicMock <IServiceProvider>();
            var service                  = mockRepository.DynamicMock <IWindowsFormsEditorService>();
            var context                  = mockRepository.DynamicMock <ITypeDescriptorContext>();
            var hasStochasticSoilProfile = mockRepository.Stub <IHasStochasticSoilProfile>();
            var stochasticSoilProfile    = new PipingStochasticSoilProfile(1.0, PipingSoilProfileTestFactory.CreatePipingSoilProfile());

            hasStochasticSoilProfile.Stub(hssp => hssp.StochasticSoilProfile).Return(stochasticSoilProfile);
            hasStochasticSoilProfile.Stub(hssp => hssp.GetAvailableStochasticSoilProfiles()).Return(
                new[]
            {
                stochasticSoilProfile
            });

            var editor      = new PipingInputContextStochasticSoilProfileSelectionEditor <IHasStochasticSoilProfile>();
            var someValue   = new object();
            var propertyBag = new DynamicPropertyBag(hasStochasticSoilProfile);

            provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service);
            service.Expect(s => s.DropDownControl(null)).IgnoreArguments();
            context.Expect(c => c.Instance).Return(propertyBag);

            mockRepository.ReplayAll();

            // Call
            object result = editor.EditValue(context, provider, someValue);

            // Assert
            Assert.AreSame(stochasticSoilProfile, result);

            mockRepository.VerifyAll();
        }
        /// <summary>
        /// Creates piping input with an aquifer layer and coverage layer.
        /// </summary>
        /// <param name="thicknessAquiferLayer">The thickness of the aquifer layer.</param>
        /// <param name="thicknessCoverageLayer">The thickness of the coverage layer.</param>
        /// <typeparam name="T">The type of piping input to create.</typeparam>
        /// <returns>A new <see cref="T"/>.</returns>
        public static T CreateInputWithAquiferAndCoverageLayer <T>(double thicknessAquiferLayer  = 1.0,
                                                                   double thicknessCoverageLayer = 2.0)
            where T : PipingInput, new()
        {
            var surfaceLine = new PipingSurfaceLine(string.Empty);

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(0, 0, thicknessCoverageLayer),
                new Point3D(1.0, 0, thicknessCoverageLayer)
            });
            var stochasticSoilProfile = new PipingStochasticSoilProfile(
                0.0, new PipingSoilProfile(string.Empty, -thicknessAquiferLayer, new[]
            {
                new PipingSoilLayer(thicknessCoverageLayer)
                {
                    IsAquifer = false
                },
                new PipingSoilLayer(0.0)
                {
                    IsAquifer = true
                }
            }, SoilProfileType.SoilProfile1D));

            return(new T
            {
                SurfaceLine = surfaceLine,
                StochasticSoilProfile = stochasticSoilProfile,
                ExitPointL = (RoundedDouble)0.5
            });
        }
        /// <summary>
        /// Creates piping input with multiple aquifer layers under the surface line.
        /// </summary>
        /// <param name="expectedThickness">The expected thickness of the aquifer.</param>
        /// <returns>A new <see cref="PipingInput"/>.</returns>
        public static PipingInput CreateInputWithMultipleAquiferLayersUnderSurfaceLine(out double expectedThickness)
        {
            var surfaceLine = new PipingSurfaceLine(string.Empty);

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(0, 0, 3.3),
                new Point3D(1.0, 0, 3.3)
            });
            var stochasticSoilProfile = new PipingStochasticSoilProfile(
                0.0, new PipingSoilProfile(string.Empty, 0, new[]
            {
                new PipingSoilLayer(4.3)
                {
                    IsAquifer = false
                },
                new PipingSoilLayer(3.3)
                {
                    IsAquifer = true
                },
                new PipingSoilLayer(1.1)
                {
                    IsAquifer = true
                }
            }, SoilProfileType.SoilProfile1D));
            var input = new TestPipingInput
            {
                SurfaceLine           = surfaceLine,
                StochasticSoilProfile = stochasticSoilProfile,
                ExitPointL            = (RoundedDouble)0.5
            };

            expectedThickness = 3.3;
            return(input);
        }
Exemple #5
0
        public void Read_DifferentStochasticSoilProfileEntitiesWithSameSoilProfileEntity_ReturnsStochasticSoilProfilesWithSamePipingSoilProfile()
        {
            // Setup
            var    random            = new Random(21);
            double probability       = random.NextDouble();
            var    soilProfileEntity = new PipingSoilProfileEntity
            {
                Name       = "StochasticSoilProfile",
                SourceType = Convert.ToByte(random.NextEnumValue <SoilProfileType>()),
                PipingSoilLayerEntities =
                {
                    new PipingSoilLayerEntity()
                }
            };
            var firstEntity = new PipingStochasticSoilProfileEntity
            {
                Probability             = probability,
                PipingSoilProfileEntity = soilProfileEntity
            };
            var secondEntity = new PipingStochasticSoilProfileEntity
            {
                Probability             = 1 - probability,
                PipingSoilProfileEntity = soilProfileEntity
            };
            var collector = new ReadConversionCollector();

            PipingStochasticSoilProfile firstProfile = firstEntity.Read(collector);

            // Call
            PipingStochasticSoilProfile secondProfile = secondEntity.Read(collector);

            // Assert
            Assert.AreNotSame(firstProfile, secondProfile);
            Assert.AreSame(firstProfile.SoilProfile, secondProfile.SoilProfile);
        }
        /// <summary>
        /// Creates piping input with a single aquifer layer above the surface line.
        /// </summary>
        /// <param name="deltaAboveSurfaceLine">The distance between the aquifer layer and the surface line.</param>
        /// <returns>A new <see cref="PipingInput"/>.</returns>
        public static PipingInput CreateInputWithSingleAquiferLayerAboveSurfaceLine(double deltaAboveSurfaceLine)
        {
            var          surfaceLine         = new PipingSurfaceLine(string.Empty);
            const double surfaceLineTopLevel = 2.0;

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(0, 0, surfaceLineTopLevel),
                new Point3D(1.0, 0, surfaceLineTopLevel)
            });
            var stochasticSoilProfile = new PipingStochasticSoilProfile(
                0.0, new PipingSoilProfile(string.Empty, 0, new[]
            {
                new PipingSoilLayer(surfaceLineTopLevel + deltaAboveSurfaceLine + 2)
                {
                    IsAquifer = false
                },
                new PipingSoilLayer(surfaceLineTopLevel + deltaAboveSurfaceLine + 1)
                {
                    IsAquifer = true
                },
                new PipingSoilLayer(surfaceLineTopLevel + deltaAboveSurfaceLine)
                {
                    IsAquifer = false
                }
            }, SoilProfileType.SoilProfile1D));
            var input = new TestPipingInput
            {
                SurfaceLine           = surfaceLine,
                StochasticSoilProfile = stochasticSoilProfile,
                ExitPointL            = (RoundedDouble)0.5
            };

            return(input);
        }
Exemple #7
0
        public void GivenReadObject_WhenReadCalledOnSameEntity_ThenSameObjectInstanceReturned()
        {
            // Given
            var random = new Random(9);
            var entity = new PipingStochasticSoilProfileEntity
            {
                PipingSoilProfileEntity = new PipingSoilProfileEntity
                {
                    Name       = "StochasticSoilProfile",
                    SourceType = Convert.ToByte(random.NextEnumValue <SoilProfileType>()),
                    PipingSoilLayerEntities =
                    {
                        new PipingSoilLayerEntity()
                    }
                }
            };

            var collector = new ReadConversionCollector();

            PipingStochasticSoilProfile profile1 = entity.Read(collector);

            // When
            PipingStochasticSoilProfile profile2 = entity.Read(collector);

            // Then
            Assert.AreSame(profile1, profile2);
        }
Exemple #8
0
        public void Read_WithCollector_ReturnsNewStochasticSoilProfileWithPropertiesSet()
        {
            // Setup
            var random = new Random(21);
            var entity = new PipingStochasticSoilProfileEntity
            {
                Probability             = random.NextDouble(),
                PipingSoilProfileEntity = new PipingSoilProfileEntity
                {
                    Name       = "StochasticSoilProfile",
                    SourceType = Convert.ToByte(random.NextEnumValue <SoilProfileType>()),
                    PipingSoilLayerEntities =
                    {
                        new PipingSoilLayerEntity()
                    }
                }
            };
            var collector = new ReadConversionCollector();

            // Call
            PipingStochasticSoilProfile profile = entity.Read(collector);

            // Assert
            Assert.IsNotNull(profile);
            Assert.AreEqual(entity.Probability, profile.Probability, 1e-6);
        }
Exemple #9
0
        /// <summary>
        /// Assigns the stochastic soil profile.
        /// </summary>
        /// <param name="calculationConfiguration">The calculation read from the imported file.</param>
        /// <param name="pipingCalculation">The calculation to configure.</param>
        /// <returns><c>false</c> when the <paramref name="calculationConfiguration"/> has:
        /// <list type="bullet">
        /// <item>a <see cref="PipingStochasticSoilProfile"/> set but no <see cref="PipingStochasticSoilModel"/> is specified;</item>
        /// <item>a <see cref="PipingStochasticSoilProfile"/> set which is not available in the <see cref="PipingStochasticSoilModel"/>.</item>
        /// </list>
        /// <c>true</c> otherwise.</returns>
        private bool TrySetStochasticSoilProfile(PipingCalculationConfiguration calculationConfiguration,
                                                 IPipingCalculationScenario <PipingInput> pipingCalculation)
        {
            if (calculationConfiguration.StochasticSoilProfileName != null)
            {
                if (pipingCalculation.InputParameters.StochasticSoilModel == null)
                {
                    Log.LogCalculationConversionError(string.Format(
                                                          Resources.PipingCalculationConfigurationImporter_ReadStochasticSoilProfile_No_soil_model_provided_for_soil_profile_with_name_0,
                                                          calculationConfiguration.StochasticSoilProfileName),
                                                      pipingCalculation.Name);
                    return(false);
                }

                PipingStochasticSoilProfile soilProfile = pipingCalculation.InputParameters
                                                          .StochasticSoilModel
                                                          .StochasticSoilProfiles
                                                          .FirstOrDefault(ssp => ssp.SoilProfile.Name == calculationConfiguration.StochasticSoilProfileName);

                if (soilProfile == null)
                {
                    Log.LogCalculationConversionError(string.Format(
                                                          Resources.PipingCalculationConfigurationImporter_ReadStochasticSoilProfile_Stochastic_soil_profile_0_does_not_exist_within_soil_model_1,
                                                          calculationConfiguration.StochasticSoilProfileName,
                                                          calculationConfiguration.StochasticSoilModelName),
                                                      pipingCalculation.Name);
                    return(false);
                }

                pipingCalculation.InputParameters.StochasticSoilProfile = soilProfile;
            }

            return(true);
        }
        /// <summary>
        /// Creates piping input with an aquifer layer.
        /// </summary>
        /// <param name="thicknessAquiferLayer">The thickness of the aquifer layer.</param>
        /// <returns>A new <see cref="PipingInput"/>.</returns>
        public static PipingInput CreateInputWithAquifer(double thicknessAquiferLayer = 1.0)
        {
            var surfaceLine = new PipingSurfaceLine(string.Empty);

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(0, 0, 0.0),
                new Point3D(1.0, 0, 0.0)
            });
            var stochasticSoilProfile = new PipingStochasticSoilProfile(
                0.0, new PipingSoilProfile(string.Empty, -thicknessAquiferLayer, new[]
            {
                new PipingSoilLayer(0.0)
                {
                    IsAquifer = true
                }
            }, SoilProfileType.SoilProfile1D));

            return(new TestPipingInput
            {
                SurfaceLine = surfaceLine,
                StochasticSoilProfile = stochasticSoilProfile,
                ExitPointL = (RoundedDouble)0.5
            });
        }
        public void GivenPipingInputViewWithSoilProfileSeries_WhenSurfaceLineSetToNull_ThenCollectionOfEmptyChartDataSetForSoilProfiles()
        {
            // Given
            using (var view = new PipingInputView())
            {
                PipingSurfaceLine           surfaceLine           = GetSurfaceLineWithGeometry();
                PipingStochasticSoilProfile stochasticSoilProfile = GetStochasticSoilProfile();
                var calculation = new TestPipingCalculationScenario(new TestPipingInput())
                {
                    InputParameters =
                    {
                        SurfaceLine           = surfaceLine,
                        StochasticSoilProfile = stochasticSoilProfile
                    }
                };

                view.Data = calculation;

                ChartDataCollection chartData = view.Chart.Data;

                // Precondition
                Assert.IsNotNull(chartData);
                Assert.AreEqual(10, chartData.Collection.Count());
                AssertSoilProfileChartData(stochasticSoilProfile, chartData.Collection.ElementAt(soilProfileIndex), true);

                // When
                calculation.InputParameters.SurfaceLine = null;
                calculation.InputParameters.NotifyObservers();

                // Then
                AssertSoilProfileChartData(stochasticSoilProfile, chartData.Collection.ElementAt(soilProfileIndex), false);
            }
        }
Exemple #12
0
        public void Create_StochasticSoilProfileSet_EntityHasStochasticSoilProfileEntity()
        {
            // Setup
            PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
            var stochasticSoilProfile     = new PipingStochasticSoilProfile(0.6, soilProfile);

            PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("A", new[]
            {
                stochasticSoilProfile
            });

            var registry = new PersistenceRegistry();
            StochasticSoilModelEntity soilModelEntity = soilModel.Create(registry, 0);

            var calculation = new ProbabilisticPipingCalculationScenario
            {
                InputParameters =
                {
                    StochasticSoilModel   = soilModel,
                    StochasticSoilProfile = stochasticSoilProfile
                }
            };

            // Call
            ProbabilisticPipingCalculationEntity entity = calculation.Create(registry, 0);

            // Assert
            PipingStochasticSoilProfileEntity expectedStochasticSoilProfileEntity = soilModelEntity.PipingStochasticSoilProfileEntities.First();

            Assert.AreSame(expectedStochasticSoilProfileEntity, entity.PipingStochasticSoilProfileEntity);
            Assert.IsTrue(registry.Contains(soilModel));
        }
        /// <summary>
        /// Reads the <see cref="PipingStochasticSoilProfileEntity"/> and use the information to
        /// construct a <see cref="PipingStochasticSoilProfile"/>.
        /// </summary>
        /// <param name="entity">The <see cref="PipingStochasticSoilProfileEntity"/> to create
        /// <see cref="PipingStochasticSoilProfile"/> for.</param>
        /// <param name="collector">The object keeping track of read operations.</param>
        /// <returns>A new <see cref="PipingStochasticSoilProfile"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        internal static PipingStochasticSoilProfile Read(this PipingStochasticSoilProfileEntity entity,
                                                         ReadConversionCollector collector)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

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

            if (collector.Contains(entity))
            {
                return(collector.Get(entity));
            }

            PipingSoilProfile soilProfile = entity.ReadSoilProfile(collector);
            var stochasticSoilProfile     = new PipingStochasticSoilProfile(entity.Probability, soilProfile);

            collector.Read(entity, stochasticSoilProfile);

            return(stochasticSoilProfile);
        }
        public void ClearStochasticSoilProfileDependentData_NoCalculationsWithOutputWithProfile_ReturnInput()
        {
            // Setup
            PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations();
            IEnumerable <IPipingCalculationScenario <PipingInput> > calculations = failureMechanism.Calculations
                                                                                   .Cast <IPipingCalculationScenario <PipingInput> >();
            PipingStochasticSoilProfile profileToDelete = null;

            var expectedInputs = new List <PipingInput>();

            foreach (IPipingCalculationScenario <PipingInput> calculation in calculations)
            {
                PipingInput input = calculation.InputParameters;
                PipingStochasticSoilProfile currentProfile = input.StochasticSoilProfile;
                if (profileToDelete == null)
                {
                    profileToDelete = currentProfile;
                }

                if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile))
                {
                    calculation.ClearOutput();
                    expectedInputs.Add(input);
                }
            }

            // Call
            IEnumerable <IObservable> affected = PipingDataSynchronizationService.ClearStochasticSoilProfileDependentData(failureMechanism, profileToDelete);

            // Assert
            CollectionAssert.AreEquivalent(expectedInputs, affected);
            CollectionAssert.IsEmpty(affected.Cast <PipingInput>().Where(a => a.StochasticSoilProfile == null));
        }
Exemple #15
0
        public void Update_ModelsWithAddedProfilesWithSameNames_ThrowsInvalidOperationException()
        {
            // Setup
            const string profileName             = "Name of the profile";
            var          addedProfile            = new PipingStochasticSoilProfile(0.2, PipingSoilProfileTestFactory.CreatePipingSoilProfile(profileName));
            PipingStochasticSoilModel otherModel = CreateValidModel(new[]
            {
                addedProfile
            });

            PipingSoilProfile soilProfile        = PipingSoilProfileTestFactory.CreatePipingSoilProfile(profileName);
            var existingStochasticSoilProfileOne = new PipingStochasticSoilProfile(0.2, soilProfile);
            var existingStochasticSoilProfileTwo = new PipingStochasticSoilProfile(0.3, soilProfile);
            PipingStochasticSoilModel model      = CreateValidModel(new[]
            {
                existingStochasticSoilProfileOne,
                existingStochasticSoilProfileTwo
            });

            // Call
            TestDelegate call = () => model.Update(otherModel);

            // Assert
            Assert.Throws <InvalidOperationException>(call);

            Assert.AreEqual(1, otherModel.StochasticSoilProfiles.Count());
            Assert.AreEqual(addedProfile, otherModel.StochasticSoilProfiles.First());

            Assert.AreEqual(2, model.StochasticSoilProfiles.Count());
            CollectionAssert.AreEqual(new[]
            {
                existingStochasticSoilProfileOne,
                existingStochasticSoilProfileTwo
            }, model.StochasticSoilProfiles);
        }
        public void RemoveStochasticSoilProfileFromInput_NoCalculationsWithProfile_ReturnNoAffectedObjects()
        {
            // Setup
            PipingFailureMechanism failureMechanism = PipingTestDataGenerator.GetPipingFailureMechanismWithAllCalculationConfigurations();
            IEnumerable <IPipingCalculationScenario <PipingInput> > calculations = failureMechanism.Calculations
                                                                                   .Cast <IPipingCalculationScenario <PipingInput> >();
            PipingStochasticSoilProfile profileToDelete = null;

            foreach (IPipingCalculationScenario <PipingInput> calculation in calculations)
            {
                PipingInput input = calculation.InputParameters;
                PipingStochasticSoilProfile currentProfile = input.StochasticSoilProfile;
                if (profileToDelete == null)
                {
                    profileToDelete = currentProfile;
                }

                if (profileToDelete != null && ReferenceEquals(profileToDelete, currentProfile))
                {
                    input.StochasticSoilProfile = null;
                }
            }

            // Call
            IEnumerable <IObservable> affected = PipingDataSynchronizationService.RemoveStochasticSoilProfileFromInput(failureMechanism, profileToDelete);

            // Assert
            CollectionAssert.IsEmpty(affected);
        }
Exemple #17
0
        public void Update_ModelWithRemovedProfileSameNameOtherType_ProfileRemoved()
        {
            // Setup
            const string profileName            = "A";
            var          soilProfile            = new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile1D);
            var          expectedRemovedProfile = new PipingStochasticSoilProfile(0.2, soilProfile);
            var          newProfile             = new PipingStochasticSoilProfile(
                0.2,
                new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile2D));
            PipingStochasticSoilModel model = CreateValidModel(new[]
            {
                CreateStochasticSoilProfile(),
                expectedRemovedProfile
            });

            PipingStochasticSoilModel otherModel = CreateValidModel(new[]
            {
                CreateStochasticSoilProfile(),
                newProfile
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                newProfile
            }, difference.AddedProfiles);
            CollectionAssert.IsEmpty(difference.UpdatedProfiles);
            CollectionAssert.AreEqual(new[]
            {
                expectedRemovedProfile
            }, difference.RemovedProfiles);
        }
Exemple #18
0
        public void Update_ModelWithUpdatedProfile_ProfileUpdated()
        {
            // Setup
            const string profileName            = "A";
            var          expectedUpdatedProfile = new PipingStochasticSoilProfile(
                0.2,
                new PipingSoilProfile(profileName, -2, CreateLayers(), SoilProfileType.SoilProfile1D));
            PipingStochasticSoilModel model = CreateValidModel(new[]
            {
                expectedUpdatedProfile
            });
            PipingStochasticSoilModel otherModel = CreateValidModel(new[]
            {
                new PipingStochasticSoilProfile(0.2,
                                                new PipingSoilProfile(profileName, -1, CreateLayers(), SoilProfileType.SoilProfile1D))
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            Assert.AreEqual(1, otherModel.StochasticSoilProfiles.Count());
            Assert.AreEqual(expectedUpdatedProfile, otherModel.StochasticSoilProfiles.First());

            CollectionAssert.IsEmpty(difference.AddedProfiles);
            CollectionAssert.AreEqual(new[]
            {
                expectedUpdatedProfile
            }, difference.UpdatedProfiles);
            CollectionAssert.IsEmpty(difference.RemovedProfiles);
        }
Exemple #19
0
        public void Update_ModelWithAddedProfile_ProfileAdded()
        {
            // Setup
            PipingStochasticSoilModel model = CreateValidModel(new[]
            {
                CreateStochasticSoilProfile()
            });

            var expectedAddedProfile             = new PipingStochasticSoilProfile(0.2, PipingSoilProfileTestFactory.CreatePipingSoilProfile());
            PipingStochasticSoilModel otherModel = CreateValidModel(new[]
            {
                expectedAddedProfile,
                CreateStochasticSoilProfile()
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            Assert.AreEqual(2, otherModel.StochasticSoilProfiles.Count());
            Assert.AreEqual(expectedAddedProfile, otherModel.StochasticSoilProfiles.First());

            CollectionAssert.AreEqual(new[]
            {
                expectedAddedProfile
            }, difference.AddedProfiles);
            CollectionAssert.IsEmpty(difference.UpdatedProfiles);
            CollectionAssert.IsEmpty(difference.RemovedProfiles);
        }
        private static void AssertCalculationScenario(IPipingCalculationScenario <PipingInput> calculationScenario,
                                                      PipingStochasticSoilProfile stochasticSoilProfile, PipingSurfaceLine surfaceLine)
        {
            PipingInput input = calculationScenario.InputParameters;

            Assert.AreSame(stochasticSoilProfile, input.StochasticSoilProfile);
            Assert.AreSame(surfaceLine, input.SurfaceLine);
            Assert.AreEqual((RoundedDouble)stochasticSoilProfile.Probability, calculationScenario.Contribution);
        }
Exemple #21
0
        public void Update_WithOtherModel_PropertiesUpdated()
        {
            // Setup
            const string equalProfileName   = "nameA";
            var          stochasticProfileA = new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile(equalProfileName));
            var          stochasticProfileB = new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile("nameB"));
            PipingStochasticSoilModel model = CreateValidModel(new[]
            {
                stochasticProfileA,
                stochasticProfileB
            });

            const string otherName     = "other name";
            var          otherGeometry = new[]
            {
                new Point2D(2, 0),
                new Point2D(3, 0)
            };
            var otherStochasticProfileA = new PipingStochasticSoilProfile(
                0.7, new PipingSoilProfile(equalProfileName, -1, new[]
            {
                new PipingSoilLayer(0)
            }, SoilProfileType.SoilProfile1D));
            var otherStochasticProfileB = new PipingStochasticSoilProfile(0.3, PipingSoilProfileTestFactory.CreatePipingSoilProfile("other profile name"));
            var otherModel = new PipingStochasticSoilModel(otherName, otherGeometry, new[]
            {
                otherStochasticProfileA,
                otherStochasticProfileB
            });

            // Call
            PipingStochasticSoilModelProfileDifference difference = model.Update(otherModel);

            // Assert
            Assert.AreEqual(otherName, model.Name);
            Assert.AreSame(otherGeometry, model.Geometry);

            PipingStochasticSoilProfile[] stochasticSoilProfiles = model.StochasticSoilProfiles.ToArray();
            Assert.AreEqual(2, stochasticSoilProfiles.Length);
            Assert.AreSame(stochasticProfileA, stochasticSoilProfiles[0]);
            Assert.AreSame(otherStochasticProfileA.SoilProfile, stochasticSoilProfiles[0].SoilProfile);
            Assert.AreNotSame(stochasticProfileB, stochasticSoilProfiles[1]);
            Assert.AreSame(otherStochasticProfileB.SoilProfile, stochasticSoilProfiles[1].SoilProfile);

            CollectionAssert.AreEqual(new[]
            {
                stochasticProfileA
            }, difference.UpdatedProfiles);
            CollectionAssert.AreEqual(new[]
            {
                stochasticProfileB
            }, difference.RemovedProfiles);
            CollectionAssert.AreEqual(new[]
            {
                otherStochasticProfileB
            }, difference.AddedProfiles);
        }
Exemple #22
0
        public void Constructor_Always_PropertiesHaveExpectedAttributesValues()
        {
            // Setup
            var pipingStochasticSoilProfile = new PipingStochasticSoilProfile(0.0, new PipingSoilProfile("", 0.0, new[]
            {
                new PipingSoilLayer(10.0)
            }, SoilProfileType.SoilProfile1D));

            // Call
            var properties = new PipingStochasticSoilProfileProperties(pipingStochasticSoilProfile);

            // Assert
            const string generalCategoryName = "Algemeen";
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);

            Assert.AreEqual(5, dynamicProperties.Count);

            PropertyDescriptor nameProperty = dynamicProperties[0];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(nameProperty,
                                                                            generalCategoryName,
                                                                            "Naam",
                                                                            "De naam van de ondergrondschematisatie.",
                                                                            true);

            PropertyDescriptor contributionProperty = dynamicProperties[1];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(contributionProperty,
                                                                            generalCategoryName,
                                                                            "Aandeel [%]",
                                                                            "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel.",
                                                                            true);

            PropertyDescriptor layersProperty = dynamicProperties[2];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(layersProperty,
                                                                            generalCategoryName,
                                                                            "Grondlagen",
                                                                            "",
                                                                            true);

            PropertyDescriptor bottomProperty = dynamicProperties[3];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(bottomProperty,
                                                                            generalCategoryName,
                                                                            "Bodemniveau",
                                                                            "Het niveau van de onderkant van de ondergrondschematisatie.",
                                                                            true);

            PropertyDescriptor typeProperty = dynamicProperties[4];

            PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(typeProperty,
                                                                            generalCategoryName,
                                                                            "Type",
                                                                            "Het type van de ondergrondschematisatie.",
                                                                            true);
        }
Exemple #23
0
 private static PipingStochasticSoilProfile CloneAndSlightlyModify(PipingStochasticSoilProfile profile)
 {
     return(new PipingStochasticSoilProfile(profile.Probability,
                                            new PipingSoilProfile(
                                                profile.SoilProfile.Name,
                                                profile.SoilProfile.Bottom - 0.2,
                                                profile.SoilProfile.Layers,
                                                profile.SoilProfile.SoilProfileSourceType)));
 }
        public void GenerateCalculationItemsStructure_SurfaceLineIntersectingSoilModelAndGenerateSemiProbabilisticAndProbabilisticFalse_ReturnEmptyCollection()
        {
            // Setup
            var soilProfile1 = new PipingStochasticSoilProfile(
                0.3, new PipingSoilProfile("Profile 1", -10.0, new[]
            {
                new PipingSoilLayer(-5.0),
                new PipingSoilLayer(-2.0),
                new PipingSoilLayer(1.0)
            }, SoilProfileType.SoilProfile1D)
                );
            var soilProfile2 = new PipingStochasticSoilProfile(0.7, new PipingSoilProfile("Profile 2", -8.0, new[]
            {
                new PipingSoilLayer(-4.0),
                new PipingSoilLayer(0.0),
                new PipingSoilLayer(4.0)
            }, SoilProfileType.SoilProfile1D)
                                                               );

            var soilModel = new PipingStochasticSoilModel("A", new[]
            {
                new Point2D(1.0, 0.0),
                new Point2D(5.0, 0.0)
            }, new[]
            {
                soilProfile1,
                soilProfile2
            });

            PipingStochasticSoilModel[] availableSoilModels =
            {
                soilModel
            };

            var surfaceLine = new PipingSurfaceLine("surface line");

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(3.0, 5.0, 0.0),
                new Point3D(3.0, 0.0, 1.0),
                new Point3D(3.0, -5.0, 0.0)
            });

            PipingSurfaceLine[] surfaceLines =
            {
                surfaceLine
            };

            // Call
            IEnumerable <ICalculationBase> result = PipingCalculationConfigurationHelper.GenerateCalculationItemsStructure(
                surfaceLines, false, false,
                availableSoilModels).ToArray();

            // Assert
            CollectionAssert.IsEmpty(result);
        }
        public void Update_WithValidProfile_UpdatesProperties(PipingStochasticSoilProfile stochasticProfile,
                                                              PipingStochasticSoilProfile otherStochasticProfile)
        {
            // Call
            stochasticProfile.Update(otherStochasticProfile);

            // Assert
            Assert.AreEqual(otherStochasticProfile.Probability, stochasticProfile.Probability);
            Assert.AreSame(otherStochasticProfile.SoilProfile, stochasticProfile.SoilProfile);
        }
Exemple #26
0
        public void UpdateModelWithImportedData_ProfilesAssignedToCalculationsWithOneImportedModelProfileRemoved_OneProfileRemovedCalculationUpdatedAccordingly()
        {
            // Setup
            const string modelsName = "same model";
            PipingStochasticSoilModel existingModel = CreateSimpleModel(modelsName, "Unaffected Profile", "Removed Profile");

            var failureMechanism = new PipingFailureMechanism();
            PipingStochasticSoilModelCollection targetCollection = failureMechanism.StochasticSoilModels;

            targetCollection.AddRange(new[]
            {
                existingModel
            }, sourceFilePath);

            PipingStochasticSoilProfile firstExistingProfile = existingModel.StochasticSoilProfiles.First();
            PipingStochasticSoilModel   readModel            = CreateSimpleModel(modelsName, firstExistingProfile.SoilProfile.Name);

            var calculationWithNotUpdatedProfile = new SemiProbabilisticPipingCalculationScenario();

            calculationWithNotUpdatedProfile.InputParameters.StochasticSoilModel   = existingModel;
            calculationWithNotUpdatedProfile.InputParameters.StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(0);
            calculationWithNotUpdatedProfile.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties());

            var calculationWithDeletedProfile = new SemiProbabilisticPipingCalculationScenario();

            calculationWithDeletedProfile.InputParameters.StochasticSoilModel   = existingModel;
            calculationWithDeletedProfile.InputParameters.StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(1);
            calculationWithDeletedProfile.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties());

            failureMechanism.CalculationsGroup.Children.Add(calculationWithDeletedProfile);
            failureMechanism.CalculationsGroup.Children.Add(calculationWithNotUpdatedProfile);

            var strategy = new PipingStochasticSoilModelUpdateDataStrategy(failureMechanism);

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

            // Assert
            PipingStochasticSoilModel firstSoilModel = targetCollection[0];

            Assert.AreSame(existingModel, firstSoilModel);
            Assert.AreSame(firstExistingProfile, firstSoilModel.StochasticSoilProfiles.ElementAt(0));

            Assert.IsTrue(calculationWithNotUpdatedProfile.HasOutput);
            CollectionAssert.DoesNotContain(affectedObjects, calculationWithNotUpdatedProfile);
            CollectionAssert.DoesNotContain(affectedObjects, calculationWithNotUpdatedProfile.InputParameters);

            Assert.IsFalse(calculationWithDeletedProfile.HasOutput);
            Assert.IsNull(calculationWithDeletedProfile.InputParameters.StochasticSoilProfile);
            CollectionAssert.Contains(affectedObjects, calculationWithDeletedProfile);
            CollectionAssert.Contains(affectedObjects, calculationWithDeletedProfile.InputParameters);
        }
        public void UpdateObserver_StochasticSoilProfileUpdated_ChartDataUpdated()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            using (var view = new PipingInputView())
            {
                PipingSurfaceLine           surfaceLine = GetSurfaceLineWithGeometry();
                PipingStochasticSoilProfile soilProfile = GetStochasticSoilProfile();
                var soilProfile2 = new PipingStochasticSoilProfile(
                    0.5, new PipingSoilProfile("profile 2", -2, new[]
                {
                    new PipingSoilLayer(0)
                    {
                        MaterialName = "Grass"
                    },
                    new PipingSoilLayer(2)
                    {
                        MaterialName = "Stone"
                    },
                    new PipingSoilLayer(3)
                    {
                        MaterialName = "Peat"
                    }
                }, SoilProfileType.SoilProfile1D));

                var calculation = new TestPipingCalculationScenario(new TestPipingInput())
                {
                    InputParameters =
                    {
                        SurfaceLine           = surfaceLine,
                        StochasticSoilProfile = soilProfile
                    }
                };

                view.Data = calculation;

                var soilProfileData = (ChartDataCollection)view.Chart.Data.Collection.ElementAt(soilProfileIndex);
                soilProfileData.Attach(observer);

                calculation.InputParameters.StochasticSoilProfile = soilProfile2;

                // Call
                calculation.InputParameters.NotifyObservers();

                // Assert
                Assert.AreSame(soilProfileData, (ChartDataCollection)view.Chart.Data.Collection.ElementAt(soilProfileIndex));
                AssertSoilProfileChartData(soilProfile2, soilProfileData, true);
                mocks.VerifyAll();
            }
        }
        public void GetStochasticSoilModelsForSurfaceLine_SurfaceLineIntersectingSoilModel_ReturnSoilModel()
        {
            // Setup
            var soilProfile1 = new PipingStochasticSoilProfile(
                0.3, new PipingSoilProfile("Profile 1", -10.0, new[]
            {
                new PipingSoilLayer(-5.0),
                new PipingSoilLayer(-2.0),
                new PipingSoilLayer(1.0)
            }, SoilProfileType.SoilProfile1D));
            var soilProfile2 = new PipingStochasticSoilProfile(
                0.7, new PipingSoilProfile("Profile 2", -8.0, new[]
            {
                new PipingSoilLayer(-4.0),
                new PipingSoilLayer(0.0),
                new PipingSoilLayer(4.0)
            }, SoilProfileType.SoilProfile1D));

            var soilModel = new PipingStochasticSoilModel("A", new[]
            {
                new Point2D(1.0, 0.0),
                new Point2D(5.0, 0.0)
            }, new[]
            {
                soilProfile1,
                soilProfile2
            });

            PipingStochasticSoilModel[] availableSoilModels =
            {
                soilModel
            };

            var surfaceLine = new PipingSurfaceLine("surface line");

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(3.0, 5.0, 0.0),
                new Point3D(3.0, 0.0, 1.0),
                new Point3D(3.0, -5.0, 0.0)
            });

            // Call
            IEnumerable <PipingStochasticSoilModel> result = PipingCalculationConfigurationHelper.GetStochasticSoilModelsForSurfaceLine(
                surfaceLine,
                availableSoilModels);

            // Assert
            PipingStochasticSoilModel[] expected =
            {
                soilModel
            };
            CollectionAssert.AreEquivalent(expected, result);
        }
Exemple #29
0
        public void StochasticSoilProfile_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged()
        {
            // Setup
            var newProfile = new PipingStochasticSoilProfile(0, PipingSoilProfileTestFactory.CreatePipingSoilProfile());
            var newValue   = new DataGridViewComboBoxItemWrapper <PipingStochasticSoilProfile>(newProfile);

            var calculation = new TestPipingCalculationScenario();

            // Call & Assert
            SetPropertyAndVerifyNotificationsAndOutputForCalculation(row => row.StochasticSoilProfile = newValue, calculation);
        }
        public void CreateInstance_WithStochasticSoilProfile_NewPropertiesWithInputAsData()
        {
            // Setup
            var stochasticSoilProfile = new PipingStochasticSoilProfile(0.5, PipingSoilProfileTestFactory.CreatePipingSoilProfile());

            // Call
            IObjectProperties objectProperties = info.CreateInstance(stochasticSoilProfile);

            // Assert
            Assert.IsInstanceOf <PipingStochasticSoilProfileProperties>(objectProperties);
            Assert.AreSame(stochasticSoilProfile, objectProperties.Data);
        }