using System; using System.Linq; using Core.Common.Base.Plugin; using Core.Common.Controls.TreeView; using Core.Common.Gui; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Placeholder; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.Contribution; using Ringtoets.Integration.Data.Placeholders; using Ringtoets.Integration.Forms.PropertyClasses; namespace Ringtoets.Integration.Plugin.Test { [TestFixture] public class RingtoetsGuiPluginTest { [Test] [STAThread] // For creation of XAML UI component public void DefaultConstructor_ExpectedValues() { // call using (var ringtoetsGuiPlugin = new RingtoetsGuiPlugin()) { // assert Assert.IsInstanceOf(ringtoetsGuiPlugin); Assert.IsInstanceOf(ringtoetsGuiPlugin.RibbonCommandHandler); } } [Test] public void GetPropertyInfos_ReturnsSupportedPropertyClasses() { // setup using (var guiPlugin = new RingtoetsGuiPlugin()) { // call PropertyInfo[] propertyInfos = guiPlugin.GetPropertyInfos().ToArray(); // assert Assert.AreEqual(1, propertyInfos.Length); var assessmentSectionProperties = propertyInfos.Single(pi => pi.ObjectType == typeof(AssessmentSectionBase)); Assert.AreEqual(typeof(AssessmentSectionBaseProperties), assessmentSectionProperties.PropertyType); Assert.IsNull(assessmentSectionProperties.AdditionalDataCheck); Assert.IsNull(assessmentSectionProperties.GetObjectPropertiesData); Assert.IsNull(assessmentSectionProperties.AfterCreate); } } [Test] public void GetProjectTreeViewNodePresenters_ReturnsSupportedNodePresenters() { // setup var mocks = new MockRepository(); var applicationCore = new ApplicationCore(); var guiStub = mocks.DynamicMultiMock(typeof(IGui), typeof(IContextMenuBuilderProvider)); guiStub.Expect(g => g.ApplicationCore).Return(applicationCore).Repeat.Any(); mocks.ReplayAll(); using (var guiPlugin = new RingtoetsGuiPlugin { Gui = guiStub }) { // call TreeNodeInfo[] treeNodeInfos = guiPlugin.GetTreeNodeInfos().ToArray(); // assert Assert.AreEqual(5, treeNodeInfos.Length); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(AssessmentSectionBase))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(PlaceholderWithReadonlyName))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailureMechanismPlaceholder))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(CategoryTreeFolder))); Assert.IsTrue(treeNodeInfos.Any(tni => tni.TagType == typeof(FailureMechanismContribution))); } mocks.VerifyAll(); } [Test] public void GetChildDataWithViewDefinitions_AssessmentSectionBase_ReturnFailureMechanismContribution() { // Setup var mocks = new MockRepository(); var assessmentSectionBase = mocks.Stub(); mocks.ReplayAll(); var guiPlugin = new RingtoetsGuiPlugin(); // Call var childrenWithViewDefinitions = guiPlugin.GetChildDataWithViewDefinitions(assessmentSectionBase); // Assert CollectionAssert.AreEqual(new[] { assessmentSectionBase.FailureMechanismContribution }, childrenWithViewDefinitions); mocks.VerifyAll(); } [Test] public void GetChildDataWithViewDefinitions_UnsupportedData_ReturnEmpty() { // Setup var guiPlugin = new RingtoetsGuiPlugin(); // Call var childrenWithViewDefinitions = guiPlugin.GetChildDataWithViewDefinitions(1); // Assert CollectionAssert.IsEmpty(childrenWithViewDefinitions); } } }