using System; using System.Reflection; using Deltares.Geotechnics; using Deltares.Geotechnics.ConePenetrationTest; using Deltares.Standard.EventPublisher.Enum; using NUnit.Framework; namespace Deltares.DSoilModel.Forms.Tests { [TestFixture] class DSoilModelSelectionRedirectorTests { private DSoilModelSelectionRedirector redirector; private PropertyEditorReactionType reactionType = PropertyEditorReactionType.Ignore; [SetUp] public void SetUp() { redirector = new DSoilModelSelectionRedirector(); } [TearDown] public void TearDown() { redirector = null; } [Test] public void SupportedTypesTest() { Assert.AreEqual(4, redirector.RedirectingTypes.Length); Assert.Contains(typeof (ConePenetrationTestLookup1D), redirector.RedirectingTypes); Assert.Contains(typeof (ConePenetrationTestLookup2D), redirector.RedirectingTypes); Assert.Contains(typeof (BoringLookup1D), redirector.RedirectingTypes); Assert.Contains(typeof (BoringLookup2D), redirector.RedirectingTypes); } [Test] [TestCase(typeof(ConePenetrationTestLookup1D), "ConePenetrationTestData", typeof(ConePenetrationTestData))] [TestCase(typeof(ConePenetrationTestLookup2D), "ConePenetrationTestData", typeof(ConePenetrationTestData))] [TestCase(typeof(BoringLookup1D), "Boring", typeof(Boring))] [TestCase(typeof(BoringLookup2D), "Boring", typeof(Boring))] public void GetRedirectedObjectTest(Type inType, string propertyName, Type outType) { var inObject = Activator.CreateInstance(inType); var property = inObject.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public); property.SetValue(inObject, Activator.CreateInstance(property.PropertyType), null); var outObject = redirector.GetRedirectedObject(inObject, ref reactionType); Assert.IsNotNull(outObject); Assert.AreEqual(outType, outObject.GetType()); } [Test] public void GetRedirectedObjectTest_ReturnsInputObjectIfNotSupported() { var lookup = new SoilProfile1DLookup2D(); var outObject = redirector.GetRedirectedObject(lookup, ref reactionType); Assert.IsNotNull(outObject); Assert.AreSame(lookup, outObject); // the same object ? Assert.IsNull(redirector.GetRedirectedObject(null, ref reactionType)); } } }