Telerik JustMock
Here is an example of how to mock an abstract method with JustMock:
public
abstract
class
Shape
{
public
double
X {
get
;
set
; }
public
double
Y {
get
;
set
; }
public
abstract
double
CalculateArea();
}
...
[TestMethod]
public
void
MockAbstractMethod()
{
// Arrange
Shape shapeMock = Mock.Create<Shape>();
Mock.Arrange(() => shapeMock.CalculateArea()).Returns(42);
// Act
double
actualResult = shapeMock.CalculateArea();
// Assert
Assert.AreEqual(42, actualResult);
}
public
abstract
class
Shape
{
public
double
X {
get
;
set
; }
public
double
Y {
get
;
set
; }
public
virtual
double
CalculateArea()
{
return
X * Y;
}
}
...
[TestMethod]
public
void
MockAbstractMethod()
{
// Arrange
Shape shapeMock = Mock.Create<Shape>();
Mock.Arrange(() => shapeMock.CalculateArea()).Returns(42);
// Act
double
actualResult = shapeMock.CalculateArea();
// Assert
Assert.AreEqual(42, actualResult);
}
public
interface
IFoo
{
int
Value{
get
;
set
;}
}
...
[TestMethod]
public
void
ShouldFakePropertyGet()
{
// Arrange
var foo = Mock.Create<IFoo>();
Mock.Arrange(() => foo.Value).Returns(25);
// Act
var actual = foo.Value;
// Assert
Assert.AreEqual(25, actual);
}
[TestMethod]
public
void
ShouldAssertPropertySet()
{
// Arrange
var foo = Mock.Create<IFoo>();
Mock.ArrangeSet(() => foo.Value = 1);
// Act
foo.Value = 1;
// Assert
Mock.AssertSet(() => foo.Value = 1);
}