Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17585/Spring/Spring.Core.Tests/Objects
Modified Files:
ObjectWrapperTestSuite.cs
Added Files:
ObjectUtilsTests.cs
Log Message:
Unit tests for the all of the new classes added in the previous commit.
--- NEW FILE: ObjectUtilsTests.cs ---
#region Licence
/*
* Copyright 2004 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using NUnit.Framework;
#endregion
namespace Spring.Objects
{
/// <summary>
/// Unit tests for the ObjectUtils class.
/// </summary>
/// <author>Rick Evans (.NET)</author>
/// <version>$Id: ObjectUtilsTests.cs,v 1.1 2004/07/26 07:42:53 springboy Exp $</version>
[TestFixture]
public class ObjectUtilsTests
{
[Test]
public void InstantiateType ()
{
object foo = ObjectUtils.InstantiateType (typeof (TestObject));
Assert.IsNotNull (foo, "Failed to instantiate an instance of a valid Type.");
Assert.IsTrue (foo is TestObject, "The instanintiared intance was an instance of the type that was passed in.");
}
[Test]
[ExpectedException (typeof (FatalObjectException))]
public void InstantiateTypeWithAbstractType ()
{
ObjectUtils.InstantiateType (typeof (AbstractType));
}
[Test]
[ExpectedException (typeof (FatalObjectException))]
public void InstantiateTypeWithInterfaceType ()
{
ObjectUtils.InstantiateType (typeof (System.Collections.IList));
}
[Test]
[ExpectedException (typeof (FatalObjectException))]
public void InstantiateTypeWithBadType ()
{
ObjectUtils.InstantiateType (typeof (NoZeroArgConstructorType));
}
[Test]
public void InstantiateByCtorWithNoArgs ()
{
Type type = typeof (TestObject);
ConstructorInfo ctor = type.GetConstructor (Type.EmptyTypes);
object foo = ObjectUtils.InstantiateType (ctor, new object [] {});
Assert.IsNotNull (foo, "Failed to instantiate an instance of a valid Type.");
Assert.IsTrue (foo is TestObject, "The instanintiared intance was an instance of the type that was passed in.");
}
[Test]
public void InstantiateByCtorArgs ()
{
Type type = typeof (TestObject);
ConstructorInfo ctor = type.GetConstructor (new Type [] {typeof (string), typeof (int)});
object foo = ObjectUtils.InstantiateType (ctor, new object [] {"Yakov Petrovich Golyadkin", 39});
Assert.IsNotNull (foo, "Failed to instantiate an instance of a valid Type.");
Assert.IsTrue (foo is TestObject, "The instanintiared intance was an instance of the type that was passed in.");
TestObject obj = foo as TestObject;
Assert.AreEqual ("Yakov Petrovich Golyadkin", obj.Name);
Assert.AreEqual (39, obj.Age);
}
[Test]
[ExpectedException (typeof (FatalObjectException))]
public void InstantiateByBadCtorArgs ()
{
Type type = typeof (TestObject);
ConstructorInfo ctor = type.GetConstructor (new Type [] {typeof (Missing), typeof (bool)});
object foo = ObjectUtils.InstantiateType (ctor, new object [] {"Yakov Petrovich Golyadkin", 39});
}
[Test]
public void IsSimpleProperty ()
{
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (string)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (long)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (bool)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (int)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (float)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (ushort)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (double)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (ulong)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (char)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (uint)));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (string [])));
Assert.IsTrue (ObjectUtils.IsSimpleProperty (typeof (Type)));
Assert.IsFalse (ObjectUtils.IsSimpleProperty (typeof (TestObject)));
Assert.IsFalse (ObjectUtils.IsSimpleProperty (typeof (System.Collections.IList [])));
}
/// <summary>
/// A class that doesn&t have a parameterless constructor.
/// </summary>
private class NoZeroArgConstructorType
{
/// <summary>
/// Creates a new instance of the NoZeroArgConstructorType class.
/// </summary>
/// <param name="foo">A spurious argument (ignored).</param>
public NoZeroArgConstructorType (string foo) {}
}
/// <summary>
/// An abstract class.
/// </summary>
private abstract class AbstractType
{
/// <summary>
/// Creates a new instance of the AbstractType class.
/// </summary>
public AbstractType () {}
}
}
}
Index: ObjectWrapperTestSuite.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Core.Tests/Objects/ObjectWrapperTestSuite.cs,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** ObjectWrapperTestSuite.cs 21 Jul 2004 03:37:18 -0000 1.18
--- ObjectWrapperTestSuite.cs 26 Jul 2004 07:42:53 -0000 1.19
***************
*** 193,197 ****
{
IObjectWrapper ow = new ObjectWrapper(t);
- Console.WriteLine(ow);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.AddPropertyValue(new PropertyValue("Age", (object) newAge));
--- 193,196 ----
|