// 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 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 .
///
/// 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 defintion for the combination of and
/// .
public static PropertyInfo AssertPropertyInfoDefined(IEnumerable propertyInfos, Type dataObjectType, Type propertyObjectType)
{
Assert.NotNull(propertyInfos);
var propertyInfo = propertyInfos.FirstOrDefault(
tni =>
tni.DataType == dataObjectType &&
tni.PropertyObjectType == propertyObjectType);
Assert.NotNull(propertyInfo);
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 type
/// - the found does not define the expected or
///
///
public static ViewInfo AssertViewInfoDefined(IEnumerable viewInfos, Type dataType, Type viewDataType, Type viewType)
{
Assert.NotNull(viewInfos);
var viewInfo = viewInfos.SingleOrDefault(vi => vi.DataType == dataType);
Assert.NotNull(viewInfo, "Could not find viewInfo for the dataType {0}", dataType);
Assert.AreEqual(viewDataType, viewInfo.ViewDataType);
Assert.AreEqual(viewType, viewInfo.ViewType);
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 type
/// - the found does not define the expected
///
public static ViewInfo AssertViewInfoDefined(IEnumerable viewInfos, Type dataType, Type viewType)
{
return AssertViewInfoDefined(viewInfos, dataType, dataType, viewType);
}
}
}