// Copyright (C) Stichting Deltares 2016. 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.TreeView;
using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionInwards.Plugin;
using GrassCoverErosionInwardsFormsResources = Ringtoets.GrassCoverErosionInwards.Forms.Properties.Resources;
namespace Ringtoets.GrassCoverErosionInwards.Forms.Test.TreeNodeInfos
{
[TestFixture]
public class GrassCoverErosionInwardsCalculationContextTreeNodeInfoTest
{
private MockRepository mocksRepository;
private GrassCoverErosionInwardsGuiPlugin plugin;
private TreeNodeInfo info;
[SetUp]
public void SetUp()
{
mocksRepository = new MockRepository();
plugin = new GrassCoverErosionInwardsGuiPlugin();
info = plugin.GetTreeNodeInfos().First(tni => tni.TagType == typeof(GrassCoverErosionInwardsCalculationContext));
}
[Test]
public void Initialized_Always_ExpectedPropertiesSet()
{
// Assert
Assert.AreEqual(typeof(GrassCoverErosionInwardsCalculationContext), info.TagType);
Assert.IsNull(info.ForeColor);
Assert.IsNull(info.CanCheck);
Assert.IsNull(info.IsChecked);
Assert.IsNull(info.OnNodeChecked);
Assert.IsNull(info.CanDrop);
Assert.IsNull(info.CanInsert);
Assert.IsNull(info.OnDrop);
}
[Test]
public void Text_Always_ReturnsWrappedDataName()
{
// Setup
var testname = "testName";
var calculation = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput())
{
Name = testname
};
var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
var assessmentSectionMock = mocksRepository.StrictMock();
mocksRepository.ReplayAll();
var calculationContext = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock);
// Call
var text = info.Text(calculationContext);
// Assert
Assert.AreEqual(testname, text);
mocksRepository.VerifyAll();
}
[Test]
public void Image_Always_ReturnsPlaceHolderIcon()
{
// Call
var image = info.Image(null);
// Assert
TestHelper.AssertImagesAreEqual(GrassCoverErosionInwardsFormsResources.CalculationIcon, image);
}
[Test]
public void EnsureVisibleOnCreate_Always_ReturnsTrue()
{
// Setup
var calculation = new GrassCoverErosionInwardsCalculation(new GeneralGrassCoverErosionInwardsInput());
var failureMechanism = new GrassCoverErosionInwardsFailureMechanism();
var assessmentSectionMock = mocksRepository.StrictMock();
mocksRepository.ReplayAll();
var calculationContext = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock);
mocksRepository.ReplayAll();
// Call
var result = info.EnsureVisibleOnCreate(calculationContext);
// Assert
Assert.IsTrue(result);
mocksRepository.VerifyAll();
}
[Test]
public void ChildNodeObjects_WithOutputData_ReturnOutputChildNode()
{
var calculation = mocksRepository.StrictMock(new GeneralGrassCoverErosionInwardsInput());
var failureMechanism = mocksRepository.StrictMock();
var assessmentSectionMock = mocksRepository.StrictMock();
mocksRepository.ReplayAll();
var calculationContext = new GrassCoverErosionInwardsCalculationContext(calculation, failureMechanism, assessmentSectionMock);
// Call
var children = info.ChildNodeObjects(calculationContext).ToArray();
// Assert
Assert.AreEqual(3, children.Length);
var commentContext = children[0] as CommentContext;
Assert.IsNotNull(commentContext);
Assert.AreSame(calculationContext.WrappedData, commentContext.CommentContainer);
var grassCoverErosionInwardsCalculationContext = (GrassCoverErosionInwardsInputContext) children[1];
Assert.AreSame(calculationContext.WrappedData.InputParameters, grassCoverErosionInwardsCalculationContext.WrappedData);
var emptyOutput = (EmptyGrassCoverErosionInwardsOutput) children[2];
Assert.IsNotNull(emptyOutput);
}
}
}