public void Constructor_WithValidParameters_FillsTableWithData() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); using (new AssemblyToolCalculatorFactoryConfig()) { // Call using (var view = new FailureMechanismSectionAssemblyGroupsView(assessmentSection)) { AssemblyGroupsTable <FailureMechanismSectionAssemblyGroup> assemblyGroupsTable = GetAssemblyGroupsTable(view); // Assert IEnumerable <FailureMechanismSectionAssemblyGroupBoundaries> expectedAssemblyGroupBoundaries = FailureMechanismSectionAssemblyGroupsHelper.GetFailureMechanismSectionAssemblyGroupBoundaries(assessmentSection); Assert.AreEqual(expectedAssemblyGroupBoundaries.Count(), assemblyGroupsTable.Rows.Count); for (int i = 0; i < expectedAssemblyGroupBoundaries.Count(); i++) { FailureMechanismSectionAssemblyGroupBoundaries expectedBoundary = expectedAssemblyGroupBoundaries.ElementAt(i); var actualBoundary = (AssemblyGroupRow <FailureMechanismSectionAssemblyGroup>)assemblyGroupsTable.Rows[i].DataBoundItem; Assert.AreEqual(expectedBoundary.FailureMechanismSectionAssemblyGroup, actualBoundary.Group); Assert.AreEqual(expectedBoundary.LowerBoundary, actualBoundary.LowerBoundary); Assert.AreEqual(expectedBoundary.UpperBoundary, actualBoundary.UpperBoundary); } } } }
public void GetFailureMechanismAssemblyGroups_AssemblySucceeds_CorrectlySetsProperties() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); using (new AssemblyToolCalculatorFactoryConfig()) { // Call var properties = new FailureMechanismSectionAssemblyGroupsProperties(assessmentSection); // Assert FailureMechanismSectionAssemblyGroupProperties[] failureMechanismAssemblyGroups = properties.FailureMechanismAssemblyGroups; IEnumerable <FailureMechanismSectionAssemblyGroupBoundaries> output = FailureMechanismSectionAssemblyGroupsHelper.GetFailureMechanismSectionAssemblyGroupBoundaries(assessmentSection); Assert.AreEqual(output.Count(), failureMechanismAssemblyGroups.Length); for (var i = 0; i < output.Count(); i++) { FailureMechanismSectionAssemblyGroupBoundaries assemblyGroupBoundaries = output.ElementAt(i); FailureMechanismSectionAssemblyGroupProperties property = failureMechanismAssemblyGroups[i]; Assert.AreEqual(assemblyGroupBoundaries.FailureMechanismSectionAssemblyGroup, property.Group); Assert.AreEqual(assemblyGroupBoundaries.UpperBoundary, property.UpperBoundary); Assert.AreEqual(assemblyGroupBoundaries.LowerBoundary, property.LowerBoundary); } } }
public void GetFailureMechanismSectionAssemblyGroupBoundaries_AssessmentSectionNull_ThrowsArgumentNullException() { // Call void Call() => FailureMechanismSectionAssemblyGroupsHelper.GetFailureMechanismSectionAssemblyGroupBoundaries(null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("assessmentSection", exception.ParamName); }
private void UpdateTableData() { Tuple <AssemblyGroupBoundaries, Color, FailureMechanismSectionAssemblyGroup>[] dataToSet = FailureMechanismSectionAssemblyGroupsHelper.GetFailureMechanismSectionAssemblyGroupBoundaries(AssessmentSection).Select( assemblyGroupBoundaries => new Tuple <AssemblyGroupBoundaries, Color, FailureMechanismSectionAssemblyGroup>( assemblyGroupBoundaries, FailureMechanismSectionAssemblyGroupColorHelper.GetFailureMechanismSectionAssemblyGroupColor(assemblyGroupBoundaries.FailureMechanismSectionAssemblyGroup), assemblyGroupBoundaries.FailureMechanismSectionAssemblyGroup)).ToArray(); assemblyGroupsTable.SetData(dataToSet); }
public void CreateAssemblyGroupsView_CalculatorThrowsException_ReturnsEmptyCollectionOfAssemblyGroupBoundaries() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyGroupBoundariesCalculator; calculator.ThrowExceptionOnCalculate = true; // Call IEnumerable <FailureMechanismSectionAssemblyGroupBoundaries> assemblyGroupBoundaries = FailureMechanismSectionAssemblyGroupsHelper.GetFailureMechanismSectionAssemblyGroupBoundaries(assessmentSection); // Assert Assert.IsEmpty(assemblyGroupBoundaries); } }
public void GetFailureMechanismSectionAssemblyGroupBoundaries_CalculationSuccessful_ReturnsCorrectAssemblyGroupBoundaries() { // Setup var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyGroupBoundariesCalculator; // Call FailureMechanismSectionAssemblyGroupBoundaries[] assemblyGroupBoundaries = FailureMechanismSectionAssemblyGroupsHelper.GetFailureMechanismSectionAssemblyGroupBoundaries(assessmentSection).ToArray(); // Assert Assert.AreEqual(calculator.FailureMechanismSectionAssemblyGroupBoundariesOutput.Count() + 3, assemblyGroupBoundaries.Length); for (var i = 0; i < calculator.FailureMechanismSectionAssemblyGroupBoundariesOutput.Count(); i++) { FailureMechanismSectionAssemblyGroupBoundaries expectedBoundary = calculator.FailureMechanismSectionAssemblyGroupBoundariesOutput.ElementAt(i); FailureMechanismSectionAssemblyGroupBoundaries actualBoundary = assemblyGroupBoundaries[i]; Assert.AreEqual(expectedBoundary.FailureMechanismSectionAssemblyGroup, actualBoundary.FailureMechanismSectionAssemblyGroup); Assert.AreEqual(expectedBoundary.LowerBoundary, actualBoundary.LowerBoundary); Assert.AreEqual(expectedBoundary.UpperBoundary, actualBoundary.UpperBoundary); } FailureMechanismSectionAssemblyGroupBoundaries dominantGroupBoundaries = assemblyGroupBoundaries[assemblyGroupBoundaries.Length - 3]; Assert.AreEqual(FailureMechanismSectionAssemblyGroup.Dominant, dominantGroupBoundaries.FailureMechanismSectionAssemblyGroup); Assert.AreEqual(double.NaN, dominantGroupBoundaries.UpperBoundary); Assert.AreEqual(double.NaN, dominantGroupBoundaries.LowerBoundary); FailureMechanismSectionAssemblyGroupBoundaries notDominantGroupBoundaries = assemblyGroupBoundaries[assemblyGroupBoundaries.Length - 2]; Assert.AreEqual(FailureMechanismSectionAssemblyGroup.NotDominant, notDominantGroupBoundaries.FailureMechanismSectionAssemblyGroup); Assert.AreEqual(double.NaN, notDominantGroupBoundaries.UpperBoundary); Assert.AreEqual(double.NaN, notDominantGroupBoundaries.LowerBoundary); FailureMechanismSectionAssemblyGroupBoundaries notRelevantGroupBoundaries = assemblyGroupBoundaries[assemblyGroupBoundaries.Length - 1]; Assert.AreEqual(FailureMechanismSectionAssemblyGroup.NotRelevant, notRelevantGroupBoundaries.FailureMechanismSectionAssemblyGroup); Assert.AreEqual(double.NaN, notRelevantGroupBoundaries.UpperBoundary); Assert.AreEqual(double.NaN, notRelevantGroupBoundaries.LowerBoundary); } }
public void GivenViewWithValidData_WhenFailureMechanismContributionUpdated_ThenDataTableUpdated() { // Given var random = new Random(); var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyGroupBoundariesCalculator; var output = new List <FailureMechanismSectionAssemblyGroupBoundaries> { CreateFailureMechanismSectionAssemblyGroupBoundaries(random) }; calculator.FailureMechanismSectionAssemblyGroupBoundariesOutput = output; using (var view = new FailureMechanismSectionAssemblyGroupsView(assessmentSection)) { AssemblyGroupsTable <FailureMechanismSectionAssemblyGroup> failureMechanismSectionGroupsTable = GetAssemblyGroupsTable(view); // Precondition int expectedNrOfDefaultGroupBoundaries = FailureMechanismSectionAssemblyGroupsHelper.GetFailureMechanismSectionAssemblyGroupBoundaries(assessmentSection).Count(); Assert.AreEqual(expectedNrOfDefaultGroupBoundaries, failureMechanismSectionGroupsTable.Rows.Count); int newNrOfGroupBoundaries = random.Next(1, 10); for (var i = 1; i <= newNrOfGroupBoundaries; i++) { output.Add(CreateFailureMechanismSectionAssemblyGroupBoundaries(random)); } // When assessmentSection.FailureMechanismContribution.NotifyObservers(); // Then Assert.AreEqual(expectedNrOfDefaultGroupBoundaries + newNrOfGroupBoundaries, failureMechanismSectionGroupsTable.Rows.Count); } } }
private FailureMechanismSectionAssemblyGroupProperties[] GetFailureMechanismAssemblyGroups() { return(FailureMechanismSectionAssemblyGroupsHelper.GetFailureMechanismSectionAssemblyGroupBoundaries(data) .Select(assemblyGroupBoundaries => new FailureMechanismSectionAssemblyGroupProperties(assemblyGroupBoundaries)) .ToArray()); }