The following test fails to run (if a line marked "Incorrectly Fails" is commented out the test will fails on the next line with such a mark):
// generic_class_mocking.h
#pragma once
using namespace System;
using namespace TypeMock;
using namespace MbUnit::Framework;
namespace generic_class_mocking {
public ref class A { };
generic<typename T>
public ref class Base
{
static T _sbt;
static property T sbt
{
T get() { return _sbt; }
void set(T t_) { _sbt = t_; }
}
T _bt;
property T bt
{
T get() { return _bt; }
void set(T t_) { _bt = t_; }
}
static A ^_sba;
static property A ^sba
{
A ^get() { return _sba; }
void set(A ^a_) { _sba = a_; }
}
A ^_ba;
property A ^ba
{
A ^get() { return _ba; }
void set(A ^a_) { _ba = a_; }
}
};
public ref class Derived : Base<A^>
{
static A ^_sda;
static property A ^sda
{
A ^get() { return _sda; }
void set(A ^a_) { _sda = a_; }
}
};
public ref class Derived2 : Base<Derived2^>
{
};
[TestFixture]
public ref class TestSuite
{
[Test]
void Test()
{
A ^a = gcnew A;
Mock ^mock = MockManager::MockAll(Derived::typeid);
mock->ExpectGetAlways("ba", a); //OK
mock->ExpectGetAlways("bt", a); //OK
mock->ExpectGetAlways("sda", a); //OK
mock->ExpectGetAlways("sba", a); //Incorrectly Fails: *** No method get_sba in type generic_class_mocking.Derived returns generic_class_mocking.A
mock->ExpectGetAlways("sbt", a); //Incorrectly Fails: *** No method get_sbt in type generic_class_mocking.Derived returns generic_class_mocking.A
Derived2 ^derived2 = gcnew Derived2;
Mock ^mock2 = MockManager::MockAll(Derived2::typeid);
mock2->ExpectGetAlways("sbt", derived2); //Incorrectly Fails: *** No method get_sbt in type generic_class_mocking.Derived2 returns generic_class_mocking.Derived2
}
};
}