本文整理汇总了C#中Rhino.Mocks.MockRepository.Playback方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.Playback方法的具体用法?C# MockRepository.Playback怎么用?C# MockRepository.Playback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rhino.Mocks.MockRepository
的用法示例。
在下文中一共展示了MockRepository.Playback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_Capture_Then_Original_Filter_Is_Switched_And_PutBack
public void When_Capture_Then_Original_Filter_Is_Switched_And_PutBack()
{
var mocks = new MockRepository();
var context = mocks.DynamicMock<HttpContextBase>();
var response = mocks.DynamicMock<HttpResponseBase>();
var origFilter = mocks.DynamicMock<Stream>();
var action = mocks.DynamicMock<Action>();
using (mocks.Record())
{
SetupResult.For(context.Response).Return(response);
SetupResult.For(response.ContentEncoding).Return(Encoding.ASCII);
Expect.Call(response.Filter).Return(origFilter);
response.Filter = null;
LastCall.IgnoreArguments().Constraints(Rhino.Mocks.Constraints.Is.TypeOf(typeof(CapturingResponseFilter)));
response.Filter = origFilter;
}
using (mocks.Playback())
{
new BlockRenderer(context).Capture(action);
}
}
示例2: Select_Finds_FirstToSatisfyAllConstraints
public void Select_Finds_FirstToSatisfyAllConstraints()
{
var mockery = new MockRepository();
var constraint1 = mockery.StrictMock<IResidentConstraint>();
var constraint2 = mockery.StrictMock<IResidentConstraint>();
var selector = new ResidentSelector();
selector.Constraints.Clear();
selector.Constraints.Add(constraint1);
selector.Constraints.Add(constraint2);
var residents = new List<Resident> { new Resident(), new Resident(), new Resident() };
var shift = new Shift(DateTime.Today, DateTime.Today, DateTime.Today);
using (mockery.Record()) {
SetupResult.For(constraint1.Assignable(residents.First(), shift)).Return(false);
SetupResult.For(constraint2.Assignable(residents.First(), shift)).Return(true);
SetupResult.For(constraint1.Assignable(residents.Skip(1).First(), shift)).Return(true);
SetupResult.For(constraint2.Assignable(residents.Skip(1).First(), shift)).Return(false);
SetupResult.For(constraint1.Assignable(residents.Skip(2).First(), shift)).Return(true);
SetupResult.For(constraint2.Assignable(residents.Skip(2).First(), shift)).Return(true);
}
using (mockery.Playback()) {
Assert.AreEqual(residents.Skip(2).First(), selector.Select(residents, shift));
}
}
示例3: 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"));
}
}
示例4: NavigateTo
public void NavigateTo(bool simulateSuccess)
{
MockRepository mocks = new MockRepository();
IGallioNavigator navigator = mocks.StrictMock<IGallioNavigator>();
using (mocks.Record())
{
Expect.Call(navigator.NavigateTo(
@"C:\Source\MbUnit\v3\src\Gallio\Gallio.Tests\Reflection\Impl\CecilReflectionPolicyTest.cs", 5, 11))
.Return(simulateSuccess);
}
using (mocks.Playback())
{
InstrumentedProgram program = new InstrumentedProgram();
program.Engine = navigator;
int returnCode = program.Run(new string[]
{
@"gallio:navigateTo?path=C:\Source\MbUnit\v3\src\Gallio\Gallio.Tests\Reflection\Impl\CecilReflectionPolicyTest.cs&line=5&column=11"
});
Assert.IsFalse(program.HelpCalled);
Assert.AreEqual(simulateSuccess ? 0 : 1, returnCode);
mocks.VerifyAll();
}
}
示例5: SubmitAdRequestsAsync
public void SubmitAdRequestsAsync()
{
var mockery = new MockRepository();
var taskFactory = mockery.StrictMock<IVistarTaskFactory>();
var adRequestor = mockery.StrictMock<IAdRequestor>();
var adRequests = new List<AdRequest> {
new AdRequest(),
new AdRequest(),
new AdRequest()
};
var expectedTasks = new List<Task<List<Advertisement>>> {
new Task<List<Advertisement>>(null),
new Task<List<Advertisement>>(null),
new Task<List<Advertisement>>(null)
};
using (mockery.Record()) {
Expect.Call(taskFactory.StartNew(adRequestor.RunSubmitAdRequest, adRequests[0])).Return(expectedTasks[0]);
Expect.Call(taskFactory.StartNew(adRequestor.RunSubmitAdRequest, adRequests[1])).Return(expectedTasks[1]);
Expect.Call(taskFactory.StartNew(adRequestor.RunSubmitAdRequest, adRequests[2])).Return(expectedTasks[2]);
}
using (mockery.Playback()) {
var client = new ApiClientAsync(adRequestor, taskFactory);
var tasks = client.SubmitAdRequestsAsync(adRequests);
Assert.AreEqual(expectedTasks, tasks);
}
}
示例6: PublishDomainEvents
public void PublishDomainEvents()
{
var e = new TestEvent();
var mockRepository = new MockRepository();
IEnumerable<object> handlers;
using (mockRepository.Record())
{
var handler1 = mockRepository.StrictMock<IEventHandler<TestEvent>>();
handler1.Expect(h => h.Handle(e)).Repeat.Once();
var handler2 = mockRepository.StrictMock<IEventHandler<TestEvent>>();
handler2.Expect(h => h.Handle(e)).Repeat.Once();
handlers = new[] { handler1, handler2 };
}
MultiInstanceFactory multiInstanceFactory = t => handlers;
var publisher = new DomainEventsPublisher(multiInstanceFactory);
DomainEvents.Raise(e);
using (mockRepository.Playback())
publisher.Publish();
mockRepository.VerifyAll();
}
示例7: 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.StrictMock<IDatabaseActionResolver>();
IDataBaseActionLocator locator = mocks.StrictMock<IDataBaseActionLocator>();
IDatabaseActionExecutor creator = mocks.StrictMock<IDatabaseActionExecutor>();
IDatabaseActionExecutor updater = mocks.StrictMock<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();
}
示例8: Certifies_deployment
public void Certifies_deployment()
{
var deployment = new Deployment();
var mocks = new MockRepository();
var clock = mocks.CreateMock<ISystemClock>();
var securityContext = mocks.CreateMock<ISecurityContext>();
var repository = mocks.CreateMock<IDeploymentRepository>();
using (mocks.Record())
{
Expect.Call(clock.GetCurrentDateTime()).Return(new DateTime(2007, 4, 15));
Expect.Call(securityContext.GetCurrentUsername()).Return("khurwitz");
repository.Save(deployment);
}
using (mocks.Playback())
{
IVersionCertifier certifier = new VersionCertifier(clock, securityContext, repository);
certifier.Certify(deployment);
Assert.That(deployment.CertifiedBy, Is.EqualTo("khurwitz"));
Assert.That(deployment.CertifiedOn, Is.EqualTo(new DateTime(2007, 4, 15)));
}
mocks.VerifyAll();
}
示例9: When_application_context_is_started_it_will_initialized_all_the_module_loader
public void When_application_context_is_started_it_will_initialized_all_the_module_loader()
{
MockRepository mocks = new MockRepository();
IModuleLoader mockLoader1 = mocks.DynamicMock<IModuleLoader>();
IModuleLoader mockLoader2 = mocks.DynamicMock<IModuleLoader>();
IModuleLoader mockLoader3 = mocks.DynamicMock<IModuleLoader>();
IApplicationShell stubShell = mocks.Stub<IApplicationShell>();
DefaultApplicationContext context = mocks.PartialMock<DefaultApplicationContext>(
stubShell,
mocks.DynamicMock<ILayoutRegistry>(),
new IModuleLoader[] { mockLoader1, mockLoader2, mockLoader3 });
//we may have order dependnecies, let us verify
//that it does this in order
using (mocks.Record())
using (mocks.Ordered())
{
mockLoader1.Initialize(context, stubShell);
mockLoader2.Initialize(context, stubShell);
mockLoader3.Initialize(context, stubShell);
}
using (mocks.Playback())
{
context.Start();
}
}
示例10: Should_not_fail_if_datebase_does_not_exist
public void Should_not_fail_if_datebase_does_not_exist()
{
var settings = new ConnectionSettings("server", "db", true, null, null);
var taskAttributes = new TaskAttributes(settings, null);
var mocks = new MockRepository();
var connectionDropper = mocks.DynamicMock<IDatabaseConnectionDropper>();
var taskObserver = mocks.CreateMock<ITaskObserver>();
var queryExecutor = mocks.CreateMock<IQueryExecutor>();
using (mocks.Record())
{
Expect.Call(() => queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]", false))
.Throw(new Exception("foo message"));
Expect.Call(() => taskObserver.Log("Database 'db' could not be dropped."));
}
using (mocks.Playback())
{
IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
dropper.Execute(taskAttributes, taskObserver);
}
mocks.VerifyAll();
}
示例11: List_getValidNumberAndReferencesOfBeautifulGirls
public void List_getValidNumberAndReferencesOfBeautifulGirls()
{
const int countOfBeautifulGirls= 50;
var girls = Builder<Girl>.CreateListOfSize(2 * countOfBeautifulGirls)
.All()
.With(x => x.Height = 175).With(x => x.Weight = 55).With(x => x.BirthDate = new DateTime(1990, 2, 2))
.TheLast(countOfBeautifulGirls)
.With(x => x.Height = 180).With(x => x.Weight = 105).With(x => x.BirthDate = new DateTime(1990, 2, 2))
.Build();
for (int page = 1; page < 10; page++)
{
Mockery = new MockRepository();
var girlService = Mockery.Stub<IGirlService>();
UnitOfWorkFactory = Mockery.DynamicMock<IUnitOfWorkFactory>();
UnitOfWork = Mockery.DynamicMock<IUnitOfWork>();
using (Mockery.Record())
{
Expect.Call(UnitOfWorkFactory.Create()).Return(UnitOfWork);
Expect.Call(girlService.GetBeautifulGirls()).Return(girls.Take(countOfBeautifulGirls).ToList());
}
IEnumerable<GirlModel> resultGirls;
using (Mockery.Playback())
{
var controller = new GirlsController(girlService, UnitOfWorkFactory);
var result = controller.List(page, true);
resultGirls = (IEnumerable<GirlModel>) result.Data;
}
var girlModels = resultGirls as GirlModel[] ?? resultGirls.ToArray();
Assert.AreEqual(girls.Take(countOfBeautifulGirls).Skip((page - 1) * Constants.GIRLS_PAGER_LINKS_PER_PAGE).
Take(Constants.GIRLS_PAGER_LINKS_PER_PAGE).Count(), girlModels.Count());
if (girlModels.Count() != 0)
Assert.AreEqual(girls.Take(countOfBeautifulGirls).Skip((page - 1) * Constants.GIRLS_PAGER_LINKS_PER_PAGE).
Take(Constants.GIRLS_PAGER_LINKS_PER_PAGE).First().Id, girlModels.First().Id);
}
}
示例12: Drops_database
public void Drops_database()
{
var settings = new ConnectionSettings("server", "db", true, null, null);
var taskAttributes = new TaskAttributes(settings, null);
var mocks = new MockRepository();
var connectionDropper = mocks.CreateMock<IDatabaseConnectionDropper>();
var taskObserver = mocks.CreateMock<ITaskObserver>();
var queryExecutor = mocks.CreateMock<IQueryExecutor>();
using (mocks.Record())
{
connectionDropper.Drop(settings, taskObserver);
queryExecutor.ExecuteNonQuery(settings, "ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE drop database [db]", false);
}
using (mocks.Playback())
{
IDatabaseActionExecutor dropper = new DatabaseDropper(connectionDropper, queryExecutor);
dropper.Execute(taskAttributes, taskObserver);
}
mocks.VerifyAll();
}
示例13: CanCreateNewSite
public void CanCreateNewSite()
{
Site site = DomainTestHelper.GetTestSite();
Theme theme = MockRepository.GenerateStub<Theme>();
theme.BasePath = "~/themes/default";
theme.Name = "default";
site.Theme = theme;
MockRepository mocks = new MockRepository();
sessionFactory = MockRepository.GenerateMock<Arashi.Core.NHibernate.ISessionFactory>();
session = MockRepository.GenerateMock<ISession>();
Site createdSite;
using (mocks.Record())
{
sessionFactory.Expect(x => x.GetSession()).Return(session /*MockRepository.GenerateStub<ISession>()*/);
session.Expect(x => x.BeginTransaction()).Return(MockRepository.GenerateStub <ITransaction>());
}
using (mocks.Playback())
{
ISiteService siteService = new SiteService( sessionFactory, // this.AutoMockingContainer().Resolve<Arashi.Core.NHibernate.ISessionFactory>(),
this.AutoMockingContainer().Resolve<ILog>(),
this.AutoMockingContainer().Resolve<IUserService>(),
this.AutoMockingContainer().Resolve<IFileService>());
createdSite = siteService.CreateNewSite("Test", "test", "[email protected]", "localhost", theme);
}
mocks.VerifyAll();
createdSite.Should().Not.Be.Null();
createdSite.Name.Should().Be.EqualTo(site.Name);
createdSite.Hosts.Count.Should().Be.GreaterThanOrEqualTo(1);
createdSite.Hosts[0].Should().Not.Be.Null();
createdSite.Theme.Should().Be.EqualTo(theme);
//NHibernate.ISession session = mocks.StrictMock<NHibernate.ISession>();
//NHibernate.ITransaction transaction = mocks.Stub<NHibernate.ITransaction>();
//Student expected = new Student();
//Student actual;
//using (mocks.Record())
//{
// Rhino.Mocks.Expect.Call(session.Transaction)
// .Return(transaction)
// .Repeat.Any();
// Rhino.Mocks.Expect.Call(transaction.IsActive)
// .Return(true);
// Rhino.Mocks.Expect.Call(session.Get<Student>(Guid.Empty))
// .Return(expected);
//}
//using (mocks.Playback())
//{
// IReadStudent StudentDao = new StudentDAOImpl(session);
// actual = StudentDao.GetById(Guid.Empty);
//}
//mocks.VerifyAll();
//Assert.IsNotNull(actual);
//Assert.AreSame(expected, actual);
}
示例14: Executes_all_the_scripts_within_a_folder
public void Executes_all_the_scripts_within_a_folder()
{
var settings = new ConnectionSettings("server", "db", true, null, null);
var sqlFiles = new[] { "c:\\scripts\\Update\\001.sql", "c:\\scripts\\Update\\002_data_.sql", "c:\\scripts\\Update\\003.sql" };
var taskAttributes = new TaskAttributes(settings, "c:\\scripts")
{
RequestedDatabaseAction = RequestedDatabaseAction.Update,
};
var mocks = new MockRepository();
var initializer = mocks.StrictMock<ISchemaInitializer>();
var fileLocator = mocks.StrictMock<ISqlFileLocator>();
var executor = mocks.StrictMock<IChangeScriptExecutor>();
var testdataexecutor = mocks.StrictMock<ITestDataScriptExecutor>();
var versioner = mocks.StrictMock<IDatabaseVersioner>();
var taskObserver = mocks.StrictMock<ITaskObserver>();
using (mocks.Record())
{
initializer.EnsureSchemaCreated(settings);
Expect.Call(fileLocator.GetSqlFilenames("c:\\scripts", "Update")).Return(sqlFiles);
executor.Execute("c:\\scripts\\Update\\001.sql", settings, taskObserver);
executor.Execute("c:\\scripts\\Update\\002_data_.sql", settings, taskObserver);
executor.Execute("c:\\scripts\\Update\\003.sql", settings, taskObserver);
versioner.VersionDatabase(settings, taskObserver);
}
using (mocks.Playback())
{
IScriptFolderExecutor folderExecutor = new ScriptFolderExecutor(initializer, fileLocator, executor, testdataexecutor, versioner);
folderExecutor.ExecuteScriptsInFolder(taskAttributes, "Update", taskObserver);
}
mocks.VerifyAll();
}
示例15: Complete_Doesnt_Save_Task_If_No_Change
public void Complete_Doesnt_Save_Task_If_No_Change()
{
var mockery = new MockRepository();
var projectId = 3;
var storyId = 4;
var id = 5;
var completed = true;
var description = "Doin work";
var task = new Task { Description = description, Id = id, ParentStoryId = storyId, ProjectId = projectId, Complete = true };
var storyService = mockery.StrictMock<IStoryService>();
using (mockery.Record())
using (mockery.Ordered()) {
Expect.Call(storyService.GetTask(projectId, storyId, id)).Return(task);
}
using (mockery.Playback()) {
var controller = new TaskController(storyService);
var result = controller.Complete(id, storyId, projectId, completed);
var viewResult = result as PartialViewResult;
Assert.NotNull(viewResult);
Assert.AreEqual("TaskDetails", viewResult.ViewName);
Assert.IsInstanceOf<TaskViewModel>(viewResult.Model);
Assert.AreEqual(task, (viewResult.Model as TaskViewModel).Task);
}
}