|
From: <sm...@us...> - 2003-07-30 17:28:08
|
Update of /cvsroot/nmock/nmock/test/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv21832/test/NMock/Dynamic
Modified Files:
ClassGeneratorTest.cs
Log Message:
Some layout
Added tests to show limitations, e.g. DoesNotOverrideToString()
Index: ClassGeneratorTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/Dynamic/ClassGeneratorTest.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** ClassGeneratorTest.cs 30 Jul 2003 15:01:28 -0000 1.10
--- ClassGeneratorTest.cs 30 Jul 2003 17:28:01 -0000 1.11
***************
*** 10,14 ****
namespace NMock.Dynamic
{
!
public interface IThingy
{
--- 10,14 ----
namespace NMock.Dynamic
{
! #region types
public interface IThingy
{
***************
*** 40,44 ****
}
! public abstract class SolidThingy : ISolidThingy
{
// internal and protected internal methods must be overridable!
--- 40,44 ----
}
! public abstract class AbstractThingy : ISolidThingy
{
// internal and protected internal methods must be overridable!
***************
*** 72,75 ****
--- 72,80 ----
A, B, C, D
}
+ public class ConcreteThing
+ {
+ public virtual void NoArgs() { Assertion.Fail("Should have been overriden"); }
+ }
+ #endregion
[TestFixture] public class ClassGeneratorTest
***************
*** 257,264 ****
}
! [Test] public void ExtendClass()
{
cg = new ClassGenerator();
! SolidThingy s = (SolidThingy)cg.Generate(typeof(SolidThingy), mock);
mock.ExpectAndReturn("VirtualMethod", "hello");
--- 262,269 ----
}
! [Test] public void CanExtendAbstractClass()
{
cg = new ClassGenerator();
! AbstractThingy s = (AbstractThingy)cg.Generate(typeof(AbstractThingy), mock);
mock.ExpectAndReturn("VirtualMethod", "hello");
***************
*** 272,289 ****
Assertion.AssertEquals("white", s.ProtectedInternalMethod());
- Assertion.AssertEquals("xx", s.NonVirtualMethod());
- Assertion.AssertEquals("xx", s.NonVirtualProperty);
- Assertion.AssertEquals("xx", s.ToString());
mock.Verify();
}
- [Test] [ExpectedException(typeof(TypeLoadException))] public void CannotMockClassWithInternalMethodBecauseOfAssemblyVisibility()
- {
- new ClassGenerator().Generate(typeof(ClassWithInternalMethod), mock);
- }
-
[Test] public void CheckBoxingOpCodes()
{
! BoxingOpCodes opCodes = new BoxingOpCodes();
Assertion.AssertEquals( OpCodes.Ldind_I1, opCodes[typeof(sbyte)] );
--- 277,286 ----
Assertion.AssertEquals("white", s.ProtectedInternalMethod());
mock.Verify();
}
[Test] public void CheckBoxingOpCodes()
{
! BoxingOpCodes opCodes = new BoxingOpCodes();
Assertion.AssertEquals( OpCodes.Ldind_I1, opCodes[typeof(sbyte)] );
***************
*** 300,303 ****
--- 297,339 ----
Assertion.AssertEquals( OpCodes.Ldind_I1, opCodes[typeof(bool)] );
}
+ [Test] public void CanExtendConcreteClass()
+ {
+ ConcreteThing concrete = (ConcreteThing)(new ClassGenerator()).Generate(typeof(ConcreteThing), mock);
+
+ mock.Expect("NoArgs");
+ concrete.NoArgs();
+ mock.Verify();
+ }
+
+ // Limitations
+ [Test] public void CannotOverrideNonVirtualFeatures()
+ {
+ cg = new ClassGenerator();
+ AbstractThingy s = (AbstractThingy)cg.Generate(typeof(AbstractThingy), mock);
+
+ mock.SetupResult("NonVirtualMethod", "non virtual method");
+ mock.SetupResult("NonVirtualProperty", "non virtual property");
+
+ Assertion.AssertEquals("xx", s.NonVirtualMethod());
+ Assertion.AssertEquals("xx", s.NonVirtualProperty);
+ mock.Verify();
+ }
+
+ [Test] public void DoesNotOverrideToString()
+ {
+ cg = new ClassGenerator();
+ AbstractThingy s = (AbstractThingy)cg.Generate(typeof(AbstractThingy), mock);
+
+ mock.SetupResult("ToString", "to string");
+
+ Assertion.AssertEquals("xx", s.ToString());
+ mock.Verify();
+ }
+
+ [Test] [ExpectedException(typeof(TypeLoadException))] public void CannotMockClassWithInternalMethodBecauseOfAssemblyVisibility()
+ {
+ new ClassGenerator().Generate(typeof(ClassWithInternalMethod), mock);
+ }
+
}
|