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


C# MockRepository类代码示例

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


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

示例1: WillMerge_UnorderedRecorder_WhenRecorderHasSingleRecorderInside

        public void WillMerge_UnorderedRecorder_WhenRecorderHasSingleRecorderInside()
        {
            MockRepository mocks = new MockRepository();
            ICustomer customer = mocks.StrictMock<ICustomer>();

            CustomerMapper mapper = new CustomerMapper();

            using (mocks.Record())
            using (mocks.Ordered())
            {
                Expect.Call(customer.Id).Return(0);

                customer.IsPreferred = true;
            }

            ExpectationViolationException ex = Assert.Throws<ExpectationViolationException>(() =>
            {
                using (mocks.Playback())
                {
                    mapper.MarkCustomerAsPreferred(customer);
                }
            });

            Assert.Equal("Unordered method call! The expected call is: 'Ordered: { ICustomer.get_Id(); }' but was: 'ICustomer.set_IsPreferred(True);'", ex.Message);
        }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:25,代码来源:FieldProblem_Shane.cs

示例2: Delete_HappyPath

        public void Delete_HappyPath()
        {
            // obtains a valid patient
            Firestarter.CreateFakePatients(this.db.Doctors.First(), this.db);
            this.db.SaveChanges();
            var patientId = this.db.Patients.First().Id;

            var formModel = new AnamneseViewModel()
            {
                PatientId = patientId,
                Conclusion = "This is my anamnese",
                DiagnosticHypotheses = new List<DiagnosticHypothesisViewModel>() {
                        new DiagnosticHypothesisViewModel() { Text = "Text", Cid10Code = "Q878" },
                        new DiagnosticHypothesisViewModel() { Text = "Text2", Cid10Code = "Q879" }
                   }
            };

            var mr = new MockRepository(true);
            var controller = mr.CreateController<AnamnesesController>();
            controller.Create(new[] { formModel });

            Assert.IsTrue(controller.ModelState.IsValid);

            // get's the newly created anamnese
            var newlyCreatedAnamnese = this.db.Anamnese.First();

            // tries to delete the anamnese
            var result = controller.Delete(newlyCreatedAnamnese.Id);
            JsonDeleteMessage deleteMessage = (JsonDeleteMessage)result.Data;

            Assert.AreEqual(true, deleteMessage.success);
            Assert.AreEqual(0, this.db.Anamnese.Count());
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:33,代码来源:AnamnesesControllerTests.cs

示例3: CallbackTests

 public CallbackTests()
 {
     System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
     mocks = new MockRepository();
     demo = (IDemo) mocks.StrictMock(typeof (IDemo));
     callbackCalled = false;
 }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:7,代码来源:CallbackTests.cs

示例4: CanMockIE

 public void CanMockIE()
 {
     //TODO: Figure out why this does not work.
     MockRepository mockRepository = new MockRepository();
     IHTMLEventObj2 mock = mockRepository.StrictMock<IHTMLEventObj2>();
     Assert.NotNull(mock);
 }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:7,代码来源:FieldProblem_Luke.cs

示例5: CallbackExpectationTests

 public CallbackExpectationTests()
 {
     mocks = new MockRepository();
     demo = (IDemo) mocks.StrictMock(typeof (IDemo));
     method = typeof (IDemo).GetMethod("VoidThreeArgs");
     callbackCalled = false;
 }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:7,代码来源:CallbackExpectationTests.cs

示例6: CanUseExpectSyntax_OnMockWithOrderedExpectations

        public void CanUseExpectSyntax_OnMockWithOrderedExpectations(bool shouldSwitchToReplyImmediately)
        {
            MockRepository mocks = new MockRepository();

            var foo54 = mocks.StrictMock<IFoo54>();
            if (shouldSwitchToReplyImmediately)
                mocks.ReplayAll();

            using (mocks.Ordered())
            {
                foo54
                    .Expect(x => x.DoSomething())
                    .Return(0);

                foo54
                    .Expect(x => x.DoSomethingElse());
            }

            if (!shouldSwitchToReplyImmediately)
                mocks.Replay(foo54);

            foo54.DoSomething();
            foo54.DoSomethingElse();

            foo54.VerifyAllExpectations();
        }
开发者ID:ChuangYang,项目名称:RhinoMocks,代码行数:26,代码来源:FieldProblem_Jodran.cs

示例7: Ayende_View_On_Mocking

        public void Ayende_View_On_Mocking()
        {
            MockRepository mocks = new MockRepository();
            ISomeSystem mockSomeSystem = mocks.StrictMock<ISomeSystem>();

            using (mocks.Record())
            {
                Expect.Call(mockSomeSystem.GetFooFor<ExpectedBar>("foo"))
                    .Return(new List<ExpectedBar>());
            }

            ExpectationViolationException ex = Assert.Throws<ExpectationViolationException>(
                () =>
                {
                    using (mocks.Playback())
                    {
                        ExpectedBarPerformer cut = new ExpectedBarPerformer(mockSomeSystem);
                        cut.DoStuffWithExpectedBar("foo");
                    }
                }
                );

            Assert.Equal(@"ISomeSystem.GetFooFor<Rhino.Mocks.Tests.FieldsProblem.UnexpectedBar>(""foo""); Expected #1, Actual #1.
            ISomeSystem.GetFooFor<Rhino.Mocks.Tests.FieldsProblem.ExpectedBar>(""foo""); Expected #1, Actual #0.", ex.Message);
        }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:25,代码来源:FieldProblem_Rob.cs

示例8: StubRecordMockState

 /// <summary>
 /// Initializes a new instance of the <see cref="StubRecordMockState"/> class.
 /// </summary>
 /// <param name="mockedObject">The proxy that generates the method calls</param>
 /// <param name="repository">Repository.</param>
 /// <param name="isPartial">A flag indicating whether we should behave like a partial stub.</param>
 public StubRecordMockState(IMockedObject mockedObject, MockRepository repository, bool isPartial)
     : base(mockedObject, repository)
 {
     this.isPartial = isPartial;
     Type[] types = mockedObject.ImplementedTypes;
     SetPropertyBehavior(mockedObject, types);
 }
开发者ID:alaendle,项目名称:rhino-mocks,代码行数:13,代码来源:StubRecordMockState.cs

示例9: EditPost_UserIsOwner_WithInvalidData

        public void EditPost_UserIsOwner_WithInvalidData()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();
            try
            {
                mr.SetCurrentUser_Andre_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");

                homeController = mr.CreateController<PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            var viewModel = new PracticeHomeControllerViewModel
            {
                PracticeName = "", // Cannot set practice name to empty
                PracticeTimeZone = 3
            };

            Mvc3TestHelper.SetModelStateErrors(homeController, viewModel);

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
                            ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
                            ?? homeController.Edit(viewModel);

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            Assert.AreEqual(null, ((ViewResult)actionResult).View);
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:34,代码来源:PracticeHomeControllerTests.cs

示例10: Override_using_tag_with_a_prerelease

 public void Override_using_tag_with_a_prerelease()
 {
     var commit = new MockCommit
     {
         CommitterEx = 2.Seconds().Ago().ToSignature()
     };
     var finder = new MasterVersionFinder();
     var mockBranch = new MockBranch("master")
     {
         commit
     };
     var mockRepository = new MockRepository
     {
         Branches = new MockBranchCollection
         {
             mockBranch
         },
         Tags = new MockTagCollection
         {
             new MockTag
             {
                 NameEx = "0.1.0-beta1",
                 TargetEx = commit
             }
         }
     };
     var version = finder.FindVersion(new GitVersionContext(mockRepository, mockBranch, new Config()));
     Assert.AreEqual(0, version.Patch, "Should set the patch version to the patch of the latest hotfix merge commit");
     ObjectApprover.VerifyWithJson(version, Scrubbers.GuidScrubber);
 }
开发者ID:unic,项目名称:GitVersion,代码行数:30,代码来源:MasterTests.cs

示例11: EditPost_UserIsAdministrator

        public void EditPost_UserIsAdministrator()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();
            try
            {
                mr.SetCurrentUser_Miguel_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");

                homeController = mr.CreateController<PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
                            ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
                            ?? homeController.Edit(new PracticeHomeControllerViewModel
                            {
                                PracticeName = "My New Practice Name",
                                PracticeTimeZone = 3
                            });

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
            var redirectResult = (RedirectToRouteResult)actionResult;
            Assert.AreEqual(2, redirectResult.RouteValues.Count);
            Assert.AreEqual("practicehome", string.Format("{0}", redirectResult.RouteValues["controller"]), ignoreCase: true);
            Assert.AreEqual("Index", string.Format("{0}", redirectResult.RouteValues["action"]), ignoreCase: true);
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:33,代码来源:PracticeHomeControllerTests.cs

示例12: DslFactoryFixture

        public DslFactoryFixture()
        {
            factory = new DslFactory();
            mocks = new MockRepository();
            mockedDslEngine = mocks.DynamicMock<DslEngine>();
            mockCache = mocks.DynamicMock<IDslEngineCache>();
        	
			mockCache.WriteLock(null);
        	LastCall.Repeat.Any()
        		.IgnoreArguments()
        		.Do((Action<CacheAction>) ExecuteCachedAction);
			
			mockCache.ReadLock(null);
			LastCall.Repeat.Any()
				.IgnoreArguments()
				.Do((Action<CacheAction>)ExecuteCachedAction);
            
			IDslEngineStorage mockStorage = mocks.DynamicMock<IDslEngineStorage>();
            Assembly assembly = Assembly.GetCallingAssembly();
            context = new CompilerContext();
            context.GeneratedAssembly = assembly;
            mockedDslEngine.Storage = mockStorage;
            mockedDslEngine.Cache = mockCache;

            SetupResult.For(mockStorage.GetMatchingUrlsIn("", ref testUrl)).Return(new string[] { testUrl });
            SetupResult.For(mockStorage.IsUrlIncludeIn(null, null, null))
                .IgnoreArguments()
                .Return(true);
        }
开发者ID:JackWangCUMT,项目名称:rhino-dsl,代码行数:29,代码来源:DslFactoryFixture.cs

示例13: RhinoInterceptor

 /// <summary>
 /// Initializes a new instance of the <see cref="RhinoInterceptor"/> class. 
 /// Creates a new <see cref="RhinoInterceptor"/> instance.
 /// </summary>
 /// <param name="repository">
 /// The repository.
 /// </param>
 /// <param name="proxyInstance">
 /// The proxy Instance.
 /// </param>
 /// <param name="invocation_visitors">
 /// The invocation_visitors.
 /// </param>
 public RhinoInterceptor(MockRepository repository, IMockedObject proxyInstance, 
                         IEnumerable<InvocationVisitor> invocation_visitors)
 {
     this.repository = repository;
     this.proxyInstance = proxyInstance;
     this.invocation_visitors = invocation_visitors;
 }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:20,代码来源:RhinoInterceptor.cs

示例14: CantCallOriginalMethodOnInterface

 public void CantCallOriginalMethodOnInterface()
 {
     MockRepository mocks = new MockRepository();
     IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo));
     var ex = Assert.Throws<InvalidOperationException>(() => SetupResult.For(demo.ReturnIntNoArgs()).CallOriginalMethod(OriginalCallOptions.CreateExpectation));
     Assert.Equal("Can't use CallOriginalMethod on method ReturnIntNoArgs because the method is abstract.", ex.Message);
 }
开发者ID:guesshoo,项目名称:rhino-mocks,代码行数:7,代码来源:CallOriginalMethodTests.cs

示例15: RecorderChanger

 /// <summary>
 /// Initializes a new instance of the <see cref="RecorderChanger"/> class. 
 /// Creates a new <see cref="RecorderChanger"/> instance.
 /// </summary>
 /// <param name="repository">
 /// The repository.
 /// </param>
 /// <param name="recorder">
 /// The recorder.
 /// </param>
 /// <param name="newRecorder">
 /// The new Recorder.
 /// </param>
 public RecorderChanger(MockRepository repository, IMethodRecorder recorder, IMethodRecorder newRecorder)
 {
     this.recorder = recorder;
     this.repository = repository;
     repository.PushRecorder(newRecorder);
     this.recorder.AddRecorder(newRecorder);
 }
开发者ID:bjornbouetsmith,项目名称:mammock,代码行数:20,代码来源:RecorderChanger.cs


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