What’s new:
var simple =
new
SimpleData();
Mock.Arrange(() => simple.Products).ReturnsCollection(GetFakeProducts());
Mock.Arrange(() => simple.Categories).ReturnsCollection(GetCategories());
var query = from product
in
simple.Products
join category
in
simple.Categories on product.CategoryId equals category.Id
select category.Id;
Assert.Equal(2, query.Count());
IFileReader fileReader = Mock.Create<IFileReader>();
const
string
expected = @
"c:\JustMock"
;
fileReader.Arrange(x => x.Path).Returns(expected).OccursOnce();
Assert.Equal(expected, fileReader.Path);
fileReader.Assert(x => x.Path);
What’s fixed:
[TestMethod]
public
void
ShouldBeAbleToSetExpectationsForPropertyFromTestClass()
{
this
.Foo = Mock.Create<IFoo>();
Mock.Arrange(() =>
this
.Foo.Echo(1)).Returns((
int
x) => x);
Assert.Equal(1,
this
.Foo.Echo(1));
}
public
interface
IFoo
{
[TestMethod]
public
void
ShouldBeAbleToSetExpectationsForPropertyFromTestClass()
{
this
.Foo = Mock.Create<IFoo>();
Mock.Arrange(() =>
this
.Foo.Echo(1)).Returns((
int
x) => x);
Assert.Equal(1,
this
.Foo.Echo(1));
}
public
interface
IFoo
{
int
Echo(
int
arg);
}
public
IFoo Foo {
get
;
set
; }
public
abstract
class
BaseProduct<T> where T : Product
{
public
T Clone()
{
return
default
(T);
}
}
public
class
ExtendedProduct : BaseProduct<Product>
{
}
[TestMethod]
public
void
ShouldBeAbleToMockMemberFromNonGenericTypeInheritingConstraintBaseType()
{
var businessObject = Mock.Create<ExtendedProduct>();
Mock.Arrange(() => businessObject.Clone()).MustBeCalled();
businessObject.Clone();
Mock.Assert(businessObject);
}
public
sealed
class
FooNonDefault
{
public
FooNonDefault(
int
arg1)
{
throw
new
ArgumentException(
"Must provide a valid argument"
);
}
}
[TestMethod]
public
void
ShouldExecuteOriginalConstructorIfMockFlagIsNotSpecified()
{
Assert.Throws<ArgumentException>(() => Mock.Create<FooNonDefault>(10));
}
public
class
Foo<TEntity>
{
public
virtual
TEntity GetByKey(
params
object
[] keyValues)
{
return
default
(TEntity);
}
}
[TestMethod]
public
void
ShouldAssetSetupWithValueTypeArgumentPassForParamsObjectArray()
{
var foo = Mock.Create<Foo<Product>>();
const
int
expected = 1;
Mock.Arrange(() => foo.GetByKey(expected)).Returns(() =>
null
).MustBeCalled();
foo.GetByKey(expected);
Mock.Assert(foo);
}
[TestMethod]
public
void
ShoudlAssertSetOnlyProperty()
{
var foo = Mock.Create<IFoo>();
foo.Track =
true
;
Mock.AssertSet(() => foo.Track =
true
);
}
public
interface
IFoo
{
bool
Track {
set
;}
}
private
ProjectNavigatorViewModel viewModel;
private
ISolutionService solutionService;
[TestInitialize]
public
void
Initialize()
{
this
.solutionService = Mock.Create<ISolutionService>();
this
.viewModel =
new
ProjectNavigatorViewModel(
this
.solutionService);
}
[TestMethod]
public
void
ShouldAssertMockRaiseFromInsideAContainer()
{
var foo = Mock.Create<IFoo>();
var projectEventArgs =
new
ProjectEventArgs(foo);
Mock.Raise(() =>
this
.solutionService.ProjectAdded +=
null
, projectEventArgs);
Assert.True(
this
.viewModel.IsProjectAddedCalled);
}
public
class
ProjectNavigatorViewModel
{
public
ProjectNavigatorViewModel(ISolutionService solutionService)
{
this
.SolutionService = solutionService;
SolutionService.ProjectAdded +=
new
EventHandler<ProjectEventArgs>(SolutionService_ProjectAdded);
}
void
SolutionService_ProjectAdded(
object
sender, ProjectEventArgs e)
{
IsProjectAddedCalled =
true
;
}
public
ISolutionService SolutionService {
get
;
set
; }
public
bool
IsProjectAddedCalled {
get
;
set
; }
}
public
class
ProjectEventArgs : EventArgs
{
private
IFoo foo;
public
ProjectEventArgs(IFoo foo)
{
this
.foo = foo;
}
}
public
interface
ISolutionService
{
event
EventHandler<ProjectEventArgs> ProjectAdded;
}
public
delegate
void
CustomEvent(
string
value);
public
delegate
void
EchoEvent(
bool
echoed);
And that sums it up. Stay tuned for the next build which will have several new features. Meanwhile you can always contact us through the support center and our forums.
Cheers and happy releasing!
The JustMock teamChris Eargle is a Microsoft C# MVP with over a decade of experience designing and developing enterprise applications, and he runs the local .NET User Group: the Columbia Enterprise Developers Guild. He is a frequent guest of conferences and community events promoting best practices and new technologies. Chris is a native Carolinian; his family settled the Dutch Form region of South Carolina in 1752. He currently resides in Columbia with his wife, Binyue, his dog, Laika, and his three cats: Meeko, Tigger, and Sookie. Amazingly, they all get along... except for Meeko, who is by no means meek.