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


C# Mocks.MockRepository类代码示例

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


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

示例1: GetById_Calls_GigDAO_Method_GetById_Once_And_Returns_A_Gig

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

            Guid gigId = Guid.NewGuid();
            Gig gig = new Gig();
            gig.ID = gigId;

            IGigDAO gigDAO = mocks.DynamicMock<IGigDAO>();
            GigManager gigManager = new GigManager();
            gigManager.GigDAO = gigDAO;

            Expect.Call(gigDAO.GetById(gigId))
               .Constraints(Is.Equal(gigId))
               .Repeat.Once()
               .Return(gig);

            mocks.ReplayAll();

            Gig result = gigManager.GetByID(gigId);

            mocks.VerifyAll();

            Assert.AreEqual(gig.ID, result.ID);
        }
开发者ID:listentorick,项目名称:ListenTo,代码行数:25,代码来源:GigManagerTests.cs

示例2: 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

示例3: ShouldParseAuthenticationStringWhenAuthorizationStringIsAvailable

        public void ShouldParseAuthenticationStringWhenAuthorizationStringIsAvailable()
        {
            MockRepository repository = new MockRepository();

             DigestHeaderParser headerParser = MockCreator<DigestHeaderParser>.Stub(repository);
             MethodExtractor methodExtractor = MockCreator<MethodExtractor>.Stub(repository);

             Message testMessage = TestResources.CreateMessage();

             AuthorizationStringExtractor extractor;
             using (repository.Record())
             {
            headerParser.Expect(parser => parser.Parse(string.Empty)).IgnoreArguments().Return(TestResources.CreateHeader());

            extractor = MockCreator<AuthorizationStringExtractor>.Create(repository);
            string authenticationString;
            extractor.Expect(extr => extr.TryExtractAuthorizationHeader(testMessage, out authenticationString)).OutRef(TestResources.AuthenticationString).Return(true);
             }

             var digestHeaderExtractor = new DigestHeaderExtractor(extractor, headerParser, methodExtractor);
             using (repository.Playback())
             {
            DigestHeader digestHeader;
            bool result = digestHeaderExtractor.TryExtract(testMessage, out digestHeader);
            Assert.That(result, Is.True);
             }
        }
开发者ID:kalkie,项目名称:DigestAuthenticationUsingWCF,代码行数:27,代码来源:DigestHeaderExtractorTest.cs

示例4: Setup

 public void Setup()
 {
     repository = new MockRepository();
     sc = new ServiceContainer();
     arch = new IntelArchitecture(ProcessorMode.Protected32);
     dcSvc = repository.StrictMock<IConfigurationService>();
 }
开发者ID:gitter-badger,项目名称:reko,代码行数:7,代码来源:Win32PlatformTests.cs

示例5: RelationsTest

        public static void RelationsTest()
        {
            MockRepository rhinoEngine = new MockRepository();
            var mockWriter = rhinoEngine.DynamicMock<TextWriter>();

            TextWriterFactory.SetTextWriter(mockWriter);

            using (rhinoEngine.Record())
            {
                mockWriter.Write("Nothing");
                LastCall.Constraints(new Rhino.Mocks.Constraints.Contains("TestCustomer") &
                                     new Rhino.Mocks.Constraints.Contains("TestMovie") &
                                     new Rhino.Mocks.Constraints.Contains("6 days") &
                                     new Rhino.Mocks.Constraints.Contains(12.ToString("C")));
                mockWriter.Flush();

            }

            Customer customer = new Customer("TestCustomer");
            customer.Rental.Add(new Rental(new Movie("TestMovie", 2), 6));

            ReportManager.CreateReport("SomePath", customer);

            rhinoEngine.VerifyAll();
        }
开发者ID:master-vk,项目名称:Tasks-ITVDN,代码行数:25,代码来源:TestClass.cs

示例6: SetUp

        public void SetUp()
        {
            _mocks = new MockRepository();
            _output = new StringWriter();

            string viewPath = "MvcContrib.ViewEngines.NVelocity.Tests";

            IDictionary properties = new Hashtable();
            properties["resource.loader"] = "assembly";
            properties["assembly.resource.loader.class"] = "NVelocity.Runtime.Resource.Loader.AssemblyResourceLoader, NVelocity";
            properties["assembly.resource.loader.assembly"] = new List<string>() {GetType().Assembly.FullName};
            properties["master.folder"] = viewPath;
            _viewEngine = new NVelocityViewEngine(properties);

            var httpContext = _mocks.DynamicMock<HttpContextBase>();
            var response = _mocks.DynamicMock<HttpResponseBase>();
            SetupResult.For(httpContext.Response).Return(response);
            SetupResult.For(response.Output).Return(_output);

            var requestContext = new RequestContext(httpContext, new RouteData());
            var controller = _mocks.DynamicMock<ControllerBase>();

            _mocks.ReplayAll();

            _controllerContext = new ControllerContext(requestContext, controller);
            _controllerContext.RouteData.Values.Add("controller", viewPath);
        }
开发者ID:mvccontrib,项目名称:NVelocity,代码行数:27,代码来源:NVelocityViewEngineTester.cs

示例7: Do3Classic

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

            model.VisibilityStateChanged += null;
            IEventRaiser visibilityChanged = LastCall.GetEventRaiser();

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

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

            mockRepository.BackToRecordAll();
            //mockRepository.Playback();

            Expect.Call(model.ToggleVisibility);
            Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments();
            Expect.Call(() => view.SetCheckedState(CheckedState.Checked));

            mockRepository.ReplayAll();

            clicked.Raise();
            visibilityChanged.Raise(VisibilityState.Visible);

            mockRepository.VerifyAll();
        }
开发者ID:baens,项目名称:Esri2011,代码行数:29,代码来源:ButtonPresenterFixture.cs

示例8: Setup

 public void Setup()
 {
     mr = new MockRepository();
     frame = mr.DynamicMock<IWindowFrame>();
     sc = new ServiceContainer();
     sc.AddService(typeof(IWindowFrame), frame);
 }
开发者ID:gitter-badger,项目名称:reko,代码行数:7,代码来源:SearchResultServiceTests.cs

示例9: 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

示例10: GetMatchNonMatchTest

        public static void GetMatchNonMatchTest(
			string headerName, 
			string[] values, 
			bool existsInStore,
			bool expectReturnNull,
			HttpStatusCode expectedStatus = HttpStatusCode.Unused)
        {
            // setup
            var mocks = new MockRepository();
            var entityTagStore = mocks.StrictMock<IEntityTagStore>();
            var entityTagHandler = new CachingHandler(entityTagStore);
            var request = new HttpRequestMessage(HttpMethod.Get, TestUrl);
            request.Headers.Add(headerName, values);
            TimedEntityTagHeaderValue entityTagHeaderValue = new TimedEntityTagHeaderValue("\"12345678\"");

            if(values.Length>0) // if
                entityTagStore.Expect(x => x.TryGetValue(Arg<CacheKey>.Matches(etg => etg.ResourceUri == entityTagHandler.UriTrimmer(new Uri(TestUrl))),
                    out Arg<TimedEntityTagHeaderValue>.Out(entityTagHeaderValue).Dummy)).Return(existsInStore);

            mocks.ReplayAll();

            // run
            var matchNoneMatch = entityTagHandler.GetIfMatchNoneMatch();
            // verify
            Task<HttpResponseMessage> resultTask = matchNoneMatch(request);
            Assert.That(expectReturnNull ^ resultTask != null, "result was not as expected");
            if(resultTask!=null && expectedStatus != HttpStatusCode.Unused)
            {
                Assert.AreEqual(expectedStatus, resultTask.Result.StatusCode, "Status code");
            }
            mocks.VerifyAll();
        }
开发者ID:sayedihashimi,项目名称:CacheCow,代码行数:32,代码来源:CachingHandlerRulesTests.cs

示例11: VerifyInstanceDoesNotCallJetTermWhenCreateInstanceFails

        public void VerifyInstanceDoesNotCallJetTermWhenCreateInstanceFails()
        {
            var mocks = new MockRepository();
            var mockApi = mocks.StrictMock<IJetApi>();
            using (new ApiTestHook(mockApi))
            {
                Expect.Call(
                    mockApi.JetCreateInstance2(
                        out Arg<JET_INSTANCE>.Out(JET_INSTANCE.Nil).Dummy,
                        Arg<string>.Is.Anything,
                        Arg<string>.Is.Anything,
                        Arg<CreateInstanceGrbit>.Is.Anything))
                    .Return((int) JET_err.InvalidName);
                mocks.ReplayAll();

                try
                {
                    using (var instance = new Instance("testfail"))
                    {
                        Assert.Fail("Expected an EsentErrorException");
                    }
                }
                catch (EsentErrorException)
                {
                    // expected
                }

                mocks.VerifyAll();
            }
        }
开发者ID:Rationalle,项目名称:ravendb,代码行数:30,代码来源:InstanceTests.cs

示例12: Setup

		public void Setup()
		{
			ssaIds = new SsaIdentifierCollection();
            mr = new MockRepository();
            arch = mr.Stub<IProcessorArchitecture>();
            importResolver = mr.Stub<IImportResolver>();
		}
开发者ID:uxmal,项目名称:reko,代码行数:7,代码来源:ValuePropagationTests.cs

示例13: TestFixtureSetUp

		public void TestFixtureSetUp()
		{
			Mocks = new MockRepository();

			Establish_context();
			Because();
		}
开发者ID:agross,项目名称:graffiti-usergroups,代码行数:7,代码来源:Spec.cs

示例14: GetGigsBySiteAfterDate_Calls_GigDAO_Method_GetGigsBySiteAfterDate_Once_And_Returns_Gigs

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

            DateTime startDate = DateTime.Now;
            int numGigs = 10;
            List<Gig> gigs = (List<Gig>)CreateListOfGigs(numGigs, startDate);

            Guid siteId = Guid.NewGuid();

            IGigDAO gigDAO = mocks.DynamicMock<IGigDAO>();
            GigManager gigManager = new GigManager();
            gigManager.GigDAO = gigDAO;

            Expect.Call(gigDAO.GetGigsBySiteAfterDate(siteId, startDate))
               .Constraints(new AbstractConstraint[] { Is.Equal(siteId), Is.Equal(startDate) })
               .Repeat.Once()
               .Return(gigs);

            mocks.ReplayAll();

            List<Gig> result = (List<Gig>)gigManager.GetGigsBySiteAfterDate(siteId, startDate);

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

示例15: ExecuteWithAllOptions

        public void ExecuteWithAllOptions()
        {
            var mocks = new MockRepository();
            var conn = mocks.StrictMock<ISolrConnection>();

            With.Mocks(mocks).Expecting(() =>
            {
                conn.Post("/update", "<commit waitSearcher=\"true\" waitFlush=\"true\" expungeDeletes=\"true\" maxSegments=\"2\" />");
                LastCall.On(conn).Repeat.Once().Do(new Writer(delegate(string ignored, string s)
                {
                    Console.WriteLine(s);
                    return null;
                }));
            }).Verify(() =>
            {
                var cmd = new CommitCommand
                              {
                                  MaxSegments = 2,
                                  ExpungeDeletes = true,
                                  WaitFlush = true,
                                  WaitSearcher = true
                              };
                cmd.Execute(conn);
            });
        }
开发者ID:holytshirt,项目名称:SolrNet,代码行数:25,代码来源:CommitCommandTests.cs


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