or
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);
Url = UrlHelper.GenerateUrl(
null
, Action, Controller,
new
RouteValueDictionary(RouteValues), RouteTable.Routes, context.RequestContext,
true
);
var request = Mock.Create<HttpRequestBase>();
var httpContext = Mock.Create<HttpContextBase>();
Mock.Arrange(() => httpContext.Request).Returns(request);
var controllerContext =
new
ControllerContext(httpContext,
new
RouteData(),
new
TestDummyController());
Mock.SetupStatic<UrlHelper>(Behavior.CallOriginal);
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues)
at Symantec.Web.Mvc.JavaScriptRedirectResult.ExecuteResult(ControllerContext context)
in
D:\Code\_wsfederation\Applications\IdentityHub\Symantec.Web.Mvc\JavaScriptRedirectResult.cs:line 59
at Symantec.Web.Mvc.Tests.JavaScriptRedirectResultTest.ExecuteResult_Redirecs_To_Action()
in
D:\Code\_wsfederation\Applications\IdentityHub\Symantec.Web.Mvc.Tests\JavaScriptRedirectResultTest.cs:line 109
[Fact]
public
void
ArrangeDoesNotMatchArguments()
{
string
value1 =
"Hello"
;
string
value2 =
"World"
;
var session = Mock.Create<IMockable>();
Mock.Arrange(() => session.Get<
string
>(Arg.Matches<
string
[]>(v => v.Contains(
"Lol"
) &&
v.Contains(
"cakes"
))))
.Returns(
new
[]
{
value1,
value2,
});
var testValues =
new
[]
{
"Lol"
,
"cakes"
};
var result = session.Get<
string
>(testValues);
Assert.Contains(value1, result);
Assert.Contains(value2, result);
}
public
interface
IMockable
{
T[] Get<T>(
params
string
[] values);
}