public void SelectedHydraulicBoundaryLocation_Always_InputChangedAndObservablesNotified() { var location = new SelectableHydraulicBoundaryLocation(CreateHydraulicBoundaryLocation(), null); SetPropertyAndVerifyNotificationsAndOutput( properties => properties.SelectedHydraulicBoundaryLocation = location); }
public void SelectedHydraulicBoundaryLocation_InputNoLocation_ReturnsNull() { // Setup mockRepository.ReplayAll(); var calculation = new StructuresCalculation <SimpleStructureInput>(); var inputContext = new SimpleInputContext(calculation.InputParameters, calculation, failureMechanism, assessmentSection); var properties = new SimpleStructuresInputProperties( inputContext, new StructuresInputBaseProperties <TestStructure, SimpleStructureInput, StructuresCalculation <SimpleStructureInput>, IFailureMechanism> .ConstructionProperties(), handler); SelectableHydraulicBoundaryLocation selectedHydraulicBoundaryLocation = null; // Call TestDelegate call = () => selectedHydraulicBoundaryLocation = properties.SelectedHydraulicBoundaryLocation; // Assert Assert.DoesNotThrow(call); Assert.IsNull(selectedHydraulicBoundaryLocation); mockRepository.VerifyAll(); }
public void EditValue_WithCurrentItemNotInAvailableItems_ReturnsOriginalValue() { // Setup SelectableHydraulicBoundaryLocation selectableHydraulicBoundaryLocation = CreateSelectableHydraulicBoundaryLocation(); var properties = new ObjectPropertiesWithSelectableHydraulicBoundaryLocation( selectableHydraulicBoundaryLocation, new SelectableHydraulicBoundaryLocation[0]); var propertyBag = new DynamicPropertyBag(properties); var editor = new HydraulicBoundaryLocationEditor(); var someValue = new object(); var serviceProvider = mockRepository.Stub <IServiceProvider>(); var service = mockRepository.Stub <IWindowsFormsEditorService>(); var descriptorContext = mockRepository.Stub <ITypeDescriptorContext>(); serviceProvider.Stub(p => p.GetService(null)).IgnoreArguments().Return(service); descriptorContext.Stub(c => c.Instance).Return(propertyBag); mockRepository.ReplayAll(); // Call object result = editor.EditValue(descriptorContext, serviceProvider, someValue); // Assert Assert.AreSame(someValue, result); mockRepository.VerifyAll(); }
public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers() { // Setup const int numberOfChangedProperties = 6; var observer = mockRepository.StrictMock <IObserver>(); observer.Expect(o => o.UpdateObserver()).Repeat.Times(numberOfChangedProperties); mockRepository.ReplayAll(); var calculation = new StructuresCalculation <SimpleStructureInput> { InputParameters = { Structure = new TestStructure() } }; var inputContext = new SimpleInputContext(calculation.InputParameters, calculation, failureMechanism, assessmentSection); var properties = new SimpleStructuresInputProperties( inputContext, new StructuresInputBaseProperties <TestStructure, SimpleStructureInput, StructuresCalculation <SimpleStructureInput>, IFailureMechanism> .ConstructionProperties(), new ObservablePropertyChangeHandler(inputContext.Calculation, calculation.InputParameters)); inputContext.Attach(observer); var random = new Random(100); double newStructureNormalOrientation = random.NextDouble(); const bool newShouldIllustrationPointsBeCalculated = true; var newStructure = new TestStructure(); ForeshoreProfile newForeshoreProfile = new TestForeshoreProfile(); HydraulicBoundaryLocation newHydraulicBoundaryLocation = CreateHydraulicBoundaryLocation(); var newSelectableHydraulicBoundaryLocation = new SelectableHydraulicBoundaryLocation(newHydraulicBoundaryLocation, null); // Call properties.Structure = newStructure; properties.StructureNormalOrientation = (RoundedDouble)newStructureNormalOrientation; properties.FailureProbabilityStructureWithErosion = 1e-2; properties.SelectedHydraulicBoundaryLocation = newSelectableHydraulicBoundaryLocation; properties.ForeshoreProfile = newForeshoreProfile; properties.ShouldIllustrationPointsBeCalculated = newShouldIllustrationPointsBeCalculated; // Assert Assert.AreSame(newStructure, properties.Structure); Assert.AreEqual(newStructureNormalOrientation, properties.StructureNormalOrientation, properties.StructureNormalOrientation.GetAccuracy()); Assert.AreEqual(0.01, properties.FailureProbabilityStructureWithErosion); Assert.AreSame(newHydraulicBoundaryLocation, properties.SelectedHydraulicBoundaryLocation.HydraulicBoundaryLocation); Assert.AreSame(newForeshoreProfile, properties.ForeshoreProfile); Assert.AreEqual(newShouldIllustrationPointsBeCalculated, properties.ShouldIllustrationPointsBeCalculated); mockRepository.VerifyAll(); }
public void SelectableHydraulicBoundaryLocation_AlwaysOnChange_NotifyObserverAndCalculationPropertyChanged() { // Setup var newLocation = new TestHydraulicBoundaryLocation(); var selectableHydraulicBoundaryLocation = new SelectableHydraulicBoundaryLocation(newLocation, new Point2D(0, 0)); var newValue = new DataGridViewComboBoxItemWrapper <SelectableHydraulicBoundaryLocation>(selectableHydraulicBoundaryLocation); var calculation = new StructuresCalculationScenario <HeightStructuresInput>(); // Call & Assert SetPropertyAndVerifyNotificationsAndOutputForCalculation(row => row.SelectableHydraulicBoundaryLocation = newValue, calculation); }
public void ToString_DifferentReferencePoints_ReturnsExpectedString(HydraulicBoundaryLocation location, Point2D referencePoint, string expectedString) { // Setup var inputItem = new SelectableHydraulicBoundaryLocation(location, referencePoint); // Call var stringRepresentation = inputItem.ToString(); // Assert Assert.AreEqual(expectedString, stringRepresentation); }
public void GetSelectableHydraulicBoundaryLocations_InputWithLocationsStructure_CalculatesDistanceWithCorrectReferencePoint() { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 200643.312, 503347.25); assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase { Locations = { hydraulicBoundaryLocation } }); mockRepository.ReplayAll(); var calculation = new StructuresCalculation <SimpleStructureInput> { InputParameters = { Structure = new TestStructure(new Point2D(200620.173572981, 503401.652985217)) } }; var inputContext = new SimpleInputContext(calculation.InputParameters, calculation, failureMechanism, assessmentSection); var properties = new SimpleStructuresInputProperties( inputContext, new StructuresInputBaseProperties <TestStructure, SimpleStructureInput, StructuresCalculation <SimpleStructureInput>, IFailureMechanism> .ConstructionProperties(), handler); // Call IEnumerable <SelectableHydraulicBoundaryLocation> availableHydraulicBoundaryLocations = properties.GetSelectableHydraulicBoundaryLocations(); // Assert double distanceToPropertiesStructureLocation = hydraulicBoundaryLocation.Location.GetEuclideanDistanceTo(properties.StructureLocation); double distanceToInputStructureLocation = hydraulicBoundaryLocation.Location.GetEuclideanDistanceTo(calculation.InputParameters.Structure.Location); Assert.AreEqual(59, distanceToPropertiesStructureLocation, 1); Assert.AreEqual(60, distanceToInputStructureLocation, 1); SelectableHydraulicBoundaryLocation hydraulicBoundaryLocationItem = availableHydraulicBoundaryLocations.ToArray()[0]; RoundedDouble itemDistance = hydraulicBoundaryLocationItem.Distance; Assert.AreEqual(distanceToInputStructureLocation, itemDistance, itemDistance.GetAccuracy()); mockRepository.VerifyAll(); }
public void Constructor_ArgumentsNotNull_ReturnsRightData(Point2D referencePoint, double expectedDistance) { // Setup var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "Location", 0, 0); // Call var inputItem = new SelectableHydraulicBoundaryLocation(hydraulicBoundaryLocation, referencePoint); // Assert Assert.AreSame(hydraulicBoundaryLocation, inputItem.HydraulicBoundaryLocation); Assert.AreEqual(0, inputItem.Distance.NumberOfDecimalPlaces); Assert.AreEqual(expectedDistance, inputItem.Distance.Value); }
public void GivenPropertiesWithStructureAndLocations_WhenSelectingLocation_ThenSelectedLocationDistanceSameAsLocationItem() { // Given var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 200643.312, 503347.25); assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase { Locations = { hydraulicBoundaryLocation } }); mockRepository.ReplayAll(); var calculation = new StructuresCalculation <SimpleStructureInput> { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation, Structure = new TestStructure(new Point2D(200620.173572981, 503401.652985217)) } }; var inputContext = new SimpleInputContext(calculation.InputParameters, calculation, failureMechanism, assessmentSection); var properties = new SimpleStructuresInputProperties( inputContext, new StructuresInputBaseProperties <TestStructure, SimpleStructureInput, StructuresCalculation <SimpleStructureInput>, IFailureMechanism> .ConstructionProperties(), handler); // When IEnumerable <SelectableHydraulicBoundaryLocation> availableHydraulicBoundaryLocations = properties.GetSelectableHydraulicBoundaryLocations(); SelectableHydraulicBoundaryLocation selectedLocation = properties.SelectedHydraulicBoundaryLocation; // Then SelectableHydraulicBoundaryLocation hydraulicBoundaryLocationItem = availableHydraulicBoundaryLocations.ToArray()[0]; Assert.AreEqual(selectedLocation.Distance, hydraulicBoundaryLocationItem.Distance, hydraulicBoundaryLocationItem.Distance.GetAccuracy()); mockRepository.VerifyAll(); }
public void SelectedHydraulicBoundaryLocation_InputWithLocationsStructure_CalculatesDistanceWithCorrectReferencePoint() { // Setup mockRepository.ReplayAll(); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 200643.312, 503347.25); var calculation = new StructuresCalculation <SimpleStructureInput> { InputParameters = { HydraulicBoundaryLocation = hydraulicBoundaryLocation, Structure = new TestStructure(new Point2D(200620.173572981, 503401.652985217)) } }; var inputContext = new SimpleInputContext(calculation.InputParameters, calculation, failureMechanism, assessmentSection); var properties = new SimpleStructuresInputProperties( inputContext, new StructuresInputBaseProperties <TestStructure, SimpleStructureInput, StructuresCalculation <SimpleStructureInput>, IFailureMechanism> .ConstructionProperties(), handler); // Call SelectableHydraulicBoundaryLocation selectedHydraulicBoundaryLocation = properties.SelectedHydraulicBoundaryLocation; // Assert double distanceToPropertiesStructureLocation = hydraulicBoundaryLocation.Location.GetEuclideanDistanceTo(properties.StructureLocation); double distanceToInputStructureLocation = hydraulicBoundaryLocation.Location.GetEuclideanDistanceTo(calculation.InputParameters.Structure.Location); Assert.AreEqual(59, distanceToPropertiesStructureLocation, 1); Assert.AreEqual(60, distanceToInputStructureLocation, 1); RoundedDouble selectedLocationDistance = selectedHydraulicBoundaryLocation.Distance; Assert.AreEqual(distanceToInputStructureLocation, selectedLocationDistance, selectedLocationDistance.GetAccuracy()); mockRepository.VerifyAll(); }
public ObjectPropertiesWithSelectableHydraulicBoundaryLocation(SelectableHydraulicBoundaryLocation selectedHydraulicBoundaryLocation, IEnumerable <SelectableHydraulicBoundaryLocation> selectableHydraulicBoundaryLocations) { SelectedHydraulicBoundaryLocation = selectedHydraulicBoundaryLocation; this.selectableHydraulicBoundaryLocations = selectableHydraulicBoundaryLocations; }