or
<
target
name
=
"Test"
description
=
"Test"
depends
=
"Build"
>
<
loadtasks
assembly
=
"C:\Program Files (x86)\Telerik\JustMock\Libraries\Telerik.JustMock.NAnt.dll"
/>
<
justmockstart
/>
<
nunit2
>
<
formatter
type
=
"Xml"
usefile
=
"true"
extension
=
".xml"
outputdir
=
"${build.dir}"
/>
<
test
assemblyname
=
"Tests/bin/release/Tests.dll"
appconfig
=
"Tests/bin/release/Tests.dll.config"
>
<
categories
>
<
exclude
name
=
"FIXME"
/>
</
categories
>
</
test
>
</
nunit2
>
<
justmockstop
/>
</
target
>
Assert.IsTrue(Mock.IsProfilerEnabled,
"Profile is enabled"
);
public
TResult CreateEmptyEntity<TResult>() where TResult : IBlockEntity
{
var result = DependencyInjector.InjectEntity<TResult>();
var setupEntity = (result
as
IBlockEntitySetup);
if
(setupEntity ==
null
)
{
throw
new
EntitySetupNotSupportedException(
"Entity type requested does not support construction through this method."
);
}
return
result = setupEntity.CreateEmptyEntity<TResult>();
}
[Test]
public
void
Test0010DependencyInjectionGetMethodCalledOnceWithCorrectType()
{
var mockedTower = Mock.Create<ITowerConfiguration>();
var mockedTowerSetup = mockedTower
as
IBlockEntitySetup;
Mock.Arrange(() => mockedTowerSetup.CreateEmptyEntity<ITowerConfiguration>()).DoNothing();
Mock.Arrange(() => InjectorMock.InjectEntity<ITowerConfiguration>()).Returns(mockedTowerSetup
as
ITowerConfiguration).OccursOnce();
Target.CreateEmptyEntity<ITowerConfiguration>();
Mock.Assert(Target);
}
public
class
TestCase1
{
static
TestCase1()
{
Mock.Replace<FileInfo,
bool
>(x => x.Exists).In<TestCase1>();
}
[Theory]
[InlineData(
false
)]
[InlineData(
true
)]
public
void
MockedFileExists(
bool
expected)
{
FileInfo file = Helper.GetMockedFile(expected);
bool
actual = file.Exists;
Assert.Equal(expected, actual);
}
}
public
class
TestCase2
{
static
TestCase2()
{
Mock.Replace<FileInfo,
bool
>(x => x.Exists).In<TestCase2>();
}
[Theory]
[InlineData(
false
)]
[InlineData(
true
)]
public
void
MockedFileExists(
bool
expected)
{
FileInfo file = Helper.GetMockedFile(expected);
bool
actual = file.Exists;
Assert.Equal(expected, actual);
}
}
public
class
Helper
{
public
static
FileInfo GetMockedFile(
bool
exists)
{
FileInfo file = Mock.Create<FileInfo>(
"c:\\test.jpg"
);
Mock.Arrange(() => file.Exists).Returns(exists);
return
file;
}
}
public
class
MockTest
{
[Fact]
public
void
ShouldThrowExceptionWhenImagesAreDifferentSizes()
{
Foo foo =
null
;
Mock.Arrange(() => foo.GetImageList()).Returns(
new
List<Bitmap> {
new
Bitmap(100, 100),
new
Bitmap(200, 200) });
Assert.Throws<ApplicationException>(() => foo =
new
Foo(
null
));
}
public
class
Foo
{
public
Foo(List<FileInfo> files)
{
this
.CheckImageDimensions();
}
public
void
CheckImageDimensions()
{
Bitmap firstImage =
this
.Images.FirstOrDefault();
Bitmap invalidImage =
this
.Images.Where(x => x.Width != firstImage.Width || x.Height != firstImage.Height).FirstOrDefault();
if
(invalidImage !=
null
)
throw
new
ApplicationException(
"Images with different dimensions are not supported."
);
}
private
List<Bitmap> _imageList;
public
List<Bitmap> Images
{
get
{
if
(
this
._imageList !=
null
)
return
this
._imageList;
this
._imageList =
this
.GetImageList();
return
this
._imageList;
}
}
public
List<Bitmap> GetImageList()
{
throw
new
NotImplementedException();
}
}
}
Mock.Arrange(() => foo.GetImageList()).Returns(
new
List<Bitmap> {
new
Bitmap(100, 100),
new
Bitmap(200, 200) });
Mock.Arrange(() => foo.Images).Returns(
new
List<Bitmap> {
new
Bitmap(100, 100),
new
Bitmap(200, 200) });
public
TResult CreateEmptyEntity<TResult>() where TResult : IBlockEntity
{
var result = DependencyInjector.Get<TResult>();
var setupEntity = (result
as
IBlockEntitySetup);
if
(setupEntity ==
null
)
{
throw
new
EntitySetupNotSupportedException(
"Entity type requested does not support construction through this method."
);
}
return
result = setupEntity.CreateEmptyEntity<TResult>();
}
[TestFixture]
public
class
ProtocolABlockTranslatorTestBase
{
protected
ProtocolABlockTranslator Target;
protected
IKernel KernelMock;
[SetUp]
public
void
BaseInitializer()
{
KernelMock =
new
StandardKernel();
Target = Mock.Create<ProtocolABlockTranslator>(Constructor.Mocked, Behavior.CallOriginal);
}
}
[TestFixture]
public
class
CreateEmptyEntityTests : ProtocolABlockTranslatorTestBase
{
[SetUp]
public
void
MyInitialization()
{
}
[Test]
public
void
Test0010DependencyInjectionGetMethodCalledOnceWithCorrectType()
{
KernelMock.Bind<ITowerConfiguration>().To<MockedTowerConfigSetup>();
Mock.Arrange(() => KernelMock.Get<ITowerConfiguration>()).OccursOnce();
Target.DependencyInjector = KernelMock;
Target.CreateEmptyEntity<ITowerConfiguration>();
Mock.Assert(KernelMock);
}
}
What I think is happening is that the Telerik.JustMock.Build.Workflow.dll Assembly now has a dependency on Microsoft.TeamFoundation.Build.Client Version 11.0.0.0 which is part of TFS 11 which I think still is in beta. We don’t have this version of the assembly so the build server fails instantly. Using Reflector I can see that the previous version of JM depended on Microsoft.TeamFoundation.Build.Client Version 10.0.0.0
Please look into this.
Thanks!
var view = Mock.Create<IView>();
Mock.ArrangeSet(() => view.MyEvent +=
null
).IgnoreArguments().OccursOnce();
var presenter = Mock.Create<Presenter>(view);
Mock.Assert(view);