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


C# MockRepository.CreateMock方法代码示例

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


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

示例1: Correctly_constructs_action_executors

		public void Correctly_constructs_action_executors()
		{
			DatabaseAction[] actions = new DatabaseAction[] { DatabaseAction.Create, DatabaseAction.Update };

			MockRepository mocks = new MockRepository();
			IDatabaseActionResolver resolver = mocks.CreateMock<IDatabaseActionResolver>();
            IDataBaseActionLocator locator = mocks.CreateMock<IDataBaseActionLocator>();

			IDatabaseActionExecutor creator = mocks.CreateMock<IDatabaseActionExecutor>();
			IDatabaseActionExecutor updater = mocks.CreateMock<IDatabaseActionExecutor>();

			using (mocks.Record())
			{
				Expect.Call(resolver.GetActions(RequestedDatabaseAction.Create)).Return(actions);
				Expect.Call(locator.CreateInstance(DatabaseAction.Create)).Return(creator);
				Expect.Call(locator.CreateInstance(DatabaseAction.Update)).Return(updater);
			}

			using (mocks.Playback())
			{
				IDatabaseActionExecutorFactory factory = new DatabaseActionExecutorFactory(resolver, locator);
				IEnumerable<IDatabaseActionExecutor> executors = factory.GetExecutors(RequestedDatabaseAction.Create);
				IList<IDatabaseActionExecutor> executorList = new List<IDatabaseActionExecutor>(executors);

				Assert.That(executorList, Is.EqualTo(new IDatabaseActionExecutor[]{ creator, updater }));		
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:29,代码来源:DatabaseActionExecutorFactoryTester.cs

示例2: Constructs_deployment

		public void Constructs_deployment()
		{
			var mocks = new MockRepository();
			var clock = mocks.CreateMock<ISystemClock>();
			var resultCalculator = mocks.CreateMock<IDeploymentResultCalculator>();

			using (mocks.Record())
			{
				Expect.Call(clock.GetCurrentDateTime()).Return(new DateTime(2007, 4, 15));
			}

			using (mocks.Playback())
			{
				IDeploymentFactory factory = new DeploymentFactory(clock, resultCalculator);
				Deployment deployment = factory.CreateDeployment("A1", "E1", "jsmith", "Output...", "1.0", true);

				Assert.That(deployment.Application, Is.EqualTo("A1"));
				Assert.That(deployment.Environment, Is.EqualTo("E1"));
				Assert.That(deployment.DeployedBy, Is.EqualTo("jsmith"));
				Assert.That(deployment.DeployedOn, Is.EqualTo(new DateTime(2007, 4, 15)));
				Assert.That(deployment.Version, Is.EqualTo("1.0"));
				Assert.That(deployment.Output.Output, Is.EqualTo("Output..."));
				Assert.That(deployment.Result, Is.SameAs(DeploymentResult.Failure));
				Assert.That(deployment.Output.Deployment, Is.SameAs(deployment));
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:28,代码来源:DeploymentFactoryTester.cs

示例3: Creates_new_application_instance

		public void Creates_new_application_instance()
		{
			MockRepository mocks = new MockRepository();
			ISystemEnvironment systemEnvironment = mocks.CreateMock<ISystemEnvironment>();
			IAssemblyContext context = mocks.CreateMock<IAssemblyContext>();
			IConfigurationReader configurationReader = mocks.CreateMock<IConfigurationReader>();

			using (mocks.Record())
			{
				Expect.Call(context.GetAssemblyVersion()).Return("1.0");
				Expect.Call(systemEnvironment.GetMachineName()).Return("MyMachine");
				Expect.Call(configurationReader.GetRequiredSetting("TarantinoWebManagementHttpHost")).Return("www.myapp.com");
			}

			using (mocks.Playback())
			{
				IApplicationInstanceFactory factory = new ApplicationInstanceFactory(systemEnvironment, context, configurationReader);
				ApplicationInstance instance = factory.Create();

				Assert.That(instance.AvailableForLoadBalancing, Is.True);
				Assert.That(instance.MachineName, Is.EqualTo("MyMachine"));
				Assert.That(instance.Version, Is.EqualTo("1.0"));
				Assert.That(instance.MaintenanceHostHeader, Is.EqualTo("www.myapp.com"));
				Assert.That(instance.ApplicationDomain, Is.EqualTo("www.myapp.com"));
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:28,代码来源:ApplicationInstanceFactoryTester.cs

示例4: Can_read_worksheet_from_excel_workbook

		public void Can_read_worksheet_from_excel_workbook()
		{
			string excelFile = "MyWorkbook.xls";
			MemoryStream excelFileStream = new MemoryStream();

			DataSet workbook = createWorkbook();

			MockRepository mocks = new MockRepository();
			IFileSystem fileSystem = mocks.CreateMock<IFileSystem>();
			IExcelWorkbookReader workbookReader = mocks.CreateMock<IExcelWorkbookReader>();

			Expect.Call(fileSystem.ReadIntoFileStream(excelFile)).Return(excelFileStream);
			Expect.Call(workbookReader.GetWorkbookData(excelFileStream)).Return(workbook);

			mocks.ReplayAll();

			IExcelWorksheetReader worksheetReader = new ExcelWorksheetReader(fileSystem, workbookReader);
			DataTable myWorksheet = worksheetReader.GetWorksheet(excelFile, "MyWorksheet");

			Assert.That(myWorksheet, Is.Not.Null);
			Assert.That(myWorksheet.Columns.Count, Is.EqualTo(2));
			Assert.That(myWorksheet.Columns[0].ColumnName, Is.EqualTo("First Column"));
			Assert.That(myWorksheet.Columns[1].ColumnName, Is.EqualTo("Second Column"));

			Assert.That(myWorksheet.Rows.Count, Is.EqualTo(2));
			Assert.That(myWorksheet.Rows[0]["First Column"], Is.EqualTo("Row 1 - First Column Value"));
			Assert.That(myWorksheet.Rows[0]["Second Column"], Is.EqualTo("Row 1 - Second Column Value"));
			Assert.That(myWorksheet.Rows[1]["First Column"], Is.EqualTo("Row 2 - First Column Value"));
			Assert.That(myWorksheet.Rows[1]["Second Column"], Is.EqualTo("Row 2 - Second Column Value"));

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:32,代码来源:ExcelWorksheetReaderTester.cs

示例5: Correctly_handles_when_service_agent_aggregator_throws_exception

		public void Correctly_handles_when_service_agent_aggregator_throws_exception()
		{
			ApplicationException exception = new ApplicationException();

			MockRepository mocks = new MockRepository();
			IApplicationSettings settings = mocks.CreateMock<IApplicationSettings>();
			IServiceAgentAggregator aggregator = mocks.CreateMock<IServiceAgentAggregator>();

			IServiceRunner runner = new ServiceRunner(aggregator, settings);

			using (mocks.Record())
			{

				aggregator.ExecuteServiceAgentCycle();
				LastCall.Throw(exception);

			}

			using (mocks.Playback())
			{
				runner.Start();
				Thread.Sleep(500);
				runner.Stop();
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:27,代码来源:ServiceRunnerTester.cs

示例6: Run_service

		public void Run_service()
		{
			MockRepository mocks = new MockRepository();
			IApplicationSettings settings = mocks.CreateMock<IApplicationSettings>();
			IServiceAgentAggregator aggregator = mocks.CreateMock<IServiceAgentAggregator>();

			IServiceRunner runner = new ServiceRunner(aggregator, settings);

			using (mocks.Record())
			{


				aggregator.ExecuteServiceAgentCycle();
				LastCall.Repeat.Times(2, int.MaxValue);

				Expect.Call(settings.GetServiceSleepTime()).Return(10);
				LastCall.Repeat.Times(2, int.MaxValue);

			}

			using (mocks.Playback())
			{
				runner.Start();
				Thread.Sleep(500);
				runner.Stop();
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:29,代码来源:ServiceRunnerTester.cs

示例7: Correctly_build_menu_view

		public void Correctly_build_menu_view()
		{
			MockRepository mocks = new MockRepository();
			IResourceFileLocator locator = mocks.CreateMock<IResourceFileLocator>();
			ITokenReplacer replacer = mocks.CreateMock<ITokenReplacer>();

			using (mocks.Record())
			{
				string htmlTemplate = "||APPLICATION_URL|| ||CACHE_URL|| ||ASSEMBLY_URL|| ||LOADBALANCER_URL|| ||DISABLE_URL||";
				Expect.Call(locator.ReadTextFile("Tarantino.Core", MenuView.MenuTemplate)).Return(htmlTemplate);
				replacer.Text = htmlTemplate;

				replacer.Replace("APPLICATION_URL", "Tarantino.WebManagement.Application.axd");
				replacer.Replace("CACHE_URL", "Tarantino.WebManagement.Cache.axd");
				replacer.Replace("ASSEMBLY_URL", "Tarantino.WebManagement.Assemblies.axd");
				replacer.Replace("LOADBALANCER_URL", "Tarantino.WebManagement.LoadBalancer.axd");
				replacer.Replace("DISABLE_URL", "Tarantino.WebManagement.DisableSSL.axd");

				Expect.Call(replacer.Text).Return("fully formatted html");
			}

			using (mocks.Playback())
			{
				IMenuView menuView = new MenuView(locator, replacer);
				string html = menuView.BuildHtml();

				Assert.That(html, Is.EqualTo("fully formatted html"));
			}
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:29,代码来源:MenuViewTester.cs

示例8: SetUp

 public void SetUp()
 {
     mocker = new MockRepository();
     service = mocker.PartialMock<HarvestService>();
     harvestor = mocker.CreateMock<IHarvester>();
     scripter = mocker.CreateMock<ISqlScripter>();
 }
开发者ID:TheCodeKing,项目名称:SqlHarvester.Net,代码行数:7,代码来源:HarvestServiceTestFixture.cs

示例9: Records_deployment

		public void Records_deployment()
		{
			var deployment = new Deployment{ Version = "1.0"};

			var mocks = new MockRepository();
			var factory = mocks.CreateMock<IDeploymentFactory>();
			var repository = mocks.CreateMock<IDeploymentRepository>();
			var context = mocks.CreateMock<ISecurityContext>();

			using (mocks.Record())
			{
				Expect.Call(context.GetCurrentUsername()).Return("jsmith");
				Expect.Call(factory.CreateDeployment("application", "environment", "jsmith", "Output...", "1.0", false)).Return(deployment);
				repository.Save(deployment);
			}

			using (mocks.Playback())
			{
				IDeploymentRecorder recorder = new DeploymentRecorder(context, factory, repository);
				var version = recorder.RecordDeployment("application", "environment", "Output...", "1.0", false);

				Assert.That(version, Is.EqualTo("1.0"));
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:26,代码来源:DeploymentRecorderTester.cs

示例10: JustPassesAfterReturningAdviceExceptionUpWithoutAnyWrapping

		public void JustPassesAfterReturningAdviceExceptionUpWithoutAnyWrapping()
		{

            MockRepository repository = new MockRepository();
            IMethodInvocation mockInvocation = (IMethodInvocation)repository.CreateMock(typeof(IMethodInvocation));
		    IAfterReturningAdvice mockAdvice = (IAfterReturningAdvice) repository.CreateMock(typeof (IAfterReturningAdvice));
		    mockAdvice.AfterReturning(null,null,null,null);
		    LastCall.IgnoreArguments();
		    LastCall.Throw(new FormatException());

            Expect.Call(mockInvocation.Method).Return(ReflectionUtils.GetMethod(typeof(object), "HashCode", new Type[] { }));
            Expect.Call(mockInvocation.Arguments).Return(null);
            Expect.Call(mockInvocation.This).Return(new object());           
		    Expect.Call(mockInvocation.Proceed()).Return(null);

            repository.ReplayAll();

            try
            {
                AfterReturningAdviceInterceptor interceptor = new AfterReturningAdviceInterceptor(mockAdvice);
                interceptor.Invoke(mockInvocation);
                Assert.Fail("Must have thrown a FormatException by this point.");
            }
            catch (FormatException)
            {
            }
            repository.VerifyAll();





		}
开发者ID:spring-projects,项目名称:spring-net,代码行数:33,代码来源:AfterReturningAdviceInterceptorTests.cs

示例11: Correctly_drops_connections

		public void Correctly_drops_connections()
		{
			string assembly = SqlDatabaseManager.SQL_FILE_ASSEMBLY;
			string sqlFile = string.Format(SqlDatabaseManager.SQL_FILE_TEMPLATE, "DropConnections");

			ConnectionSettings settings = new ConnectionSettings("server", "MyDatabase", true, null, null);

			MockRepository mocks = new MockRepository();

			ITaskObserver taskObserver = mocks.CreateMock<ITaskObserver>();			
			IResourceFileLocator fileLocator = mocks.CreateMock<IResourceFileLocator>();
			ITokenReplacer replacer = mocks.CreateMock<ITokenReplacer>();
			IQueryExecutor queryExecutor = mocks.CreateMock<IQueryExecutor>();

			using (mocks.Record())
			{
				taskObserver.Log("Dropping connections for database MyDatabase\n");
				Expect.Call(fileLocator.ReadTextFile(assembly, sqlFile)).Return("Unformatted SQL");
				replacer.Text = "Unformatted SQL";
				replacer.Replace("DatabaseName", "MyDatabase");
				Expect.Call(replacer.Text).Return("Formatted SQL");
				queryExecutor.ExecuteNonQuery(settings, "Formatted SQL", false);
			}

			using (mocks.Playback())
			{
				IDatabaseConnectionDropper dropper = new DatabaseConnectionDropper(fileLocator, replacer, queryExecutor);
				dropper.Drop(settings, taskObserver);
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:32,代码来源:DatabaseConnectionDropperTester.cs

示例12: Manages_database

		public void Manages_database()
		{
			var settings = new ConnectionSettings("server", "db", true, null, null);
            var scriptDirectory = @"c:\scripts"; 
            var taskAttributes = new TaskAttributes(settings, scriptDirectory);

			var mocks = new MockRepository();
			var taskObserver = mocks.CreateMock<ITaskObserver>();
			var generator = mocks.CreateMock<ILogMessageGenerator>();
			var factory = mocks.CreateMock<IDatabaseActionExecutorFactory>();

			var creator = mocks.CreateMock<IDatabaseActionExecutor>();
			var updater = mocks.CreateMock<IDatabaseActionExecutor>();

			var executors = new IDatabaseActionExecutor[] { creator, updater };

			using (mocks.Record())
			{
				Expect.Call(generator.GetInitialMessage(taskAttributes)).Return("starting...");
				taskObserver.Log("starting...");
				Expect.Call(factory.GetExecutors(RequestedDatabaseAction.Create)).Return(executors);

                creator.Execute(taskAttributes, taskObserver);
                updater.Execute(taskAttributes, taskObserver);
			}

			using (mocks.Playback())
			{
				ISqlDatabaseManager manager = new SqlDatabaseManager(generator, factory);

				manager.Upgrade(taskAttributes, taskObserver);
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:35,代码来源:SqlDatabaseManagerTester.cs

示例13: Should_enable_load_balancing_when_requested

		public void Should_enable_load_balancing_when_requested()
		{
			ApplicationInstance instance = new ApplicationInstance();
			instance.AvailableForLoadBalancing = false;

			MockRepository mocks = new MockRepository();
			IApplicationInstanceContext instanceContext = mocks.CreateMock<IApplicationInstanceContext>();
			IWebContext context = mocks.CreateMock<IWebContext>();
			ISecureAvailabilityStatusUpdater updater = mocks.CreateMock<ISecureAvailabilityStatusUpdater>();			

			using (mocks.Record())
			{
				Expect.Call(instanceContext.GetCurrent()).Return(instance);
				Expect.Call(context.GetRequestItem(LoadBalanceStatusManager.ENABLED_PARAM)).Return("True");
				Expect.Call(updater.SetStatus(true)).Return("My error message");
			}

			using (mocks.Playback())
			{
				ILoadBalanceStatusManager manager = new LoadBalanceStatusManager(instanceContext, context, updater);
				string errorMessage = manager.HandleLoadBalanceRequest();

				Assert.That(errorMessage, Is.EqualTo("My error message"));
			}
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:25,代码来源:LoadBalanceStatusManagerTester.cs

示例14: Versions_database

		public void Versions_database()
		{
			string assembly = SqlDatabaseManager.SQL_FILE_ASSEMBLY;
			string sqlFile = string.Format(SqlDatabaseManager.SQL_FILE_TEMPLATE, "VersionDatabase");

			ConnectionSettings settings = new ConnectionSettings(String.Empty, String.Empty, false, String.Empty, String.Empty);
			string sqlScript = "SQL script...";

			MockRepository mocks = new MockRepository();
			IResourceFileLocator fileLocator = mocks.CreateMock<IResourceFileLocator>();
			IQueryExecutor queryExecutor = mocks.CreateMock<IQueryExecutor>();
			ITaskObserver taskObserver = mocks.CreateMock<ITaskObserver>();

			using (mocks.Record())
			{
				Expect.Call(fileLocator.ReadTextFile(assembly, sqlFile)).Return(sqlScript);
				Expect.Call(queryExecutor.ExecuteScalarInteger(settings, sqlScript)).Return(7);
				taskObserver.SetVariable("usdDatabaseVersion", "7");
			}

			using (mocks.Playback())
			{
				IDatabaseVersioner versioner = new DatabaseVersioner(fileLocator, queryExecutor);
				versioner.VersionDatabase(settings, taskObserver);
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:28,代码来源:DatabaseVersionerTester.cs

示例15: Should_send_forgotten_password_email_when_email_address_exists

		public void Should_send_forgotten_password_email_when_email_address_exists()
		{
			MailMessage forgottenPasswordEmail = new MailMessage();

			MockRepository mocks = new MockRepository();
			ISystemUser user = mocks.CreateMock<ISystemUser>();
			IForgottenPasswordMailFactory mailFactory = mocks.CreateMock<IForgottenPasswordMailFactory>();
			ISystemUserRepository repository = mocks.CreateMock<ISystemUserRepository>();
			IEncryptionEngine encryptionEngine = mocks.CreateMock<IEncryptionEngine>();
			IMailSender sender = mocks.CreateMock<IMailSender>();

			using (mocks.Record())
			{
				Expect.Call(repository.GetByEmailAddress("[email protected]")).Return(user);
				Expect.Call(user.Password).Return("encryptedPassword");
				Expect.Call(encryptionEngine.Decrypt("encryptedPassword")).Return("clearTextPassword");

				Expect.Call(mailFactory.CreateEmail("[email protected]", "clearTextPassword")).Return(forgottenPasswordEmail);

				sender.SendMail(forgottenPasswordEmail);
			}

			using (mocks.Playback())
			{
				IForgottenPasswordMailer mailer = new ForgottenPasswordMailer(encryptionEngine, mailFactory, sender);
				bool emailWasSent = mailer.SendForgottenPasswordEmail("[email protected]", repository);
				Assert.That(emailWasSent);
			}

			mocks.VerifyAll();
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:31,代码来源:ForgottenPasswordMailerTester.cs


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