When I test a method that uses Environment.GetFolderPath(...) I recieve a NullReferenceException with the following message:
TestCase 'SomeNamespace.UnitTests.SomeClassTest.SomeMethodTest' failed: System.NullReferenceException : Type must be declared abstract if any of its methods are abstract.
at System.Enum.GetTypeCode()
at System.Convert.GetTypeCode(Object value)
at System.Enum.ToUInt64(Object value)
at System.Enum.IsDefined(Type enumType, Object value)
at System.Environment.GetFolderPath(SpecialFolder folder)
at SomeNamespace.SomeClass.SomeMethod()
c:...SomeClassTest.cs(28,0): at SomeNamespace.UnitTests.SomeClassTest.SomeMethodTest()
The following code will reproduce the error:
Class
using System;
namespace SomeNamespace {
public class SomeClass {
public SomeClass() {
}
// This method will fail during a test since it
// calls Environment.GetFolderPath(...).
public void SomeMethod() {
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
}
}
}
TestClass
using NUnit.Framework;
using TypeMock;
namespace SomeNamespace.UnitTests {
[TestFixture()]
public class SomeClassTest {
private SomeClass someClass;
public SomeClassTest() {
}
[SetUp()]
public void Initialize() {
MockManager.Init();
someClass = new SomeClass();
}
[TearDown()]
public void Cleanup() {
MockManager.Verify();
}
[Test()]
public void SomeMethodTest() {
// This will fail because Environment.GetFolderPath(...)
// is called in SomeMethod.
someClass.SomeMethod();
}
}
}
I am using the following software:
- Windows 2003 Server
- Visual Studio .Net 2003
- TestDriven .Net 1.0.915
- NUnit 2.2
- TypeMock 2.2.2
Thanks,
Andy Blubaugh
PS
TypeMock is an absolutely phenomenal product! Keep up the good work!