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


C# MockRepository.StrictMock方法代码示例

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


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

示例1: ShouldVerify_IsNotFriendly

        public void ShouldVerify_IsNotFriendly()
        {
            var mocks = new MockRepository();

            var context = mocks.DynamicMock<HttpContextBase>();
            SetupResult.For(context.Request).Return(MockedRequest(mocks));

            var response = mocks.StrictMock<HttpResponseBase>();
            SetupResult.For(response.StatusCode).PropertyBehavior();
            SetupResult.For(context.Response).Return(response);

            var whoisService = mocks.StrictMock<IWhois>();

            Expect.Call(whoisService.WhoisEnhancedXml(null, null, null)).IgnoreArguments().Return(new WhoisEnhancedRecord {IsFriendly = false});

            mocks.ReplayAll();

            var controller = new ContactController(whoisService, null);
            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);
            var result = controller.IsFriendly() as ContentResult;

            Assert.IsNotNull(result);
            Assert.AreNotEqual(MyWebPresence.EmailAccount, result.Content);
            Assert.IsTrue(controller.Response.StatusCode == (int) HttpStatusCode.BadRequest);

            mocks.VerifyAll();
        }
开发者ID:AdamDotCom,项目名称:adamdotcom-website,代码行数:27,代码来源:ContactControllerTests.cs

示例2: Creates_database

		public void Creates_database()
		{
			var settings = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts");
            taskAttributes.RequestedDatabaseAction= RequestedDatabaseAction.Create;
			var mocks = new MockRepository();
            var queryExecutor = mocks.StrictMock<IQueryExecutor>();
            var executor = mocks.StrictMock<IScriptFolderExecutor>();
            var taskObserver = mocks.StrictMock<ITaskObserver>();
			
			using (mocks.Record())
			{
				queryExecutor.ExecuteNonQuery(settings, "create database [db]");
                taskObserver.Log(string.Format("Run scripts in Create folder."));
				executor.ExecuteScriptsInFolder(taskAttributes, "Create", taskObserver);
			}

			using (mocks.Playback())
			{
				IDatabaseActionExecutor creator = new DatabaseCreator(queryExecutor, executor);
				creator.Execute(taskAttributes, taskObserver);
			}

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

示例3: Do3Fluent

        public void Do3Fluent()
        {
            var mockRepository = new MockRepository();
            var view = mockRepository.StrictMock<IButtonView>();
            var model = mockRepository.StrictMock<IToggleModel>();

            var presenter = new ButtonPresenter(model);
            presenter.ConnectView(view);

            //IEventRaiser clicked = null;
            //view.Clicked += null;
            //clicked = LastCall.GetEventRaiser();

            IEventSubscriber subscriber = mockRepository.StrictMock<IEventSubscriber>();
            IWithEvents events = new WithEvents();
            // This doesn't create an expectation because no method is called on subscriber!!
            events.Blah += subscriber.Handler;
            subscriber.Handler(VisibilityState.Visible);

            With.Mocks(mockRepository)
                .Expecting(delegate
                           	{
                           		Expect.Call(model.ToggleVisibility);
                           		Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments();
                           		Expect.Call(() => view.SetCheckedState(CheckedState.Checked));
                           	})
                .Verify(delegate
                            {
                                events.RaiseEvent(VisibilityState.Visible);
                                //clicked.Raise();
                            });
        }
开发者ID:baens,项目名称:Esri2011,代码行数:32,代码来源:ButtonPresenterFixture.cs

示例4: BidirectionalConverter_Should_Convert_All_Items

        public void BidirectionalConverter_Should_Convert_All_Items()
        {
            var mocks = new MockRepository();
            var converter1 = mocks.StrictMock<IBidirectionalConverter<int, string>>();

            Expect.Call(converter1.Convert(5)).Return("5");
            Expect.Call(converter1.Convert(3)).Return("3");
            Expect.Call(converter1.Convert(7)).Return("7");

            var converter2 = mocks.StrictMock<IBidirectionalConverter<string, int>>();

            Expect.Call(converter2.Convert("5")).Return(5);
            Expect.Call(converter2.Convert("3")).Return(3);
            Expect.Call(converter2.Convert("7")).Return(7);

            mocks.ReplayAll();

            // Convert one way
            IList<int> input1 = new List<int> { 5, 3, 7 };
            var output1 = converter1.ConvertAll(input1);

            Assert.IsTrue(output1.Contains("5"));
            Assert.IsTrue(output1.Contains("3"));
            Assert.IsTrue(output1.Contains("7"));

            // Convert the other way
            IList<string> input2 = new List<string> { "5", "3", "7" };
            var output2 = converter2.ConvertAll(input2);

            Assert.IsTrue(output2.Contains(5));
            Assert.IsTrue(output2.Contains(3));
            Assert.IsTrue(output2.Contains(7));

            mocks.VerifyAll();
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:35,代码来源:ConvertAll.cs

示例5: SetUp

 public void SetUp()
 {
     _mockRepository = new MockRepository();
     _accountRepository = _mockRepository.StrictMock<IAccountRepository>();
     _transactionsRepository = _mockRepository.StrictMock<ITransactionsRepository>();
     _paymentGateway = _mockRepository.StrictMock<IPaymentGateway>();
 }
开发者ID:olcayseker,项目名称:Logging-Interception-demo,代码行数:7,代码来源:ProcessTransactionServiceTests.cs

示例6: PublishDomainEvents

        public void PublishDomainEvents()
        {
            var e = new TestEvent();

            var mockRepository = new MockRepository();
            IEnumerable<object> handlers;

            using (mockRepository.Record())
            {
                var handler1 = mockRepository.StrictMock<IEventHandler<TestEvent>>();
                handler1.Expect(h => h.Handle(e)).Repeat.Once();

                var handler2 = mockRepository.StrictMock<IEventHandler<TestEvent>>();
                handler2.Expect(h => h.Handle(e)).Repeat.Once();

                handlers = new[] { handler1, handler2 };
            }

            MultiInstanceFactory multiInstanceFactory = t => handlers;

            var publisher = new DomainEventsPublisher(multiInstanceFactory);
            DomainEvents.Raise(e);

            using (mockRepository.Playback())
                publisher.Publish();

            mockRepository.VerifyAll();
        }
开发者ID:jasondentler,项目名称:RockPaperScissors,代码行数:28,代码来源:DomainEventsPublisherShould.cs

示例7: Updates_database

        public void Updates_database()
        {
            var settings = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, "c:\\scripts");
            taskAttributes.RequestedDatabaseAction = RequestedDatabaseAction.Update;
            var mocks = new MockRepository();
            var scriptfolderexecutor = mocks.StrictMock<IScriptFolderExecutor>();
            var queryexecutor = mocks.StrictMock<IQueryExecutor>();
            queryexecutor.Stub(x => x.CheckDatabaseExists(taskAttributes.ConnectionSettings)).Return(true);

            var taskObserver = mocks.StrictMock<ITaskObserver>();
            using (mocks.Record())
            {
                taskObserver.Log(string.Format("Run scripts in Update folder."));
                scriptfolderexecutor.ExecuteScriptsInFolder(taskAttributes, "Update", taskObserver);

                taskObserver.Log(string.Format("Run scripts in Everytime folder."));
                scriptfolderexecutor.ExecuteChangedScriptsInFolder(taskAttributes, "Everytime", taskObserver);

                taskObserver.Log(string.Format("Run scripts in RunAlways folder."));
                scriptfolderexecutor.ExecuteRunAlwaysScriptsInFolder(taskAttributes, "RunAlways", taskObserver);
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor updater = new DatabaseUpdater(scriptfolderexecutor, queryexecutor);
                updater.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
开发者ID:mpobudejski,项目名称:AliaSQL,代码行数:31,代码来源:DatabaseUpdaterTester.cs

示例8: TestRefreshAmount

        public void TestRefreshAmount()
        {
            var mock = new MockRepository();
              var getAmountEventReceived = new AutoResetEvent(false);

              var accountServiceMock = mock.StrictMock<IAccountService>();
              var getAmountResetEventMock = mock.StrictMock<AutoResetEvent>();

              var expectedAccountId = new Random().Next(100);
              var accountInfoToTest = new AccountInfo(expectedAccountId, accountServiceMock, getAmountResetEventMock);

              var expectedReturnAmount = new Random().NextDouble();
              Expect.Call(getAmountResetEventMock.WaitOne(0)).Return(true);
              Expect.Call(getAmountResetEventMock.WaitOne(0)).Return(false);
              Expect.Call(accountServiceMock.GetAccountAmount(expectedAccountId)).Return(expectedReturnAmount);
              Expect.Call(getAmountResetEventMock.Set()).Return(true).WhenCalled(MethodInvocation => getAmountEventReceived.Set());
              mock.ReplayAll();

              getAmountEventReceived.Reset();

              accountInfoToTest.RefreshAmount();
              accountInfoToTest.RefreshAmount();

              Assert.IsTrue(getAmountEventReceived.WaitOne(1000));
              Assert.AreEqual(expectedReturnAmount, accountInfoToTest.Amount);

              mock.VerifyAll();
        }
开发者ID:justinmai,项目名称:DeveloperAssignment,代码行数:28,代码来源:TestMethod.cs

示例9: CorrectlyExecutesScriptIfItHasntAlreadyBeenExecuted

		public void CorrectlyExecutesScriptIfItHasntAlreadyBeenExecuted()
		{
			ConnectionSettings settings = getConnectionSettings();
			string scriptFile = @"c:\scripts\Update\01_Test.sql";
			string fileContents = "file contents...";

			MockRepository mocks = new MockRepository();
            IScriptExecutionTracker executionTracker = mocks.StrictMock<IScriptExecutionTracker>();
            IFileSystem fileSystem = mocks.StrictMock<IFileSystem>();
            IQueryExecutor queryExecutor = mocks.StrictMock<IQueryExecutor>();
            ITaskObserver taskObserver = mocks.StrictMock<ITaskObserver>();

			Expect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql")).Return(false);
			taskObserver.Log("Executing: 01_Test.sql in a transaction");
			Expect.Call(fileSystem.ReadTextFile(scriptFile)).Return(fileContents);
			queryExecutor.ExecuteNonQueryTransactional(settings, fileContents);
			executionTracker.MarkScriptAsExecuted(settings, "01_Test.sql", taskObserver);

			mocks.ReplayAll();

			IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, queryExecutor, fileSystem);
			executor.Execute(scriptFile, settings, taskObserver);

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

示例10: CallAllTheInterceptors

        public void CallAllTheInterceptors()
        {
            var mocks = new MockRepository();
            var interceptor1 = mocks.StrictMock<InstanceInterceptor>();
            var interceptor2 = mocks.StrictMock<InstanceInterceptor>();
            var interceptor3 = mocks.StrictMock<InstanceInterceptor>();
            var interceptor4 = mocks.StrictMock<InstanceInterceptor>();

            Expect.Call(interceptor1.Process("0", null)).Return("1");
            Expect.Call(interceptor2.Process("1", null)).Return("2");
            Expect.Call(interceptor3.Process("2", null)).Return("3");
            Expect.Call(interceptor4.Process("3", null)).Return("4");

            mocks.ReplayAll();
            var compoundInterceptor = new CompoundInterceptor(new[]
            {
                interceptor1,
                interceptor2,
                interceptor3,
                interceptor4
            });

            Assert.AreEqual("4", compoundInterceptor.Process("0", null));
            mocks.VerifyAll();
        }
开发者ID:joshuaflanagan,项目名称:structuremap,代码行数:25,代码来源:CompoundInterceptorTester.cs

示例11: MyTestInitialize

        public void MyTestInitialize()
        {
            var mocks = new MockRepository();
            Func<IProbe> registryMethod = delegate() { return new RegistryProber(); };
            Func<IProbe> familyProberWindowsMethod = delegate { return new FamilyProberWindows(); };
            Func<IProbe> familyProberUnixMethod = delegate { return new FamilyProberUnix(); };
            Func<IProbe> lineProberCiscoIosMethod = delegate { return new LineProber(); };
            Func<ISystemInformationService> systemInformationMethod = delegate() { return new WindowsSystemInformationService(); };

            var registryProbe =
                mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>(
                    registryMethod, GetProbeCapability("registry", FamilyEnumeration.windows));
            var familyProberWindows =
                mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>(
                    familyProberWindowsMethod, GetProbeCapability("family", FamilyEnumeration.windows));
            var familyProberUnix =
                mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>(
                    familyProberUnixMethod, GetProbeCapability("family", FamilyEnumeration.unix));
            var lineProberCiscoIOS =
                mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>(
                    lineProberCiscoIosMethod, GetProbeCapability("line", FamilyEnumeration.ios));
                    
            var probes = GetProbeCapabilities(registryProbe, familyProberWindows, familyProberUnix, lineProberCiscoIOS);

            var windowsInformationService =
                mocks.StrictMock<Lazy<ISystemInformationService, ISystemInformationServicePlataform>>(
                    systemInformationMethod, GetSystemInformationSvcForWindows());
            
            var systemInformations =
                new Lazy<ISystemInformationService, ISystemInformationServicePlataform>[] { windowsInformationService };
            
            ProbeManager = new ProbeManager() { probes = probes, systemInformationServices = systemInformations };
        }
开发者ID:jonaslsl,项目名称:modSIC,代码行数:33,代码来源:ProbeManagerTest.cs

示例12: DisplayProjectDetails_Should_Set_Bug_Count_From_BugService

        public void DisplayProjectDetails_Should_Set_Bug_Count_From_BugService()
        {
            MockRepository repo = new MockRepository();
            IBugListView mockBugView = repo.StrictMock<IBugListView>();
            IBugService mockBugService = repo.StrictMock<IBugService>();
            IProject mockProject = repo.StrictMock<IProject>();
            IBug[] mockBugsArray = new IBug[] { repo.StrictMock<IBug>(), repo.StrictMock<IBug>() };
            List<IBug> mockBugs = new List<IBug>(mockBugsArray);

            mockBugView.Expect(view => view.SelectedProject).Return(mockProject).Repeat.Twice();
            mockBugService.Expect(svc => svc.GetBugCountForProject(mockProject)).Return(200);
            mockBugView.Expect(view => view.TotalBugs).SetPropertyWithArgument(200);
            mockBugView.Expect(view => view.FilterBy).Return(string.Empty).Repeat.Any();
            mockBugView.Expect(view => view.FilterValue).Return(string.Empty).Repeat.Any();
            mockBugView.Expect(view => view.IsBusy).Return(false).Repeat.Any();
            mockBugView.Expect(view => view.IsBusy).SetPropertyAndIgnoreArgument().Repeat.Any();

            repo.ReplayAll();

            IBugListViewPresenter pres = new BugListViewPresenter(mockBugView, mockBugService);
            pres.DisplayProjectDetails();

            mockBugService.VerifyAllExpectations();
            mockBugView.VerifyAllExpectations();
        }
开发者ID:scottiemc7,项目名称:YurtleTrack,代码行数:25,代码来源:BugListViewPresenter_Test.cs

示例13: RunSubmitAdRequest_Returns_Empty_List_If_No_Ads

        public void RunSubmitAdRequest_Returns_Empty_List_If_No_Ads()
        {
            var mockery = new MockRepository();
              var restClient = mockery.StrictMock<IRestClient>();
              var restRequestFactory = mockery.StrictMock<IRestRequestFactory>();
              var restRequest = mockery.StrictMock<IRestRequest>();
              var serializer = mockery.Stub<ISerializer>();

              var str = "some data";

              var adRequest = new AdRequest { NetworkId = Guid.NewGuid().ToString() };

              var advertisementResponse = new AdvertisementResponseMessage { advertisement = null };
              var restResponse = new RestResponse<AdvertisementResponseMessage>();
              restResponse.Data = advertisementResponse;

              using (mockery.Record()) {
            Expect.Call(restRequestFactory.Create(null, Method.POST))
              .Constraints(Is.Anything(), Is.Equal(Method.POST))
              .Return(restRequest);
            restRequest.RequestFormat = DataFormat.Json;
            Expect.Call(restRequest.JsonSerializer).Return(serializer);
            Expect.Call(serializer.Serialize(null)).Constraints(
              Rhino.Mocks.Constraints.Property.Value("network_id", adRequest.NetworkId) &&
              Is.TypeOf<AdRequestMessage>()
            ).Return(str);
            Expect.Call(restRequest.AddParameter("text/json", str, ParameterType.RequestBody)).Return(new RestRequest());
            Expect.Call(restClient.Execute<AdvertisementResponseMessage>(restRequest)).Return(restResponse);
              }

              using (mockery.Playback()) {
            var results = new AdRequestor(restClient, restRequestFactory).RunSubmitAdRequest(adRequest);
            Assert.IsEmpty(results);
              }
        }
开发者ID:vistarmedia,项目名称:net-client,代码行数:35,代码来源:AdRequestorTest.cs

示例14: Versions_database

		public void Versions_database()
		{
			string assembly = SqlDatabaseManager.SQL_FILE_ASSEMBLY;
			string sqlFile = string.Format(SqlDatabaseManager.SQL_FILE_TEMPLATE, "VersionDatabase");

			ConnectionSettings settings = new ConnectionSettings(String.Empty, String.Empty, false, String.Empty, String.Empty);
			string sqlScript = "SQL script...";

			MockRepository mocks = new MockRepository();
            IResourceFileLocator fileLocator = mocks.StrictMock<IResourceFileLocator>();
            IQueryExecutor queryExecutor = mocks.StrictMock<IQueryExecutor>();
            ITaskObserver taskObserver = mocks.StrictMock<ITaskObserver>();

			using (mocks.Record())
			{
				Expect.Call(fileLocator.ReadTextFile(assembly, sqlFile)).Return(sqlScript);
				Expect.Call(queryExecutor.ExecuteScalarInteger(settings, sqlScript)).Return(7);
				taskObserver.SetVariable("usdDatabaseVersion", "7");
			}

			using (mocks.Playback())
			{
				IDatabaseVersioner versioner = new DatabaseVersioner(fileLocator, queryExecutor);
				versioner.VersionDatabase(settings, taskObserver);
			}

			mocks.VerifyAll();
		}
开发者ID:jlbrown,项目名称:AliaSQL,代码行数:28,代码来源:DatabaseVersionerTester.cs

示例15: Drops_Azure_database_without_dropping_connections

        public void Drops_Azure_database_without_dropping_connections()
        {
            var settings = new ConnectionSettings("server", "db", true, null, null);
            var taskAttributes = new TaskAttributes(settings, null);

            var mocks = new MockRepository();
            var connectionDropper = mocks.StrictMock<IDatabaseConnectionDropper>();
            var taskObserver = mocks.StrictMock<ITaskObserver>();
            var queryExecutor = mocks.StrictMock<IQueryExecutor>();

            using (mocks.Record())
            {
                Expect.Call(() => taskObserver.Log("Running against: SQL Azure"));
                Expect.Call(queryExecutor.ReadFirstColumnAsStringArray(settings, "select @@version")).Return(new string[] { "SQL Azure" });
                queryExecutor.ExecuteNonQuery(settings, "drop database [db]");
                Expect.Call(() => taskObserver.Log("Dropping database: db\n"));
            }

            using (mocks.Playback())
            {
                IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
                dropper.Execute(taskAttributes, taskObserver);
            }

            mocks.VerifyAll();
        }
开发者ID:jlbrown,项目名称:AliaSQL,代码行数:26,代码来源:DatabaseDropperTester.cs


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