public void GetAssessmentSectionAssemblyGroups_AssemblySucceeds_CorrectlySetsProperties()
        {
            // Setup
            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;

                // Call
                var properties = new AssessmentSectionAssemblyGroupsProperties(new AssessmentSection(AssessmentSectionComposition.Dike));

                // Assert
                AssessmentSectionAssemblyGroupProperties[]             assessmentSectionAssemblyGroups = properties.AssessmentSectionAssemblyGroups;
                IEnumerable <AssessmentSectionAssemblyGroupBoundaries> output = calculator.AssessmentSectionAssemblyGroupBoundariesOutput;
                Assert.AreEqual(output.Count(), assessmentSectionAssemblyGroups.Length);
                for (var i = 0; i < output.Count(); i++)
                {
                    AssessmentSectionAssemblyGroupBoundaries assemblyGroup = output.ElementAt(i);

                    AssessmentSectionAssemblyGroupProperties property = assessmentSectionAssemblyGroups[i];
                    Assert.AreEqual(assemblyGroup.AssessmentSectionAssemblyGroup, property.Group);
                    Assert.AreEqual(assemblyGroup.UpperBoundary, property.UpperBoundary);
                    Assert.AreEqual(assemblyGroup.LowerBoundary, property.LowerBoundary);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Creates a new instance of <see cref="TestAssemblyToolCalculatorFactory"/>.
 /// </summary>
 public TestAssemblyToolCalculatorFactory()
 {
     LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator       = new AssessmentSectionAssemblyGroupBoundariesCalculatorStub();
     LastCreatedFailureMechanismSectionAssemblyGroupBoundariesCalculator = new FailureMechanismSectionAssemblyGroupBoundariesCalculatorStub();
     LastCreatedFailureMechanismSectionAssemblyCalculator = new FailureMechanismSectionAssemblyCalculatorStub();
     LastCreatedFailureMechanismAssemblyCalculator        = new FailureMechanismAssemblyCalculatorStub();
     LastCreatedAssessmentSectionAssemblyCalculator       = new AssessmentSectionAssemblyCalculatorStub();
 }
        public void GetAssessmentSectionAssemblyGroups_AssemblyThrowsException_SetsEmptyProperties()
        {
            // Setup
            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;
                calculator.ThrowExceptionOnCalculate = true;

                // Call
                var properties = new AssessmentSectionAssemblyGroupsProperties(new AssessmentSection(AssessmentSectionComposition.Dike));

                // Assert
                Assert.IsEmpty(properties.AssessmentSectionAssemblyGroups);
            }
        }
        public void CreateAssessmentSectionAssemblyGroupBoundaries_CalculatorThrowsException_ThrowsAssemblyException()
        {
            // Setup
            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;
                calculator.ThrowExceptionOnCalculate = true;

                // Call
                void Call() => AssessmentSectionAssemblyGroupBoundariesFactory.CreateAssessmentSectionAssemblyGroupBoundaries(0, 0);

                // Assert
                var exception = Assert.Throws <AssemblyException>(Call);
                Assert.IsInstanceOf <AssessmentSectionAssemblyGroupBoundariesCalculatorException>(exception.InnerException);
                Assert.AreEqual(exception.InnerException.Message, exception.Message);
            }
        }
        public void GivenViewWithFailureMechanismContribution_WhenFailureMechanismContributionUpdated_ThenDataTableUpdated()
        {
            // Given
            var random = new Random(21);

            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

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

            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            failureMechanismContribution.Attach(observer);

            using (new AssemblyToolCalculatorFactoryConfig())
                using (var view = new AssessmentSectionAssemblyGroupsView(failureMechanismContribution))
                {
                    var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;

                    AssemblyGroupsTable <AssessmentSectionAssemblyGroup> groupsTable = GetCategoriesTable(view);

                    // Precondition
                    Assert.AreEqual(calculator.AssessmentSectionAssemblyGroupBoundariesOutput.Count(), groupsTable.Rows.Count);

                    // When
                    var newOutput = new[]
                    {
                        new AssessmentSectionAssemblyGroupBoundaries(random.NextDouble(),
                                                                     random.NextDouble(),
                                                                     random.NextEnumValue <AssessmentSectionAssemblyGroup>())
                    };
                    calculator.AssessmentSectionAssemblyGroupBoundariesOutput = newOutput;
                    failureMechanismContribution.NotifyObservers();

                    // Then
                    Assert.AreEqual(newOutput.Length, groupsTable.Rows.Count);
                }

            mocks.VerifyAll();
        }
        public void CreateAssessmentSectionAssemblyGroupBoundaries_WithInput_SetsInputOnCalculator()
        {
            // Setup
            var    random = new Random(11);
            double signalFloodingProbability           = random.NextDouble();
            double maximumAllowableFloodingProbability = random.NextDouble();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;

                // Call
                AssessmentSectionAssemblyGroupBoundariesFactory.CreateAssessmentSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability);

                // Assert
                Assert.AreEqual(signalFloodingProbability, calculator.SignalFloodingProbability);
                Assert.AreEqual(maximumAllowableFloodingProbability, calculator.MaximumAllowableFloodingProbability);
            }
        }
        public void CreateAssessmentSectionAssemblyGroupBoundaries_CalculatorRan_ReturnsOutput()
        {
            // Setup
            var    random = new Random(11);
            double signalFloodingProbability           = random.NextDouble();
            double maximumAllowableFloodingProbability = random.NextDouble();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;

                // Call
                AssessmentSectionAssemblyGroupBoundaries[] output = AssessmentSectionAssemblyGroupBoundariesFactory.CreateAssessmentSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability).ToArray();

                // Assert
                AssessmentSectionAssemblyGroupBoundaries[] calculatorOutput = calculator.AssessmentSectionAssemblyGroupBoundariesOutput.ToArray();

                Assert.AreEqual(calculatorOutput.Length, output.Length);
                CollectionAssert.AreEqual(calculatorOutput.Select(co => co.LowerBoundary), output.Select(o => o.LowerBoundary));
                CollectionAssert.AreEqual(calculatorOutput.Select(co => co.UpperBoundary), output.Select(o => o.UpperBoundary));
                CollectionAssert.AreEqual(calculatorOutput.Select(co => co.AssessmentSectionAssemblyGroup), output.Select(o => o.AssessmentSectionAssemblyGroup));
            }
        }
        public void Constructor_WithFailureMechanismContribution_CreatesViewAndTableWithData()
        {
            // Setup
            FailureMechanismContribution failureMechanismContribution = FailureMechanismContributionTestFactory.CreateFailureMechanismContribution();

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
                using (var view = new AssessmentSectionAssemblyGroupsView(failureMechanismContribution))
                {
                    // Assert
                    Assert.IsInstanceOf <UserControl>(view);
                    Assert.IsInstanceOf <IView>(view);
                    Assert.IsNull(view.Data);
                    Assert.AreEqual(1, view.Controls.Count);
                    Assert.AreSame(failureMechanismContribution, view.FailureMechanismContribution);

                    AssemblyGroupsTable <AssessmentSectionAssemblyGroup> tableControl = GetCategoriesTable(view);
                    Assert.AreEqual(DockStyle.Fill, tableControl.Dock);

                    var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                    AssessmentSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssessmentSectionAssemblyGroupBoundariesCalculator;
                    Assert.AreEqual(calculator.AssessmentSectionAssemblyGroupBoundariesOutput.Count(), tableControl.Rows.Count);
                }
        }