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


C# DynamicMock.ExpectAndReturn方法代码示例

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


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

示例1: StartCruiseServerProject

		public void StartCruiseServerProject()
		{
			ConsoleRunnerArguments consoleArgs = new ConsoleRunnerArguments();
			Mock mockCruiseServer = new DynamicMock(typeof(ICruiseServer));
			mockCruiseServer.Expect("Start");
			mockCruiseServer.Expect("WaitForExit");
			Mock mockCruiseServerFactory = new DynamicMock(typeof(ICruiseServerFactory));
			mockCruiseServerFactory.ExpectAndReturn("Create", mockCruiseServer.MockInstance, consoleArgs.UseRemoting, consoleArgs.ConfigFile);

			new ConsoleRunner(consoleArgs, (ICruiseServerFactory)mockCruiseServerFactory.MockInstance).Run();

			mockCruiseServer.Verify();
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:13,代码来源:ConsoleRunnerTest.cs

示例2: AdjustScrollRange

		public void AdjustScrollRange()
		{
			DynamicMock rootBox = new DynamicMock(typeof(IVwRootBox));
			// This was taken out because it doesn't seem like the views code does this
			// anymore. It just calls AdjustScrollRange for the original view that changed.
			// Done as a part of TE-3576
			//// result for style pane
			//rootBox.ExpectAndReturn("Height", 900);
			//rootBox.ExpectAndReturn("Width", 100);
			//rootBox.ExpectAndReturn("Height", 1000);
			//rootBox.ExpectAndReturn("Width", 100);
			//rootBox.ExpectAndReturn("Height", 1000);
			//rootBox.ExpectAndReturn("Width", 100);
			//// result for draft pane
			//rootBox.ExpectAndReturn("Height", 950);
			//rootBox.ExpectAndReturn("Width", 100);
			//rootBox.ExpectAndReturn("Height", 900);
			//rootBox.ExpectAndReturn("Width", 100);
			//rootBox.ExpectAndReturn("Height", 1000);
			//rootBox.ExpectAndReturn("Width", 100);
			// result for bt pane
			rootBox.ExpectAndReturn("Height", 1100);
			rootBox.ExpectAndReturn("Width", 100);
			rootBox.ExpectAndReturn("Height", 900);
			rootBox.ExpectAndReturn("Width", 100);
			rootBox.ExpectAndReturn("Height", 950);
			rootBox.ExpectAndReturn("Width", 100);

			using (RootSiteGroup group = new RootSiteGroup())
			{
				DummyBasicView stylePane = new DummyBasicView();
				DummyBasicView draftPane = new DummyBasicView();
				DummyBasicView btPane = new DummyBasicView();

				PrepareView(stylePane, 50, 300, (IVwRootBox)rootBox.MockInstance);
				PrepareView(draftPane, 150, 300, (IVwRootBox)rootBox.MockInstance);
				PrepareView(btPane, 150, 300, (IVwRootBox)rootBox.MockInstance);

				group.AddToSyncGroup(stylePane);
				group.AddToSyncGroup(draftPane);
				group.AddToSyncGroup(btPane);
				group.ScrollingController = btPane;
				group.Controls.AddRange(new Control[] { stylePane, draftPane, btPane } );

				btPane.ScrollMinSize = new Size(100, 1000);
				btPane.ScrollPosition = new Point(0, 700);

				// now call AdjustScrollRange on each of the panes.
				// This simulates what the views code does.
				// This was taken out because it doesn't seem like the views code does this
				// anymore. It just calls AdjustScrollRange for the original view that changed.
				// Done as a part of TE-3576
				//stylePane.AdjustScrollRange(null, 0, 0, -100, 500);
				//draftPane.AdjustScrollRange(null, 0, 0, -50, 500);
				btPane.AdjustScrollRange(null, 0, 0, 100, 500);

				Assert.AreEqual(1108, btPane.ScrollMinSize.Height, "Wrong ScrollMinSize");
				Assert.AreEqual(800, -btPane.ScrollPosition.Y, "Wrong scroll position");
			}
		}
开发者ID:sillsdev,项目名称:WorldPad,代码行数:60,代码来源:RootSiteGroupTests.cs

示例3: ViewManagerCreateView

        public void ViewManagerCreateView()
        {
            #region Mock intialization

            DynamicMock useCase = new DynamicMock(typeof(IUseCase));
            DynamicMock engine = new DynamicMock(typeof(IRegexEngine));
            DynamicMock view = new DynamicMock(typeof(IRegexView));

            IRegexView viewMockInstance = (IRegexView)view.MockInstance;
            IUseCase useCaseMockInstance = (IUseCase)useCase.MockInstance;
            IRegexEngine engineMockInstance = (IRegexEngine)engine.MockInstance;

            #endregion

            useCase.ExpectAndReturn("CreateNewView", viewMockInstance);
            useCase.ExpectAndReturn("CreateNewEngine", engineMockInstance);
            engine.Expect("AttachView", withSameObjectAs(viewMockInstance));
            view.Expect("Init", withSameObjectAs(engineMockInstance));

            ViewManager factory = new ViewManager();
            IRegexView newView = factory.CreateView(useCaseMockInstance);

            useCase.Verify();
            engine.Verify();
            view.Verify();

            Assert.AreSame(newView, viewMockInstance,"Returned view is not the same instance as expected");
        }
开发者ID:Nullstr1ng,项目名称:dotnet-regex-tools,代码行数:28,代码来源:ViewFactoryTests.cs

示例4: SetupAndTeardownRemotingInfrastructure

		public void SetupAndTeardownRemotingInfrastructure()
		{
			string configFile = CreateTemporaryConfigurationFile();

			IMock mockCruiseManager = new RemotingMock(typeof (ICruiseManager));
			IMock mockCruiseServer = new DynamicMock(typeof (ICruiseServer));
			mockCruiseServer.ExpectAndReturn("CruiseManager", mockCruiseManager.MockInstance);
			mockCruiseServer.ExpectAndReturn("CruiseManager", mockCruiseManager.MockInstance);
			mockCruiseServer.Expect("Dispose");

			using (new RemoteCruiseServer((ICruiseServer) mockCruiseServer.MockInstance, configFile))
			{
				Assert.AreEqual(2, ChannelServices.RegisteredChannels.Length);
				Assert.IsNotNull(ChannelServices.GetChannel("ccnet"), "ccnet channel is missing");
				Assert.IsNotNull(ChannelServices.GetChannel("ccnet2"), "ccnet2 channel is missing");

				ICruiseManager remoteManager = (ICruiseManager) RemotingServices.Connect(typeof (ICruiseManager), "tcp://localhost:35354/" + RemoteCruiseServer.ManagerUri);
				Assert.IsNotNull(remoteManager, "cruiseserver should be registered on tcp channel");

				remoteManager = (ICruiseManager) RemotingServices.Connect(typeof (ICruiseManager), "http://localhost:35355/" + RemoteCruiseServer.ManagerUri);
				Assert.IsNotNull(remoteManager, "cruiseserver should be registered on http channel");
			}
			Assert.AreEqual(0, ChannelServices.RegisteredChannels.Length, "all registered channels should be closed.");
			mockCruiseServer.Verify();
			mockCruiseManager.Verify();
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:26,代码来源:RemoteCruiseServerTest.cs

示例5: InvalidPortName

 public void InvalidPortName()
 {
     Mock source = new DynamicMock(typeof(IUnmanagedSource));
     source.ExpectAndReturn("CreateFile", new IntPtr(2), null, null, null, null, null, null, null, null);
     source.ExpectAndReturn("GetFileType", FileType.Disk, new IntPtr(2));
     UnmanagedProvider.Source = (IUnmanagedSource) source.MockInstance;
     new PortStream("xpto");
     source.Verify();
 }
开发者ID:davidajulio,项目名称:hx,代码行数:9,代码来源:TestPortStream.cs

示例6: DefaultPowerShellShouldBe1IfNothingNewerInstalled

        public void DefaultPowerShellShouldBe1IfNothingNewerInstalled()
        {
            IMock mockRegistry2 = new DynamicMock(typeof(IRegistry));

            PowerShellTask task = new PowerShellTask((IRegistry)mockRegistry2.MockInstance, (ProcessExecutor)mockProcessExecutor.MockInstance);
            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", null, PowerShellTask.regkeypowershell2, PowerShellTask.regkeyholder);
            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", POWERSHELL1_PATH,
                                         PowerShellTask.regkeypowershell1, PowerShellTask.regkeyholder);
            Assert.AreEqual(POWERSHELL1_PATH + "\\powershell.exe", task.Executable);
            mockRegistry2.Verify();
            mockProcessExecutor.Verify();
        }
开发者ID:derrills1,项目名称:ccnet_gitmode,代码行数:12,代码来源:PowerShellTaskTest.cs

示例7: ShouldDelegateForEachFileAndSeparateWithLineBreaks

		public void ShouldDelegateForEachFileAndSeparateWithLineBreaks()
		{
			DynamicMock delegateMock = new DynamicMock(typeof(ITransformer));
			HtmlAwareMultiTransformer transformer = new HtmlAwareMultiTransformer((ITransformer) delegateMock.MockInstance);

			string input = "myinput";

			delegateMock.ExpectAndReturn("Transform", @"<p>MyFirstOutput<p>",  input, "xslFile1", null);
			delegateMock.ExpectAndReturn("Transform", @"<p>MySecondOutput<p>",  input, "xslFile2", null);

			Assert.AreEqual(@"<p>MyFirstOutput<p><p>MySecondOutput<p>", transformer.Transform(input, new string[] { "xslFile1", "xslFile2" }, null));
			delegateMock.Verify();
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:13,代码来源:HtmlAwareMultiTransformerTest.cs

示例8: ShouldCallDelegateTransformerWithCorrectFileNames

		public void ShouldCallDelegateTransformerWithCorrectFileNames()
		{
			DynamicMock delegateMock = new DynamicMock(typeof(IMultiTransformer));
			DynamicMock pathProviderStub = new DynamicMock(typeof(IPhysicalApplicationPathProvider));

			PathMappingMultiTransformer transformer = new PathMappingMultiTransformer((IPhysicalApplicationPathProvider) pathProviderStub.MockInstance, (IMultiTransformer) delegateMock.MockInstance);

            pathProviderStub.ExpectAndReturn("GetFullPathFor", @"c:\myAppPath\xslFile1", "xslFile1");
            pathProviderStub.ExpectAndReturn("GetFullPathFor", @"c:\myAppPath\xslFile2", "xslFile2");

			delegateMock.ExpectAndReturn("Transform", "output", "myInput", new string[] { @"c:\myAppPath\xslFile1", @"c:\myAppPath\xslFile2" }, null);

			Assert.AreEqual("output", transformer.Transform("myInput", new string[] { "xslFile1", "xslFile2"}, null));
			pathProviderStub.Verify();
			delegateMock.Verify();
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:16,代码来源:PathMappingMultiTransformerTest.cs

示例9: ShouldOnlyDisposeOnce

		public void ShouldOnlyDisposeOnce()
		{
			string configFile = CreateTemporaryConfigurationFile();
			IMock mockCruiseManager = new RemotingMock(typeof (ICruiseManager));
			IMock mockCruiseServer = new DynamicMock(typeof (ICruiseServer));
			mockCruiseServer.ExpectAndReturn("CruiseManager", mockCruiseManager.MockInstance);
			mockCruiseServer.ExpectAndReturn("CruiseManager", mockCruiseManager.MockInstance);
			mockCruiseServer.Expect("Dispose");

			RemoteCruiseServer server = new RemoteCruiseServer((ICruiseServer) mockCruiseServer.MockInstance, configFile);
			((IDisposable)server).Dispose();

			mockCruiseServer.ExpectNoCall("Dispose");
			((IDisposable)server).Dispose();
			mockCruiseServer.Verify();
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:16,代码来源:RemoteCruiseServerTest.cs

示例10: ShouldOnlyAllowOneThreadToResolveEachType

		public void ShouldOnlyAllowOneThreadToResolveEachType()
		{
			TypeToTypeMap sharedMap = new HashtableTypeMap(Hashtable.Synchronized(new Hashtable()));
			
			DynamicMock expectedToBeUsed = new DynamicMock(typeof(ImplementationResolver));
			expectedToBeUsed.ExpectAndReturn("ResolveImplementation", typeof(TestClass), typeof(TestInterface));
			DynamicMock notExpectedToBeUsed = new DynamicMock(typeof(ImplementationResolver));
			notExpectedToBeUsed.ExpectNoCall("ResolveImplementation", typeof(Type));

			StallingImplementationResolver stallingResolver = new StallingImplementationResolver((ImplementationResolver) expectedToBeUsed.MockInstance);
			ImplementationResolver resolvingResolver = new CachingImplementationResolver(
				stallingResolver, sharedMap);
			ImplementationResolver moochingResolver = new CachingImplementationResolver((ImplementationResolver) notExpectedToBeUsed.MockInstance, sharedMap);

			ImplementationResolverRunner resolvingRunner = new ImplementationResolverRunner(resolvingResolver, typeof(TestInterface));
			Thread resolvingThread = new Thread(
				new ThreadStart(resolvingRunner.runResolution));
			ImplementationResolverRunner moochingRunner = new ImplementationResolverRunner(moochingResolver, typeof(TestInterface));
			Thread moochingThread = new Thread(
				new ThreadStart(moochingRunner.runResolution));

			resolvingThread.Start();
			moochingThread.Start();
			Thread.Sleep(500); // allow moochingThread to catch up to resolvingThread
			stallingResolver.Resume();
			
			Assert.IsTrue(resolvingThread.Join(200), "Resolving thread did not complete before timeout.");
			Assert.IsTrue(moochingThread.Join(200), "Mooching thread did not complete before timeout.");
			
			expectedToBeUsed.Verify();
			notExpectedToBeUsed.Verify();

			Assert.AreEqual(typeof(TestClass), resolvingRunner.implementationType);
			Assert.AreEqual(typeof(TestClass), moochingRunner.implementationType);
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:35,代码来源:CachingImplementationResolverTest.cs

示例11: ShouldUseBuildLogTransformerToGenerateView

		public void ShouldUseBuildLogTransformerToGenerateView()
		{
			DynamicMock buildLogTransformerMock = new DynamicMock(typeof(IBuildLogTransformer));
			DynamicMock cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest));
			DynamicMock buildSpecifierMock = new DynamicMock(typeof(IBuildSpecifier));
			DynamicMock requestStub = new DynamicMock(typeof(IRequest));

			ICruiseRequest cruiseRequest = (ICruiseRequest) cruiseRequestMock.MockInstance;
			IBuildSpecifier buildSpecifier = (IBuildSpecifier) buildSpecifierMock.MockInstance;
			IRequest request = (IRequest) requestStub.MockInstance;

			cruiseRequestMock.ExpectAndReturn("BuildSpecifier", buildSpecifier);
			cruiseRequestMock.SetupResult("Request", request);
			requestStub.SetupResult("ApplicationPath", "myAppPath");
			Hashtable expectedXsltArgs = new Hashtable();
			expectedXsltArgs["applicationPath"] = "myAppPath";
			buildLogTransformerMock.ExpectAndReturn("Transform", "transformed", buildSpecifier, new string[] { @"xsl\myxsl.xsl" }, new HashtableConstraint(expectedXsltArgs), null);

			XslReportBuildAction action = new XslReportBuildAction((IBuildLogTransformer) buildLogTransformerMock.MockInstance, null);
			action.XslFileName = @"xsl\myxsl.xsl";

			Assert.AreEqual("transformed", ((HtmlFragmentResponse)action.Execute(cruiseRequest)).ResponseFragment);

			buildLogTransformerMock.Verify();
			cruiseRequestMock.Verify();
			buildSpecifierMock.Verify();
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:27,代码来源:XslReportActionTest.cs

示例12: ShouldBeAbleToSaveProjectsThatALoaderCanLoad

		public void ShouldBeAbleToSaveProjectsThatALoaderCanLoad()
		{
			ExecutableTask builder = new ExecutableTask();
			builder.Executable = "foo";
			FileSourceControl sourceControl = new FileSourceControl();
			sourceControl.RepositoryRoot = "bar";
			// Setup
			Project project1 = new Project();
			project1.Name = "Project One";
			project1.SourceControl = sourceControl;
			Project project2 = new Project();
			project2.Name = "Project Two";
			project2.SourceControl = sourceControl;
			ProjectList projectList = new ProjectList();
			projectList.Add(project1);
			projectList.Add(project2);

			DynamicMock mockConfiguration = new DynamicMock(typeof(IConfiguration));
			mockConfiguration.ExpectAndReturn("Projects", projectList);

			FileInfo configFile = new FileInfo(TempFileUtil.CreateTempFile(TempFileUtil.CreateTempDir(this), "loadernet.config"));

			// Execute
			DefaultConfigurationFileSaver saver = new DefaultConfigurationFileSaver(new NetReflectorProjectSerializer());
			saver.Save((IConfiguration) mockConfiguration.MockInstance, configFile);

			DefaultConfigurationFileLoader loader = new DefaultConfigurationFileLoader();
			IConfiguration configuration2 = loader.Load(configFile);

			// Verify
			Assert.IsNotNull (configuration2.Projects["Project One"]);
			Assert.IsNotNull (configuration2.Projects["Project Two"]);
			mockConfiguration.Verify();
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:34,代码来源:ConfigurationFileSaverTest.cs

示例13: ViewManagerCreateView

        public void ViewManagerCreateView()
        {
            DynamicMock useCase = new DynamicMock(typeof(IUseCase));
            IUseCase useCaseMockInstance = (IUseCase)useCase.MockInstance;

            IRegexEngine engine = new DotNetRegexEngine();
            IRegexView view = new ReplaceView();

            useCase.ExpectAndReturn("CreateNewView", view);
            useCase.ExpectAndReturn("CreateNewEngine", engine);

            ViewManager factory = new ViewManager();
            IRegexView newView = factory.CreateView(useCaseMockInstance);
            Form frm = (Form)newView;
            frm.ShowDialog();
        }
开发者ID:Nullstr1ng,项目名称:dotnet-regex-tools,代码行数:16,代码来源:ReplaceUseCaseTests.cs

示例14: TestSimpleSmtpNegotiation

		public void TestSimpleSmtpNegotiation()
		{
			SmtpServer smtpserver=new SmtpServer("localhost");
			EmailMessage emailMessage=GetTestHtmlAndTextMessage();

			IMock mockSmtpProxy = new DynamicMock(typeof(ISmtpProxy));
			mockSmtpProxy.ExpectAndReturn("Open", new SmtpResponse(220, "welcome to the mock object server"), null);
			mockSmtpProxy.ExpectAndReturn("Helo", new SmtpResponse(250, "helo"), Dns.GetHostName());
			mockSmtpProxy.ExpectAndReturn("MailFrom", new SmtpResponse(250, "mail from"), emailMessage.FromAddress);
			foreach (EmailAddress rcpttoaddr in emailMessage.ToAddresses) 
			{
				mockSmtpProxy.ExpectAndReturn("RcptTo", new SmtpResponse(250, "receipt to"), rcpttoaddr);
			}
			mockSmtpProxy.ExpectAndReturn("Data", new SmtpResponse(354, "data open"), null);
			mockSmtpProxy.ExpectAndReturn("WriteData", new SmtpResponse(250, "data"), emailMessage.ToDataString());
			
			mockSmtpProxy.ExpectAndReturn("Quit", new SmtpResponse(221, "quit"), null);
			mockSmtpProxy.Expect("Close", null);

			ISmtpProxy smtpProxy= (ISmtpProxy) mockSmtpProxy.MockInstance;
			

			smtpserver.OverrideSmtpProxy(smtpProxy);

			
			emailMessage.Send(smtpserver);


		}
开发者ID:dineshkummarc,项目名称:DotNetOpenMail-0.5.8b-src,代码行数:29,代码来源:SmtpServerTests.cs

示例15: MethodsAndPropertiesDoSimpleDelagationOntoInjectedMonitor

		public void MethodsAndPropertiesDoSimpleDelagationOntoInjectedMonitor()
		{
			DynamicMock mockServerMonitor = new DynamicMock(typeof (ISingleServerMonitor));

			SynchronizedServerMonitor monitor = new SynchronizedServerMonitor(
				(ISingleServerMonitor) mockServerMonitor.MockInstance, null);

			mockServerMonitor.ExpectAndReturn("ServerUrl", @"tcp://blah/");
			Assert.AreEqual(@"tcp://blah/", monitor.ServerUrl);

			mockServerMonitor.ExpectAndReturn("IsConnected", true);
			Assert.AreEqual(true, monitor.IsConnected);

			mockServerMonitor.Expect("Poll");
			monitor.Poll();

			mockServerMonitor.Verify();
		}
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:18,代码来源:SynchronizedServerMonitorTest.cs


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