本文整理汇总了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();
}
示例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();
}
示例3: Create
public void Create(params string[] lines)
{
_textBuffer = EditorUtil.CreateTextBuffer(lines);
_factory = new MockRepository(MockBehavior.Strict);
_adapterRaw = new ResharperExternalEditAdapter();
_adapter = _adapterRaw;
}
示例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>[] { });
}
示例5: Setup
public void Setup()
{
_candidate = ObjectMother.GetCandidate();
_mockRepository = new MockRepository(MockBehavior.Default);
_candidateRepoMock = _mockRepository.Create<ICandidateRepository>();
_service = new CandidateService(_candidateRepoMock.Object);
}
示例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);
}
示例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);
}
示例8: ReportDesignerUtilTest
protected ReportDesignerUtilTest()
{
_factory = new MockRepository(MockBehavior.Strict);
_vsEditorAdaptersFactoryService = _factory.Create<IVsEditorAdaptersFactoryService>();
_reportDesignerUtilRaw = new ReportDesignerUtil(_vsEditorAdaptersFactoryService.Object);
_reportDesignerUtil = _reportDesignerUtilRaw;
}
示例9: Create
public void Create(params string[] lines)
{
_textBuffer = CreateTextBuffer(lines);
_factory = new MockRepository(MockBehavior.Strict);
_reSharperUtilRaw = new ReSharperUtil(isResharperInstalled: true);
_reSharperUtil = _reSharperUtilRaw;
}
示例10: CreateVsTextLineMarker
public static Mock<IVsTextLineMarker> CreateVsTextLineMarker(
TextSpan span,
MARKERTYPE type,
MockRepository factory = null)
{
return CreateVsTextLineMarker(span, (int)type, factory);
}
示例11: UserBusinessLogicTests
public UserBusinessLogicTests()
{
MockFactory = new MockRepository(MockBehavior.Loose) { DefaultValue = DefaultValue.Mock };
MockedUserBusinessLogic = MockFactory.Create<IUserBusinessLogic>();
MockedUserRepository = MockFactory.Create<IUserRepository>();
}
示例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;
}
示例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;
}
示例14: Setup
public void Setup()
{
_interview = ObjectMother.GetInterview();
_mockRepository = new MockRepository(MockBehavior.Default);
_interviewRepoMoq = _mockRepository.Create<IInterviewRepository>();
_service = new InterviewService(_interviewRepoMoq.Object);
}
示例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();
}