当前位置: 首页>>代码示例>>C#>>正文


C# MockFactory.CreateMock方法代码示例

本文整理汇总了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();
        }
开发者ID:pweibel,项目名称:DotNetMockingFrameworksDemo,代码行数:26,代码来源:NMock3Test.cs

示例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 });
        }
开发者ID:nakaji,项目名称:EventSearch,代码行数:27,代码来源:AllEventCollectorTest.cs

示例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 };
        }
开发者ID:absurdhero,项目名称:tmotmo-full,代码行数:10,代码来源:TestSpriteCollection.cs

示例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();
        }
开发者ID:justin-lovell,项目名称:AiChallenge,代码行数:28,代码来源:OwnAntTrackingManagerFixture.cs

示例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();
        }
开发者ID:royosherove,项目名称:dotnetmocks2demo,代码行数:17,代码来源:7_LoginManagerTestsNMock3.cs

示例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();
        }
开发者ID:royosherove,项目名称:dotnetmocks2demo,代码行数:11,代码来源:7_LoginManagerTestsNMock3.cs

示例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);
        }
开发者ID:silverforge,项目名称:UnitTesting,代码行数:21,代码来源:BookShopServiceTest.cs

示例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();
        }
开发者ID:justin-lovell,项目名称:AiChallenge,代码行数:47,代码来源:GameManagerFixture.cs

示例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();
        }
开发者ID:justin-lovell,项目名称:AiChallenge,代码行数:18,代码来源:GameManagerFixture.cs

示例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();
        }
开发者ID:justin-lovell,项目名称:AiChallenge,代码行数:34,代码来源:OwnAntTrackingManagerFixture.cs

示例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();
        }
开发者ID:justin-lovell,项目名称:AiChallenge,代码行数:35,代码来源:OwnAntTrackingManagerFixture.cs

示例12: Before

 public void Before()
 {
     mockery = new MockFactory();
     auctionEventListener = mockery.CreateMock<IAuctionEventListener>();
     auctionMessageTranslator = new AuctionMessageTranslator(auctionEventListener.MockObject);
 }
开发者ID:JayBazuzi,项目名称:goos-dot-net,代码行数:6,代码来源:AuctionMessageTranslatorTest.cs

示例13: SetUp

 public void SetUp()
 {
     _mockFactory = new MockFactory();
     _mockInvocationHandler = _mockFactory.CreateMock<IInvocationHandler>();
     _module = new TestJavaScriptModule();
 }
开发者ID:chukcha-wtf,项目名称:react-native-windows,代码行数:6,代码来源:JavaScriptModuleBaseTests.cs

示例14: SetUp

 public void SetUp()
 {
     factory = new MockFactory();
     sprite = factory.CreateMock<Sprite>();
 }
开发者ID:absurdhero,项目名称:tmotmo-full,代码行数:5,代码来源:TestCycler.cs

示例15: SetUp

 public void SetUp()
 {
     factory = new MockFactory();
     sounds = factory.CreateMock<MockSounds>();
     tracker = new LoopTracker(sounds.MockObject);
 }
开发者ID:absurdhero,项目名称:tmotmo-full,代码行数:6,代码来源:TestLoopTracker.cs


注:本文中的MockFactory.CreateMock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。