// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of Riskeer. // // Riskeer is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser 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; using System.Collections.Generic; using System.Linq; using Core.Common.Gui.Plugin; using NUnit.Framework; namespace Core.Common.Gui.TestUtil { /// /// Contains routines for testing classes which are related to GUI. /// public static class PluginTestHelper { /// /// Asserts that the given contains a definition for the combination of /// and . /// /// The collection of definitions. /// The type of the data object for which property info is defined. /// The type of the object which shows the data object properties. /// The found property info. /// Thrown when the is null /// or does not contain a definition for the combination of and /// . public static PropertyInfo AssertPropertyInfoDefined(IEnumerable propertyInfos, Type dataObjectType, Type propertyObjectType) { Assert.NotNull(propertyInfos, "The given collection of propertyInfos was undefined."); PropertyInfo propertyInfo = propertyInfos.FirstOrDefault( tni => tni.DataType == dataObjectType && tni.PropertyObjectType == propertyObjectType); Assert.NotNull(propertyInfo, $"The property info object was not found for the given dataType ({dataObjectType}) " + $"and propertyObjectType ({propertyObjectType})."); return propertyInfo; } /// /// Asserts that a view info is defined in the collection of view infos given. /// /// The collection of to search in. /// The type of the data which is passed to the . /// The type of the data which is set on the view. /// The type of the view. /// The that was found within the collection of . /// Thrown when either: /// /// is null; /// no can be found for the combination of and ; /// the found does not define the expected . /// /// public static ViewInfo AssertViewInfoDefined(IEnumerable viewInfos, Type dataType, Type viewDataType, Type viewType) { Assert.NotNull(viewInfos); ViewInfo viewInfo = viewInfos.SingleOrDefault(vi => vi.ViewDataType == viewDataType && vi.ViewType == viewType); Assert.NotNull(viewInfo, "Could not find viewInfo for the combination of viewDataType {0} and viewType {1} ", viewDataType, viewType); Assert.AreEqual(dataType, viewInfo.DataType); return viewInfo; } /// /// Asserts that a view info is defined in the collection of view infos given. /// /// The collection of to search in. /// The type of the data which is passed to the and is set on the view. /// The type of the view. /// The that was found within the collection of . /// Thrown when either: /// /// is null; /// no can be found for the combination of and . /// /// public static ViewInfo AssertViewInfoDefined(IEnumerable viewInfos, Type dataType, Type viewType) { return AssertViewInfoDefined(viewInfos, dataType, dataType, viewType); } } }