or
Public
Sub
Execute_SimpleRequest_ReturnsTrue()
Dim
executor
As
New
DatabaseExecutor
executor.Connection =
New
Connection
Mock.Arrange(
Function
() executor.Connection.Open).Returns(
True
)
Assert.AreEqual(
True
, executor.Execute)
End
Sub
Hi,
I'm trying out the JustMock and getting it up and running on my local dev box (Windows 7 x64) with VS 2010 installed was no problem. However, I'm having problem getting the tests to run on our Windows 2003 build server where there's no VS installed.
I have added the <Import ...> and <JustMockStart> + <JustMockStop> in my build script, but it seems like the CLR profiler won't start when running on the build server. Am I missing something? Do I need to download and install CLR Profiler for .Net 2.0 (http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=a362781c-3870-43be-8926-862b40aa0cd0&displaylang=en) on the build server? Or is VS required?
- kjetil
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.JustMock;
using PatrickMocks;
namespace PatrickMocks
{
public class Mens
{
public int Leeftijd { get; set; }
public virtual bool IsElf()
{
// this.Foo();
return (this.Leeftijd == 11);
}
public virtual void Foo()
{
this.Leeftijd++;
this.Leeftijd--;
}
}
}
namespace MockTest
{
[TestClass()]
public class MensTest
{
[TestMethod()]
public void IsElfTest()
{
// Arrange
Mens mensMock = Mock.Create<PatrickMocks.Mens>();
//Mens mensMock = Mock.Create<PatrickMocks.Mens>(Behavior.CallOriginal); //<== THIS WORKS OK!!!
Mock.Arrange(() => mensMock.Foo()).CallOriginal().MustBeCalled();
// Act
bool expected = true; // TODO: Initialize to an appropriate value
bool actual = true;
mensMock.Leeftijd = 11;
actual = mensMock.IsElf();
// Assert
Assert.AreEqual(expected, actual);
Mock.Assert(mensMock); // Check dat deze method gedraaid heeft!
}
}
}
...
SPSecurity.RunWithElevatedPrivileges(
delegate
()
{
// Code to unit test
});
...
//Arrange
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting1.Name)).Returns(moduleSetting1.Value).MustBeCalled();
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting2.Name)).Returns(moduleSetting2.Value).MustBeCalled();
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting3.Name)).Returns(moduleSetting3.Value).MustBeCalled();
//Act
_presenter.Load();
//Assert
Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting1.Name), Occurs.Exactly(1));
Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting2.Name), Occurs.Exactly(1));
Mock.Assert(() => _mock.ThisIsAMethod(module, moduleSetting3.Name), Occurs.Exactly(1));
//Arrange
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting1.Name)).Returns(moduleSetting1.Value).MustBeCalled();
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting2.Name)).Returns(moduleSetting2.Value).MustBeCalled();
Mock.Arrange(() => _mock.ThisIsAMethod(module, moduleSetting3.Name)).Returns(moduleSetting3.Value).MustBeCalled();
//Act
_presenter.Load();
//Assert
Mock.Assert(() => _mock.ThisIsAMethod(module, Arg.AnyString), Occurs.Exactly(3));