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


C# MockRepository.DynamicMock方法代码示例

本文整理汇总了C#中Rhino.Mocks.MockRepository.DynamicMock方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.DynamicMock方法的具体用法?C# MockRepository.DynamicMock怎么用?C# MockRepository.DynamicMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rhino.Mocks.MockRepository的用法示例。


在下文中一共展示了MockRepository.DynamicMock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Setup

 public void Setup()
 {
   _mocks = new MockRepository();
   _treeService = _mocks.DynamicMock<ITreeCreationService>();
   _naming = _mocks.DynamicMock<INamingService>();
   _mapper = new ViewSourceMapper(new NullLogger(), _treeService, _naming);
 }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:7,代码来源:ViewSourceMapperTests.cs

示例2: BeforeEachTest

 protected virtual void BeforeEachTest()
 {
     CreateMappings.Create();
     Mockery = new MockRepository();
     UnitOfWorkFactory = Mockery.DynamicMock<IUnitOfWorkFactory>();
     UnitOfWork = Mockery.DynamicMock<IUnitOfWork>();
 }
开发者ID:AndreyB1990,项目名称:Task1,代码行数:7,代码来源:ControllerFixtureBase.cs

示例3: RetrieveDenialsForDirectory_Root_Group

        public void RetrieveDenialsForDirectory_Root_Group()
        {
            MockRepository mocks = new MockRepository();
            ISettingsStorageProviderV30 prov = mocks.DynamicMock<ISettingsStorageProviderV30>();
            IFilesStorageProviderV30 filesProv = mocks.DynamicMock<IFilesStorageProviderV30>();
            IAclManager aclManager = mocks.DynamicMock<IAclManager>();

            Expect.Call(prov.AclManager).Return(aclManager).Repeat.Any();

            string dirName = Actions.ForDirectories.ResourceMasterPrefix + AuthTools.GetDirectoryName(filesProv, "/");
            Expect.Call(aclManager.RetrieveEntriesForSubject("G.Group")).Return(
                new AclEntry[] {
                    new AclEntry(dirName, Actions.ForDirectories.List, "G.Group", Value.Deny),
                    new AclEntry(dirName, Actions.FullControl, "G.Group", Value.Grant),
                    new AclEntry("D." + AuthTools.GetDirectoryName(filesProv, "/Other/"), Actions.ForDirectories.UploadFiles, "G.Group", Value.Deny)
                });

            mocks.Replay(prov);
            mocks.Replay(aclManager);

            Collectors.SettingsProvider = prov;

            string[] grants = AuthReader.RetrieveDenialsForDirectory(new UserGroup("Group", "Group", null),
                filesProv, "/");

            Assert.AreEqual(1, grants.Length, "Wrong denial count");
            Assert.AreEqual(Actions.ForDirectories.List, grants[0], "Wrong denial");
        }
开发者ID:mono,项目名称:ScrewTurnWiki,代码行数:28,代码来源:AuthReaderTests.cs

示例4: WillInitializeAllModuleLoadersOnStart

		public void WillInitializeAllModuleLoadersOnStart()
		{

			MockRepository mocks = new MockRepository();
			IModuleLoader mockLoader1 = mocks.DynamicMock<IModuleLoader>();
			IModuleLoader mockLoader2 = mocks.DynamicMock<IModuleLoader>();
			IModuleLoader mockLoader3 = mocks.DynamicMock<IModuleLoader>();
			IShellView stubShell = mocks.Stub<IShellView>();
			DefaultApplicationContext context = mocks.PartialMock<DefaultApplicationContext>(
				stubShell, new IModuleLoader[] { mockLoader1, mockLoader2, mockLoader3 });

			using (mocks.Record())
			{
				//we may have order dependnecies, let us verify
				//that it does this in order
				using (mocks.Ordered())
				{
					mockLoader1.Initialize(context, stubShell);
					mockLoader2.Initialize(context, stubShell);
					mockLoader3.Initialize(context, stubShell);
				}

				//force context to ignore these calls
				Expect.Call(context.GetShellAsForm()).Return(null).Repeat.Once();
				Expect.Call(delegate { context.RunForm(null); }).Repeat.Once();
			}

			using (mocks.Playback())
			{
				context.Start();
			}
		}
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:32,代码来源:ApplicationContextFixture.cs

示例5: CanRegisterConsumer

        public void CanRegisterConsumer()
        {
            var mockRepository = new MockRepository();
            var rabbitModel = mockRepository.DynamicMock<IModel>();
            var messageSerializer = mockRepository.DynamicMock<IMessageSerializer>();
            var registeredConsumer = mockRepository.DynamicMock<IRegisteredConsumer>();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();

            using (mockRepository.Record())
            {
                SetupResult.For(registeredConsumer.Queue).Return("q");

                Expect.Call(rabbitModel.BasicConsume(null, false, null))
                    .IgnoreArguments()
                    .WhenCalled(mi =>
                                    {
                                        Assert.Equal("q", mi.Arguments[0] as string);
                                        Assert.Equal(false, (bool)mi.Arguments[1]);
                                        Assert.IsType(typeof(QueueActivityConsumer), mi.Arguments[2]);
                                    }).Return("token");
            }

            using (mockRepository.Playback())
            {
                var callbackConsumer = new GroupedCallbackConsumer(rabbitModel, messageSerializer, config);
                callbackConsumer.ConsumeQueue(registeredConsumer);

                Assert.Equal(1, callbackConsumer.QueueConsumers.Count);
                Assert.Equal(1, callbackConsumer.QueueConsumers.Values.Count);
                Assert.Equal("token", callbackConsumer.QueueConsumers.Values.First().ConsumeToken.ConsumerTag);

                callbackConsumer.Close();
                callbackConsumer.Dispose();
            }
        }
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:35,代码来源:GroupedCallbackConsumerTests.cs

示例6: BuildAndExecuteRequest

        public void BuildAndExecuteRequest()
        {
            MockRepository mr = new MockRepository();

            IOAuthHelpers helpers = mr.DynamicMock<IOAuthHelpers>();
            IHttpImplemenation http = mr.DynamicMock<IHttpImplemenation>();

            DefaultOAuthRequestImplementation request = new DefaultOAuthRequestImplementation();
            request.SetHelperImplementation(helpers);
            request.SetHttpImplementaton(http);

            string testUrl = "TESTURL";
            var baseString = "BASESTRING";
            string consumerKey = "CONSUMER_KEY";
            string signature = "SIGNATURE";
            byte[] bytes = new byte[1] { (byte)1 };
            List<KeyValuePair<string, string>> args = new List<KeyValuePair<string, string>>();
            args.Add(new KeyValuePair<string, string>("key", "value"));

            using (mr.Record())
            {
                helpers.Expect(h => h.BuildBaseString("GET", testUrl, args)).Return(baseString);
                helpers.Expect(h => h.GetBytes(consumerKey)).Return(bytes);
                helpers.Expect(h => h.GetBytes(baseString)).Return(bytes);
                helpers.Expect(h => h.UrlEncode(String.Empty)).IgnoreArguments().Return(signature);
                http.Expect(x => x.CreateRequest("TESTURL?key=value&oauth_signature=SIGNATURE")).Return(null);
            }
            using (mr.Playback())
            {
                request.BuildAndExecuteRequest(testUrl, consumerKey, args);
            }
        }
开发者ID:thelvey,项目名称:StupidSimpleOAuth,代码行数:32,代码来源:Client.cs

示例7: GroupLayerCloneTest

        public void GroupLayerCloneTest()
        {
            var mocks = new MockRepository();
            var map = mocks.StrictMock<Map>();
            map.Expect(m => m.IsDisposing).Return(false).Repeat.Any();

            var layer1 = mocks.DynamicMock<ILayer>();
            var layer1Clone = mocks.DynamicMock<ILayer>();
            layer1.Expect(l => l.Clone()).Return(layer1Clone).Repeat.Once();

            mocks.ReplayAll();

            var originalGroupLayer = new GroupLayer("original");
            originalGroupLayer.Map = map;
            originalGroupLayer.Layers.AddRange(new[]{layer1});
            originalGroupLayer.HasReadOnlyLayersCollection = true;

            var clone = (GroupLayer) originalGroupLayer.Clone();

            Assert.AreEqual("original", clone.Name);
            Assert.IsNull(clone.Map);
            Assert.IsTrue(clone.HasReadOnlyLayersCollection);

            mocks.VerifyAll();
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:25,代码来源:GroupLayerTest.cs

示例8: AcksOnDelivery

        public void AcksOnDelivery()
        {
            var mockRepository = new MockRepository();
            var rabbitModel = mockRepository.DynamicMock<IModel>();
            var messageSerializer = mockRepository.DynamicMock<IMessageSerializer>();
            var registeredConsumer = mockRepository.DynamicMock<IRegisteredConsumer>();
            var properties = mockRepository.Stub<IBasicProperties>();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();

            using (mockRepository.Record())
            {
                SetupResult.For(registeredConsumer.MessageType).Return(typeof (TestMessage));
                SetupResult.For(registeredConsumer.Queue).Return("q");
                SetupResult.For(registeredConsumer.ConsumerType).Return(typeof (TestConsumer));
                SetupResult.For(messageSerializer.DeserializeMessage(null)).IgnoreArguments().Return(
                    mockRepository.Stub<IMessageEnvelope<TestMessage>>());
                SetupResult.For(config.PipelineEvents).Return(new PipelineEvents());
                Expect.Call(() => rabbitModel.BasicAck(1, false));
            }

            using (mockRepository.Playback())
            {
                var callbackConsumer = new GroupedCallbackConsumer(rabbitModel, messageSerializer, config);
                callbackConsumer.ConsumeQueue(registeredConsumer);
                callbackConsumer.QueueConsumers["q"].Consumer.HandleBasicDeliver("ct1", 1, false, "ex", typeof(TestMessage).ToRoutingKey(), properties, new byte[0]);

                callbackConsumer.Close();
                callbackConsumer.Dispose();
            }
        }
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:30,代码来源:GroupedCallbackConsumerTests.cs

示例9: ProcessEvents_LogFiles_CorrectNames

        public void ProcessEvents_LogFiles_CorrectNames()
        {
            MockRepository mocks = new MockRepository();

            IDnaDataReaderCreator dataReaderCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            IDnaHttpClientCreator httpClientCreator = mocks.DynamicMock<IDnaHttpClientCreator>();
            IDnaDataReader dataReader = mocks.Stub<IDnaDataReader>();

            dataReaderCreator.Stub(x => x.CreateDnaDataReader("getexmoderationevents")).Return(dataReader);
            dataReader.Stub(x => x.Execute()).Return(dataReader);
            dataReader.Stub(x => x.Read()).Return(true).Repeat.Times(1);
            dataReader.Stub(x => x.Read()).Return(false);
            dataReader.Stub(x => x.GetInt32NullAsZero("modid")).Return(0);
            dataReader.Stub(x => x.GetString("notes")).Return("");
            dataReader.Stub(x => x.GetString("uri")).Return("");
            dataReader.Stub(x => x.GetDateTime("datecompleted")).Return(DateTime.Now);
            dataReader.Stub(x => x.GetInt32NullAsZero("status")).Return(0);
            dataReader.Stub(x => x.GetString("callbackuri")).Return("");

            IDnaLogger logger = new DnaLogger();

            mocks.ReplayAll();

            ExModerationProcessor exModProcessor = new ExModerationProcessor(dataReaderCreator, logger, httpClientCreator);

            exModProcessor.ProcessEvents(null);
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:27,代码来源:ExModerationProcessorTests.cs

示例10: ClosesOpenConnectionOnDispose

        public void ClosesOpenConnectionOnDispose()
        {
            var mockRepository = new MockRepository();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();
            var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
            var conn = mockRepository.DynamicMock<IBrokerConnection>();
            var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();

            using (mockRepository.Record())
            {
                SetupResult.For(consumer.MessageType).Return(typeof (TestMessage));
                SetupResult.For(connFactory.CreateConnection()).Return(conn);
                SetupResult.For(config.ConnectionFactory).Return(connFactory);
                SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } });
                SetupResult.For(conn.IsOpen).Return(true);

                Expect.Call(conn.Close);
            }

            using (mockRepository.Playback())
            {
                var bus = new Bus(config);
                bus.GetLiveConnection();
                bus.Dispose();
            }
        }
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:26,代码来源:BusTests.cs

示例11: CanPublish

        public void CanPublish()
        {
            var mockRepository = new MockRepository();
            var config = mockRepository.DynamicMock<IBrokerConfiguration>();
            var connFactory = mockRepository.DynamicMock<IBrokerConnectionFactory>();
            var conn = mockRepository.DynamicMock<IBrokerConnection>();
            var consumer = mockRepository.DynamicMock<IRegisteredConsumer>();
            var message = new TestMessage();

            using (mockRepository.Record())
            {
                SetupResult.For(consumer.MessageType).Return(typeof(TestMessage));
                SetupResult.For(connFactory.CreateConnection()).Return(conn);
                SetupResult.For(config.Exchange).Return("ex");
                SetupResult.For(config.ConnectionFactory).Return(connFactory);
                SetupResult.For(config.RegisteredConsumers).Return(new Dictionary<Type, IList<IRegisteredConsumer>> { { typeof(TestMessage), new List<IRegisteredConsumer> { consumer } } }); ;
                SetupResult.For(conn.IsOpen).Return(true);

                Expect.Call(() => conn.Publish<TestMessage>(null))
                    .IgnoreArguments()
                    .WhenCalled(mi =>
                            {
                                var envelope = mi.Arguments[0];

                                Assert.IsAssignableFrom(typeof(IMessageEnvelope<TestMessage>), envelope);
                                Assert.Same(message, ((IMessageEnvelope<TestMessage>)envelope).Message);
                            });
            }

            using (mockRepository.Playback())
            {
                var bus = new Bus(config);
                bus.Publish(message);
            }
        }
开发者ID:nordbergm,项目名称:NSimpleBus,代码行数:35,代码来源:BusTests.cs

示例12: SubscribeToForum_SubscribeCanRead_ReturnsValidObject

        public void SubscribeToForum_SubscribeCanRead_ReturnsValidObject()
        {
            int canReadOut = 0;
            MockRepository mocks = new MockRepository();
            IDnaDataReader reader = mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.TryGetIntOutputParameter("CanRead", out canReadOut)).Return(true).OutRef(1);
            //reader.Stub(x => x.AddParameter("reviewforumid", id)).Return(reader).AssertWasNotCalled(y => y.Throw(new Exception("AddParameter(reviewforumid, id) not called")));

            IDnaDataReaderCreator creator = mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("getforumpermissions")).Return(reader);
            creator.Stub(x => x.CreateDnaDataReader("subscribetoforum")).Return(reader);
            mocks.ReplayAll();


            int userId = 1; 
            int forumId = 1; 
            bool unSubcribe = false; 
            SubscribeResult actual;
            actual = SubscribeResult.SubscribeToForum(creator, userId, forumId, unSubcribe);
            Assert.AreEqual(forumId, actual.ToForum);
            Assert.AreEqual(0, actual.Failed);
            
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:25,代码来源:SubscribeResultTest.cs

示例13: When_Capture_Then_Original_Filter_Is_Switched_And_PutBack

            public void When_Capture_Then_Original_Filter_Is_Switched_And_PutBack()
            {
                var mocks = new MockRepository();
                var context = mocks.DynamicMock<HttpContextBase>();
                var response = mocks.DynamicMock<HttpResponseBase>();
                var origFilter = mocks.DynamicMock<Stream>();

                var action = mocks.DynamicMock<Action>();

                using (mocks.Record())
                {
                    SetupResult.For(context.Response).Return(response);
                    SetupResult.For(response.ContentEncoding).Return(Encoding.ASCII);

                    Expect.Call(response.Filter).Return(origFilter);

                    response.Filter = null;
                    LastCall.IgnoreArguments().Constraints(Rhino.Mocks.Constraints.Is.TypeOf(typeof(CapturingResponseFilter)));

                    response.Filter = origFilter;
                }
                using (mocks.Playback())
                {
                    new BlockRenderer(context).Capture(action);
                }
            }
开发者ID:JonKruger,项目名称:MvcContrib,代码行数:26,代码来源:BlockRendererTester.cs

示例14: OnViewLoadedSetsCategorieIntheView

        public void OnViewLoadedSetsCategorieIntheView()
        {
            // Mock the View
            MockRepository mocks = new MockRepository();
            //Arrange
            var service = mocks.DynamicMock<ICategorieService>();

            //Act
            var controller = mocks.DynamicMock<ICategorieController>();

            // Create Presenter With Mock View and Dummy BlogService
            CategorieService serviceActual = new MockCategorieService();
            var controllerActual = new CategorieController(serviceActual,null,null);
            var presenter = new CategorieenPresenter(controllerActual);
            var cat = new BeheerContextEntity { DataKeyValue = "added" };
            IList<BeheerContextEntity> list= new List<BeheerContextEntity>();
            list.Add(cat);
            //controller.AddBusinessEntity(cat);

            // Set Expectations  
            controller.Expect(action=>action.AddBusinessEntity(cat));
            //presenter.Expect(action => action.OnViewLoaded());
            
            
            // Tell Rhino Mocks We're Done Setting Expectations
            mocks.ReplayAll();
            presenter.OnViewLoaded();
            
            mocks.VerifyAll();


        }
开发者ID:Letractively,项目名称:henoch,代码行数:32,代码来源:CategorieenPresenterFixture.cs

示例15: ExtraParams

 public void ExtraParams()
 {
     var mocks = new MockRepository();
     var parser = mocks.DynamicMock<ISolrQueryResultParser<TestDocument>>();
     var conn = mocks.DynamicMock<ISolrConnection>();
     var serializer = mocks.StrictMock<ISolrQuerySerializer>();
     With.Mocks(mocks)
         .Expecting(() => Expect.On(serializer)
                              .Call(serializer.Serialize(null))
                              .IgnoreArguments()
                              .Return("123123"))
         .Verify(() => {
             var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, serializer, null, null);
             var p = queryExecuter.GetAllParameters(new SolrQuery("123123"), new QueryOptions {
                 ExtraParams = new Dictionary<string, string> {
                     {"qt", "geo"},
                     {"lat", "40.75141843299745"},
                     {"long", "-74.0093994140625"},
                     {"radius", "1"},
                 }
             }).ToDictionary(x => x.Key, x => x.Value);
             Assert.AreEqual("123123", p["q"]);
             Assert.AreEqual("geo", p["qt"]);
             Assert.AreEqual("1", p["radius"]);
         });
 }
开发者ID:paulcarroll,项目名称:SolrNet,代码行数:26,代码来源:SolrQueryExecuterTests.cs


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