本文整理汇总了C#中MockFactory.CreateMock方法的典型用法代码示例。如果您正苦于以下问题:C# MockFactory.CreateMock方法的具体用法?C# MockFactory.CreateMock怎么用?C# MockFactory.CreateMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockFactory
的用法示例。
在下文中一共展示了MockFactory.CreateMock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPersist
public void TestPersist()
{
MockFactory factory = new MockFactory();
//Create mocks
Mock<IUserGateway> mockGateway = factory.CreateMock<IUserGateway>();
Mock<IUserValidator> mockValidator = factory.CreateMock<IUserValidator>();
//Create user
User user = new User();
//Expectations
using(factory.Ordered)
{
mockValidator.Expects.One.MethodWith(m => m.Validate(user)).WillReturn(true);
mockGateway.Expects.One.MethodWith(m => m.Persist(user)).WillReturn(true);
}
//Assign gateway
user.Gateway = mockGateway.MockObject;
//Test method
Assert.AreEqual(true, user.Persist(mockValidator.MockObject));
factory.VerifyAllExpectationsHaveBeenMet();
}
示例2: SetUp
public void SetUp()
{
_factory = new MockFactory();
List<CommonEvent> mockResult;
var mock1 = _factory.CreateMock<BaseEventCollector>();
mockResult = new List<CommonEvent>();
mockResult.AddRange(new[]
{
new CommonEvent(0, "100", "Mock1Event1", new DateTime(2013,10,15), null, "", "", "", "", "", ""),
new CommonEvent(0, "100", "Mock1Event2", new DateTime(2013,10,1), null, "", "", "", "", "", ""),
});
mock1.Expects.One.MethodWith(x => x.GetEvents(201307, "松山")).WillReturn(mockResult);
var mock2 = _factory.CreateMock<BaseEventCollector>();
mockResult = new List<CommonEvent>();
mockResult.AddRange(new[]
{
new CommonEvent(0, "100", "Mock2Event1", new DateTime(2013,10,8), null, "", "", "", "", "", ""),
new CommonEvent(0, "100", "Mock2Event2", new DateTime(2013,10,30), null, "", "", "", "", "", ""),
new CommonEvent(0, "100", "Mock2Event3", new DateTime(2013,10,25), null, "", "", "", "", "", ""),
});
mock2.Expects.One.MethodWith(x => x.GetEvents(201307, "松山")).WillReturn(mockResult);
sut = new AllEventCollector(new[] { mock1.MockObject, mock2.MockObject });
}
示例3: SetUp
public void SetUp()
{
factory = new MockFactory();
camera = factory.CreateMock<Camera>();
sensor = factory.CreateMock<AbstractTouchSensor>();
sprite1 = factory.CreateMock<Sprite>();
sprite2 = factory.CreateMock<Sprite>();
sprites = new[] { sprite1.MockObject, sprite2.MockObject };
}
示例4: DoNotIssueMoveIntoWater
public void DoNotIssueMoveIntoWater()
{
var mock = new MockFactory();
var outputAdapterMock = mock.CreateMock<IGameOutputAdapter>();
using (mock.Ordered)
{
outputAdapterMock.Expects.One.MethodWith(adapter => adapter.NotifyEndOfTurn());
}
var trackerManager = new OwnAntTrackingManager(outputAdapterMock.MockObject);
MapTile origin = GameContext.Map.At(3, 4);
MapTile destination = origin.North;
var ant = new Ant(origin);
destination.State = TileState.Water;
origin.CurrentAnt = ant;
trackerManager.HasProcessedAllInputMoves();
trackerManager.EnrollToMove(ant, destination);
trackerManager.FinalizeAllMoves();
Assert.IsNotNull(origin.CurrentAnt);
Assert.AreEqual(ant, origin.CurrentAnt);
mock.VerifyAllExpectationsHaveBeenMet();
}
示例5: IsLoginOK_WhenLoggerThrows_CallsWebService
public void IsLoginOK_WhenLoggerThrows_CallsWebService()
{
var fac = new MockFactory();
var webservice = fac.CreateMock<IWebService>();
webservice.Expects.AtLeastOne.Method(_ => _.Write(null)).With(NMock.Is.StringContaining("s"));
var logger = fac.CreateMock<ILogger>();
logger.Stub.Out.Method(_ => _.Write(null))
.WithAnyArguments()
.Will(Throw.Exception(new Exception("dude this is fake")));
var lm =
new LoginManagerWithMockAndStub(logger.MockObject,webservice.MockObject);
lm.IsLoginOK("a", "b");
webservice.VerifyAllExpectations();
}
示例6: IsLoginOK_WhenCalled_WritesToLog
public void IsLoginOK_WhenCalled_WritesToLog()
{
var factory = new MockFactory();
Mock<ILogger> logger = factory.CreateMock<ILogger>();
logger.Expects.One.Method(_ => _.Write(null)).WithAnyArguments();
var lm = new LoginManagerWithMock(logger.MockObject);
lm.IsLoginOK("a", "b");
logger.VerifyAllExpectations();
}
示例7: BookShopServiceTest
public BookShopServiceTest()
{
DataPreparation();
var mockery = new MockFactory();
_bookRepositoryMock = mockery.CreateMock<IFileSystemStorage<Book>>();
_bookRepositoryMock.Expects.AtLeastOne
.Method(m => m.Save(null)).WithAnyArguments();
_bookRepositoryMock.Expects.AtLeastOne
.Method(m => m.List()).WithNoArguments().WillReturn(_bookList);
_customerRepositoryMock = mockery.CreateMock<IFileSystemStorage<Customer>>();
_customerRepositoryMock.Expects.AtLeastOne
.Method(m => m.Save(null)).WithAnyArguments();
_customerRepositoryMock.Expects.AtLeastOne
.Method(m => m.List()).WithNoArguments().WillReturn(_customerList);
_bookShopService = new BookShopService(_bookRepositoryMock.MockObject,
_customerRepositoryMock.MockObject);
}
示例8: EnsureThatEverythingIsTrackedCorrectly
public void EnsureThatEverythingIsTrackedCorrectly()
{
var mock = new MockFactory();
Mock<IGameOutputAdapter> outputAdapterMock = mock.CreateMock<IGameOutputAdapter>();
outputAdapterMock.Expects.AtLeastOne.MethodWith(x => x.NotifyReady());
outputAdapterMock.Expects.AtLeastOne.MethodWith(x => x.NotifyEndOfTurn());
var gameManager = new GameManager(outputAdapterMock.MockObject);
var inputInterpreter = new InputInterpreter(gameManager);
inputInterpreter.Interpret("turn 0");
inputInterpreter.Interpret("rows 10");
inputInterpreter.Interpret("cols 10");
inputInterpreter.Interpret("ready");
inputInterpreter.Interpret("turn 1");
inputInterpreter.Interpret("a 0 5 0");
inputInterpreter.Interpret("go");
Ant initAnt = (from row in Enumerable.Range(0, GameContext.Map.Rows)
from col in Enumerable.Range(0, GameContext.Map.Columns)
let tile = GameContext.Map.At(row, col)
where tile.CurrentAnt != null
select tile.CurrentAnt
).Single();
initAnt.MovementStrategy = new MoveDirection(initAnt, Direction.South);
for (int turn = 2; turn < 10; turn++)
{
var expectedRow = turn - 2;
var expectedColumn = initAnt.CurrentPosition.Column;
inputInterpreter.Interpret("turn " + turn);
inputInterpreter.Interpret(string.Format("a {0} {1} 0", expectedRow, expectedColumn));
outputAdapterMock.Expects.One
.MethodWith(adapter => adapter.MoveAnt(expectedRow, expectedColumn, Direction.South));
inputInterpreter.Interpret("go");
Assert.IsTrue(initAnt.MovementStrategy is MoveDirection);
}
mock.VerifyAllExpectationsHaveBeenMet();
}
示例9: EnsureMovesAreIssued
public void EnsureMovesAreIssued()
{
var mock = new MockFactory();
Mock<IGameOutputAdapter> outputAdapterMock = mock.CreateMock<IGameOutputAdapter>();
outputAdapterMock.Expects.One.MethodWith(x => x.NotifyReady());
outputAdapterMock.Expects.One.MethodWith(x => x.NotifyEndOfTurn());
var gameManager = new GameManager(outputAdapterMock.MockObject);
var turnResults = new TurnState();
turnResults.Ants.Add(new TurnState.Point(3, 3));
gameManager.RulesNotification(new GameRules {MapColumns = 10, MapRows = 10});
gameManager.DoMoves(turnResults);
mock.VerifyAllExpectationsHaveBeenMet();
}
示例10: TwoAntsCannotMoveIntoSameTile
public void TwoAntsCannotMoveIntoSameTile()
{
var mock = new MockFactory();
var outputAdapterMock = mock.CreateMock<IGameOutputAdapter>();
using (mock.Ordered)
{
outputAdapterMock.Expects.One
.Method(adapter => adapter.MoveAnt(0, 0, 0))
.WithAnyArguments();
outputAdapterMock.Expects.One.MethodWith(adapter => adapter.NotifyEndOfTurn());
}
var trackerManager = new OwnAntTrackingManager(outputAdapterMock.MockObject);
MapTile origin1 = GameContext.Map.At(3, 4);
MapTile destination = origin1.North;
MapTile origin2 = destination.North;
var ant1 = new Ant(origin1);
var ant2 = new Ant(origin2);
origin1.CurrentAnt = ant1;
origin2.CurrentAnt = ant2;
trackerManager.HasProcessedAllInputMoves();
trackerManager.EnrollToMove(ant1, destination);
trackerManager.EnrollToMove(ant2, destination);
trackerManager.FinalizeAllMoves();
trackerManager.AntHasMovedTo(destination.Row, destination.Column);
mock.VerifyAllExpectationsHaveBeenMet();
}
示例11: SimpleTrackingCase
public void SimpleTrackingCase()
{
var mock = new MockFactory();
var outputAdapterMock = mock.CreateMock<IGameOutputAdapter>();
using (mock.Ordered)
{
outputAdapterMock.Expects.One
.Method(adapter => adapter.MoveAnt(0, 0, 0))
.WithAnyArguments();
outputAdapterMock.Expects.One.MethodWith(adapter => adapter.NotifyEndOfTurn());
}
var trackerManager = new OwnAntTrackingManager(outputAdapterMock.MockObject);
MapTile origin = GameContext.Map.At(3, 4);
MapTile destination = origin.North;
var ant = new Ant(origin);
origin.CurrentAnt = ant;
trackerManager.HasProcessedAllInputMoves();
trackerManager.EnrollToMove(ant, destination);
trackerManager.FinalizeAllMoves();
Assert.IsNull(origin.CurrentAnt);
trackerManager.AntHasMovedTo(destination.Row, destination.Column);
Assert.IsNull(origin.CurrentAnt);
Assert.AreEqual(ant, destination.CurrentAnt);
mock.VerifyAllExpectationsHaveBeenMet();
}
示例12: Before
public void Before()
{
mockery = new MockFactory();
auctionEventListener = mockery.CreateMock<IAuctionEventListener>();
auctionMessageTranslator = new AuctionMessageTranslator(auctionEventListener.MockObject);
}
示例13: SetUp
public void SetUp()
{
_mockFactory = new MockFactory();
_mockInvocationHandler = _mockFactory.CreateMock<IInvocationHandler>();
_module = new TestJavaScriptModule();
}
示例14: SetUp
public void SetUp()
{
factory = new MockFactory();
sprite = factory.CreateMock<Sprite>();
}
示例15: SetUp
public void SetUp()
{
factory = new MockFactory();
sounds = factory.CreateMock<MockSounds>();
tracker = new LoopTracker(sounds.MockObject);
}