當前位置: 首頁>>代碼示例>>C#>>正文


C# Moq.MockRepository類代碼示例

本文整理匯總了C#中Moq.MockRepository的典型用法代碼示例。如果您正苦於以下問題:C# MockRepository類的具體用法?C# MockRepository怎麽用?C# MockRepository使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MockRepository類屬於Moq命名空間,在下文中一共展示了MockRepository類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Install_should_install_if_a_package_has_not_been_installed_yet

        public void Install_should_install_if_a_package_has_not_been_installed_yet()
        {
            // Arrange
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            var proj = fixture.Freeze<Project>();
            var pwPkg = new ProjectWidePackage("Prig", "2.0.0", proj);
            var mocks = new MockRepository(MockBehavior.Strict);
            {
                var m = mocks.Create<IVsPackageInstallerServices>();
                m.Setup(_ => _.IsPackageInstalledEx(proj, "Prig", "2.0.0")).Returns(false);
                m.Setup(_ => _.IsPackageInstalled(proj, "Prig")).Returns(false);
                fixture.Inject(m);
            }
            {
                var m = mocks.Create<IVsPackageUninstaller>();
                fixture.Inject(m);
            }
            {
                var m = mocks.Create<IVsPackageInstaller>();
                m.Setup(_ => _.InstallPackage(default(string), proj, "Prig", "2.0.0", false));
                fixture.Inject(m);
            }

            var pwInstllr = fixture.NewProjectWideInstaller();


            // Act
            pwInstllr.Install(pwPkg);


            // Assert
            mocks.VerifyAll();
        }
開發者ID:umaranis,項目名稱:Prig,代碼行數:34,代碼來源:ProjectWideInstallerTest.cs

示例2: InvokeErrorTest

 public async Task InvokeErrorTest()
 {
     var mr = new MockRepository(MockBehavior.Strict);
     var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware)null);
     var ctx = mr.Create<IOwinContext>();
     var logger = mr.Create<ILog>();
     var exception = new Exception();
     var request = mr.Create<IOwinRequest>();
     ctx.SetupGet(x => x.Request).Returns(request.Object).Verifiable();
     logger.Setup(x => x.Info(It.IsAny<string>())).Throws(exception);
     request.SetupGet(x => x.Method).Returns("fasefaes").Verifiable();
     request.SetupGet(x => x.Uri).Returns(new Uri("http://ya.ru")).Verifiable();
     request.SetupGet(x => x.RemoteIpAddress).Returns("asefasergsdrg").Verifiable();
     request.SetupGet(x => x.RemotePort).Returns(11).Verifiable();
     var mw = new LoggerMiddleware(next.Object, logger.Object);
     try
     {
         await mw.Invoke(ctx.Object);
     }
     catch (Exception e)
     {
         Assert.AreEqual(exception, e);
         return;
     }
     finally
     {
         mr.VerifyAll();
     }
     Assert.Fail();
 }
開發者ID:riberk,項目名稱:Rib.Common,代碼行數:30,代碼來源:LoggerMiddlewareTests.cs

示例3: Create

 public void Create(params string[] lines)
 {
     _textBuffer = EditorUtil.CreateTextBuffer(lines);
     _factory = new MockRepository(MockBehavior.Strict);
     _adapterRaw = new ResharperExternalEditAdapter();
     _adapter = _adapterRaw;
 }
開發者ID:GunioRobot,項目名稱:VsVim,代碼行數:7,代碼來源:ResharperExternalEditAdapterTest.cs

示例4: HostFactoryTest

        protected HostFactoryTest()
        {
            _globalSettings = Vim.GlobalSettings;
            _protectedOperations = new TestableProtectedOperations();
            _mockFactory = new MockRepository(MockBehavior.Strict);
            _synchronizer = _mockFactory.Create<IEditorToSettingsSynchronizer>(MockBehavior.Strict);
            _vsEditorAdaptersFactoryService = _mockFactory.Create<IVsEditorAdaptersFactoryService>();
            _vimApplicationSettings = _mockFactory.Create<IVimApplicationSettings>(MockBehavior.Loose);

            var vsAdapter = _mockFactory.Create<IVsAdapter>();
            vsAdapter.SetupGet(x => x.EditorAdapter).Returns(_vsEditorAdaptersFactoryService.Object);

            _hostFactory = new HostFactory(
                Vim,
                _vsEditorAdaptersFactoryService.Object,
                _mockFactory.Create<IDisplayWindowBrokerFactoryService>(MockBehavior.Loose).Object,
                _mockFactory.Create<ITextManager>(MockBehavior.Loose).Object,
                vsAdapter.Object,
                _protectedOperations,
                new VimBufferCoordinatorFactory(Vim),
                _mockFactory.Create<IKeyUtil>(MockBehavior.Loose).Object,
                _synchronizer.Object,
                _vimApplicationSettings.Object,
                new Lazy<ICommandTargetFactory, IOrderable>[] { });
        }
開發者ID:aesire,項目名稱:VsVim,代碼行數:25,代碼來源:HostFactoryTest.cs

示例5: Setup

 public void Setup()
 {
     _candidate = ObjectMother.GetCandidate();
     _mockRepository = new MockRepository(MockBehavior.Default);
     _candidateRepoMock = _mockRepository.Create<ICandidateRepository>();
     _service = new CandidateService(_candidateRepoMock.Object);
 }
開發者ID:AprigioJoseZancheta,項目名稱:TrabalhoDesenvolvimentoAprigio,代碼行數:7,代碼來源:ServiceCandidateTest.cs

示例6: Create

 public void Create(params string[] lines)
 {
     _textView = CreateTextView(lines);
     _textView.Caret.MoveTo(new SnapshotPoint(_textView.TextSnapshot, 0));
     _textBuffer = _textView.TextBuffer;
     _factory = new MockRepository(MockBehavior.Strict);
     _editOpts = _factory.Create<IEditorOperations>();
     _vimHost = _factory.Create<IVimHost>();
     _vimHost.Setup(x => x.IsDirty(It.IsAny<ITextBuffer>())).Returns(false);
     _operations = _factory.Create<ICommonOperations>();
     _operations.SetupGet(x => x.EditorOperations).Returns(_editOpts.Object);
     _statusUtil = _factory.Create<IStatusUtil>();
     _fileSystem = _factory.Create<IFileSystem>(MockBehavior.Strict);
     _foldManager = _factory.Create<IFoldManager>(MockBehavior.Strict);
     _vimData = new VimData();
     _vim = MockObjectFactory.CreateVim(RegisterMap, host: _vimHost.Object, vimData: _vimData, factory: _factory);
     var localSettings = new LocalSettings(Vim.GlobalSettings);
     var vimTextBuffer = MockObjectFactory.CreateVimTextBuffer(
         _textBuffer,
         vim: _vim.Object,
         localSettings: localSettings,
         factory: _factory);
     var vimBufferData = CreateVimBufferData(
         vimTextBuffer.Object,
         _textView,
         statusUtil: _statusUtil.Object);
     var vimBuffer = CreateVimBuffer(vimBufferData);
     _interpreter = new Interpreter.VimInterpreter(
         vimBuffer,
         _operations.Object,
         _foldManager.Object,
         _fileSystem.Object,
         _factory.Create<IBufferTrackingService>().Object);
 }
開發者ID:wmchristie,項目名稱:VsVim,代碼行數:34,代碼來源:CommandProcessorLegacyTest.cs

示例7: UserServiceTest

 public UserServiceTest()
 {
     this.mockRepository = new MockRepository(MockBehavior.Strict);
     this.mockErrorState = this.mockRepository.Create<IErrorState>();
     this.mockUserRepository = this.mockRepository.Create<IUserRepository>();
     this.userService = new UserService(this.mockErrorState.Object, this.mockUserRepository.Object);
 }
開發者ID:akornatskyy,項目名稱:sample-blog-api-net,代碼行數:7,代碼來源:UserServiceTest.cs

示例8: ReportDesignerUtilTest

 protected ReportDesignerUtilTest()
 {
     _factory = new MockRepository(MockBehavior.Strict);
     _vsEditorAdaptersFactoryService = _factory.Create<IVsEditorAdaptersFactoryService>();
     _reportDesignerUtilRaw = new ReportDesignerUtil(_vsEditorAdaptersFactoryService.Object);
     _reportDesignerUtil = _reportDesignerUtilRaw;
 }
開發者ID:aesire,項目名稱:VsVim,代碼行數:7,代碼來源:ReportDesignerUtilTest.cs

示例9: Create

 public void Create(params string[] lines)
 {
     _textBuffer = CreateTextBuffer(lines);
     _factory = new MockRepository(MockBehavior.Strict);
     _reSharperUtilRaw = new ReSharperUtil(isResharperInstalled: true);
     _reSharperUtil = _reSharperUtilRaw;
 }
開發者ID:honeyhoneywell,項目名稱:VsVim,代碼行數:7,代碼來源:ReSharperUtilTest.cs

示例10: CreateVsTextLineMarker

 public static Mock<IVsTextLineMarker> CreateVsTextLineMarker(
     TextSpan span,
     MARKERTYPE type,
     MockRepository factory = null)
 {
     return CreateVsTextLineMarker(span, (int)type, factory);
 }
開發者ID:kcprogrammer,項目名稱:VsVim,代碼行數:7,代碼來源:MockObjectFactory.cs

示例11: UserBusinessLogicTests

        public UserBusinessLogicTests()
        {
            MockFactory = new MockRepository(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock };

            MockedUserBusinessLogic = MockFactory.Create<IUserBusinessLogic>();
            MockedUserRepository = MockFactory.Create<IUserRepository>();
        }
開發者ID:dragana-berber,項目名稱:FarmAppReborn,代碼行數:7,代碼來源:UserBusinessLogicTests.cs

示例12: VsCommandTargetTest

        public VsCommandTargetTest()
        {
            _textView = CreateTextView("");
            _buffer = Vim.CreateVimBuffer(_textView);
            _bufferCoordinator = new VimBufferCoordinator(_buffer);
            _vim = _buffer.Vim;
            _factory = new MockRepository(MockBehavior.Strict);

            // By default Resharper isn't loaded
            _resharperUtil = _factory.Create<IResharperUtil>();
            _resharperUtil.SetupGet(x => x.IsInstalled).Returns(false);

            _nextTarget = _factory.Create<IOleCommandTarget>(MockBehavior.Strict);
            _vsAdapter = _factory.Create<IVsAdapter>();
            _vsAdapter.SetupGet(x => x.KeyboardDevice).Returns(InputManager.Current.PrimaryKeyboardDevice);
            _vsAdapter.Setup(x => x.InAutomationFunction).Returns(false);
            _vsAdapter.Setup(x => x.InDebugMode).Returns(false);
            _vsAdapter.Setup(x => x.IsIncrementalSearchActive(It.IsAny<ITextView>())).Returns(false);

            _broker = _factory.Create<IDisplayWindowBroker>(MockBehavior.Loose);

            var oldCommandFilter = _nextTarget.Object;
            var vsTextView = _factory.Create<IVsTextView>(MockBehavior.Loose);
            vsTextView.Setup(x => x.AddCommandFilter(It.IsAny<IOleCommandTarget>(), out oldCommandFilter)).Returns(0);
            var result = VsCommandTarget.Create(
                _bufferCoordinator,
                vsTextView.Object,
                _vsAdapter.Object,
                _broker.Object,
                _resharperUtil.Object,
                KeyUtil);
            Assert.True(result.IsSuccess);
            _targetRaw = result.Value;
            _target = _targetRaw;
        }
開發者ID:kcprogrammer,項目名稱:VsVim,代碼行數:35,代碼來源:VsCommandTargetTest.cs

示例13: VimTest

        public VimTest()
        {
            _factory = new MockRepository(MockBehavior.Strict);
            _globalSettings = new GlobalSettings();
            _markMap = _factory.Create<IMarkMap>(MockBehavior.Strict);
            _fileSystem = _factory.Create<IFileSystem>(MockBehavior.Strict);
            _bufferFactory = VimBufferFactory;

            var map = new Dictionary<string, VariableValue>();
            _keyMap = new KeyMap(_globalSettings, map);
            _vimHost = _factory.Create<IVimHost>(MockBehavior.Strict);
            _searchInfo = _factory.Create<ISearchService>(MockBehavior.Strict);
            _vimRaw = new Vim(
                _vimHost.Object,
                _bufferFactory,
                FSharpList<Lazy<IVimBufferCreationListener>>.Empty,
                _globalSettings,
                _markMap.Object,
                _keyMap,
                MockObjectFactory.CreateClipboardDevice().Object,
                _searchInfo.Object,
                _fileSystem.Object,
                new VimData(),
                _factory.Create<IBulkOperations>().Object,
                map);
            _vim = _vimRaw;
            _vim.AutoLoadVimRc = false;
        }
開發者ID:fpicalausa,項目名稱:VsVim,代碼行數:28,代碼來源:VimTest.cs

示例14: Setup

 public void Setup()
 {
     _interview = ObjectMother.GetInterview();
     _mockRepository = new MockRepository(MockBehavior.Default);
     _interviewRepoMoq = _mockRepository.Create<IInterviewRepository>();
     _service = new InterviewService(_interviewRepoMoq.Object);
 }
開發者ID:AprigioJoseZancheta,項目名稱:TrabalhoDesenvolvimentoAprigio,代碼行數:7,代碼來源:ServiceInterviewTest.cs

示例15: InvokeTest

        public async Task InvokeTest()
        {
            var mr = new MockRepository(MockBehavior.Strict);
            var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware) null);
            var ctx = mr.Create<IOwinContext>();
            var logger = mr.Create<ILog>();
            var exception = new Exception();

            logger.Setup(x => x.Fatal(It.IsAny<object>(), exception)).Verifiable();
            next.Setup(x => x.Invoke(ctx.Object)).Returns(async () =>
            {
                await Task.Delay(1);
                throw exception;
            }).Verifiable();

            var mw = new ExceptionHandlerMiddleware(next.Object, logger.Object);
            try
            {
                await mw.Invoke(ctx.Object);
            }
            catch (Exception e)
            {
                Assert.AreEqual(exception, e);
            }

            mr.VerifyAll();
        }
開發者ID:riberk,項目名稱:Rib.Common,代碼行數:27,代碼來源:ExceptionHandlerMiddlewareTests.cs


注:本文中的Moq.MockRepository類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。