// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System.Linq;
using Core.Common.Controls.Views;
using Core.Common.Gui.Plugin;
using Core.Common.TestUtil;
using NUnit.Framework;
using Ringtoets.ClosingStructures.Data;
using Ringtoets.ClosingStructures.Forms.PresentationObjects;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.Data.TestUtil.IllustrationPoints;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.Common.Forms.Views;
using Ringtoets.Common.Service.Test;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Forms.PresentationObjects;
using Ringtoets.Integration.Data;
using Ringtoets.StabilityPointStructures.Data;
using Ringtoets.StabilityPointStructures.Forms.PresentationObjects;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
namespace Ringtoets.Integration.Plugin.Test.ViewInfos
{
[TestFixture]
public class GeneralResultFaultTreeIllustrationPointViewInfoTest
{
private RingtoetsPlugin plugin;
private ViewInfo info;
[SetUp]
public void SetUp()
{
plugin = new RingtoetsPlugin();
info = plugin.GetViewInfos().First(tni => tni.ViewType == typeof(GeneralResultFaultTreeIllustrationPointView));
}
[TearDown]
public void TearDown()
{
plugin.Dispose();
}
[Test]
public void Initialized_Always_ExpectedPropertiesSet()
{
// Assert
Assert.AreEqual(typeof(StructuresOutputContext), info.DataType);
Assert.AreEqual(typeof(IStructuresCalculation), info.ViewDataType);
TestHelper.AssertImagesAreEqual(RingtoetsCommonFormsResources.GeneralOutputIcon, info.Image);
}
[Test]
public void GetViewName_Always_ReturnsCalculationOutputDisplayName()
{
// Call
string viewName = info.GetViewName(null, null);
// Assert
Assert.AreEqual("Resultaat", viewName);
}
[Test]
public void GetViewData_Always_ReturnsWrappedStructuresCalculation()
{
// Setup
var calculation = new TestStructuresCalculation();
var context = new StructuresOutputContext(calculation);
// Call
object viewData = info.GetViewData(context);
// Assert
Assert.AreSame(calculation, viewData);
}
public abstract class ShouldCloseGeneralResultFaultTreeIllustrationPointViewForStructuresTester : ShouldCloseViewWithCalculationDataTester
{
protected override bool PerformShouldCloseViewWithCalculationDataMethod(IView view, object o)
{
using (var plugin = new RingtoetsPlugin())
{
return plugin.GetViewInfos()
.First(tni => tni.ViewType == typeof(GeneralResultFaultTreeIllustrationPointView))
.CloseForData(view, o);
}
}
protected override IView GetView()
{
return new GeneralResultFaultTreeIllustrationPointView(() => new TestGeneralResultFaultTreeIllustrationPoint());
}
}
[TestFixture]
public class ShouldCloseGeneralResultFaultTreeIllustrationPointViewForHeightStructuresTester : ShouldCloseGeneralResultFaultTreeIllustrationPointViewForStructuresTester
{
protected override ICalculation GetCalculation()
{
return new StructuresCalculation();
}
protected override ICalculationContext GetCalculationContextWithCalculation()
{
return new HeightStructuresCalculationContext(
new StructuresCalculation(),
new HeightStructuresFailureMechanism(),
new AssessmentSection(AssessmentSectionComposition.Dike));
}
protected override ICalculationContext GetCalculationGroupContextWithCalculation()
{
return new HeightStructuresCalculationGroupContext(
new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
},
new HeightStructuresFailureMechanism(),
new AssessmentSection(AssessmentSectionComposition.Dike));
}
protected override IFailureMechanismContext GetFailureMechanismContextWithCalculation()
{
return new HeightStructuresFailureMechanismContext(
new HeightStructuresFailureMechanism
{
CalculationsGroup =
{
Children =
{
new StructuresCalculation()
}
}
},
new AssessmentSection(AssessmentSectionComposition.Dike));
}
}
[TestFixture]
public class ShouldCloseGeneralResultFaultTreeIllustrationPointViewForClosingStructuresTester : ShouldCloseGeneralResultFaultTreeIllustrationPointViewForStructuresTester
{
protected override ICalculation GetCalculation()
{
return new StructuresCalculation();
}
protected override ICalculationContext GetCalculationContextWithCalculation()
{
return new ClosingStructuresCalculationContext(
new StructuresCalculation(),
new ClosingStructuresFailureMechanism(),
new AssessmentSection(AssessmentSectionComposition.Dike));
}
protected override ICalculationContext GetCalculationGroupContextWithCalculation()
{
return new ClosingStructuresCalculationGroupContext(
new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
},
new ClosingStructuresFailureMechanism(),
new AssessmentSection(AssessmentSectionComposition.Dike));
}
protected override IFailureMechanismContext GetFailureMechanismContextWithCalculation()
{
return new ClosingStructuresFailureMechanismContext(
new ClosingStructuresFailureMechanism
{
CalculationsGroup =
{
Children =
{
new StructuresCalculation()
}
}
},
new AssessmentSection(AssessmentSectionComposition.Dike));
}
}
[TestFixture]
public class ShouldCloseGeneralResultFaultTreeIllustrationPointViewForStabilityPointStructuresTester : ShouldCloseGeneralResultFaultTreeIllustrationPointViewForStructuresTester
{
protected override ICalculation GetCalculation()
{
return new StructuresCalculation();
}
protected override ICalculationContext GetCalculationContextWithCalculation()
{
return new StabilityPointStructuresCalculationContext(
new StructuresCalculation(),
new StabilityPointStructuresFailureMechanism(),
new AssessmentSection(AssessmentSectionComposition.Dike));
}
protected override ICalculationContext GetCalculationGroupContextWithCalculation()
{
return new StabilityPointStructuresCalculationGroupContext(
new CalculationGroup
{
Children =
{
new StructuresCalculation()
}
},
new StabilityPointStructuresFailureMechanism(),
new AssessmentSection(AssessmentSectionComposition.Dike));
}
protected override IFailureMechanismContext GetFailureMechanismContextWithCalculation()
{
return new StabilityPointStructuresFailureMechanismContext(
new StabilityPointStructuresFailureMechanism
{
CalculationsGroup =
{
Children =
{
new StructuresCalculation()
}
}
},
new AssessmentSection(AssessmentSectionComposition.Dike));
}
}
}
}