本文整理汇总了C#中Rhino.Mocks.MockRepository.Ordered方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.Ordered方法的具体用法?C# MockRepository.Ordered怎么用?C# MockRepository.Ordered使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rhino.Mocks.MockRepository
的用法示例。
在下文中一共展示了MockRepository.Ordered方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WillInitializeAllModuleLoadersOnStart
public void WillInitializeAllModuleLoadersOnStart()
{
MockRepository mocks = new MockRepository();
IModuleLoader mockLoader1 = mocks.DynamicMock<IModuleLoader>();
IModuleLoader mockLoader2 = mocks.DynamicMock<IModuleLoader>();
IModuleLoader mockLoader3 = mocks.DynamicMock<IModuleLoader>();
IShellView stubShell = mocks.Stub<IShellView>();
DefaultApplicationContext context = mocks.PartialMock<DefaultApplicationContext>(
stubShell, new IModuleLoader[] { mockLoader1, mockLoader2, mockLoader3 });
using (mocks.Record())
{
//we may have order dependnecies, let us verify
//that it does this in order
using (mocks.Ordered())
{
mockLoader1.Initialize(context, stubShell);
mockLoader2.Initialize(context, stubShell);
mockLoader3.Initialize(context, stubShell);
}
//force context to ignore these calls
Expect.Call(context.GetShellAsForm()).Return(null).Repeat.Once();
Expect.Call(delegate { context.RunForm(null); }).Repeat.Once();
}
using (mocks.Playback())
{
context.Start();
}
}
示例2: 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();
}
}
示例3: testArrayWithfunction
public void testArrayWithfunction()
{
string classname = "TestClassName";
string json = @"{@class:'" + classname+ @"',
id:'123',
objectListPropA:null,
intListPropB: _a_([3, 4, 5]) }";
var mocks = new MockRepository();
var theMock = mocks.StrictMock<JsonExploreListener>();
RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
Console.WriteLine("***testArrayWithfunction json: " + json);
using (mocks.Ordered())
{
theMock.JsonStartObject(null, 0);
theMock.JsonLeaf("@class", classname, true);
theMock.JsonLeaf("id", "123", true);
theMock.JsonLeaf("objectListPropA", null, false);
theMock.JsonStartFunction("_a_", json.IndexOf("("), "intListPropB" );
theMock.JsonStartArray(null, json.IndexOf("["));
theMock.JsonLeaf(null, "3", false);
theMock.JsonLeaf(null, "4", false);
theMock.JsonLeaf(null, "5", false);
theMock.JsonEndArray(json.IndexOf("]"));
theMock.JsonEndFunction(json.IndexOf(")"));
theMock.JsonEndObject(json.IndexOf("}"));
}
theMock.Replay();
JSONExplorerImpl jsonExplorerImpl = new JSONExplorerImpl();
jsonExplorerImpl.explore(json, theMock);
//todo - verify expectations
}
示例4: 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);
}
}
示例5: ShouldIgnoreArgumentsOnGenericCallWhenTypeIsStruct
public void ShouldIgnoreArgumentsOnGenericCallWhenTypeIsStruct()
{
// setup
MockRepository mocks = new MockRepository();
ISomeService m_SomeServiceMock = mocks.StrictMock<ISomeService>();
SomeClient sut = new SomeClient(m_SomeServiceMock);
using (mocks.Ordered())
{
Expect.Call(delegate
{
m_SomeServiceMock.DoSomething<string>(null, null);
});
LastCall.IgnoreArguments();
Expect.Call(delegate
{
m_SomeServiceMock.DoSomething<DateTime>(null, default(DateTime)); // can't use null here, because it's a value type!
});
LastCall.IgnoreArguments();
}
mocks.ReplayAll();
// test
sut.DoSomething();
// verification
mocks.VerifyAll();
// cleanup
m_SomeServiceMock = null;
sut = null;
}
示例6: FiltersOnParseAndFormat
public void FiltersOnParseAndFormat()
{
MockRepository mocks = new MockRepository();
IFormatter underlyingFormatter = mocks.StrictMock<IFormatter>();
TestFilteringFormatter formatter = (TestFilteringFormatter) mocks.PartialMock(typeof (TestFilteringFormatter), underlyingFormatter);
string inputText = "inputText";
string filteredInputText = "filteredInputText";
object outputValue = new object();
object filteredOutputValue = new object();
using(mocks.Ordered())
{
Expect.Call(formatter.DoFilterValueToParse(inputText)).Return(filteredInputText);
Expect.Call(underlyingFormatter.Parse(filteredInputText)).Return(outputValue);
Expect.Call(formatter.DoFilterValueToFormat(outputValue)).Return(filteredOutputValue);
Expect.Call(underlyingFormatter.Format(filteredOutputValue)).Return(inputText);
}
mocks.ReplayAll();
Assert.AreSame(outputValue, formatter.Parse(inputText));
Assert.AreEqual(inputText, formatter.Format(outputValue));
mocks.VerifyAll();
}
示例7: AddComment
public void AddComment()
{
var mockery = new MockRepository();
var storyService = mockery.StrictMock<IStoryService>();
var storyId = 1;
var projectId = 3;
var comment = "comment";
var story = new Story();
using (mockery.Record())
using (mockery.Ordered()) {
storyService.AddComment(projectId, storyId, comment);
Expect.Call(storyService.GetStory(projectId, storyId)).Return(story);
}
using(mockery.Playback()){
var controller = new StoriesController(storyService);
var result = controller.AddComment(projectId, storyId, comment);
var partialResult = result as PartialViewResult;
Assert.NotNull(partialResult);
var model = partialResult.Model as StoryRowViewModel;
Assert.NotNull(model);
Assert.AreEqual(story, model.Story);
}
}
示例8: HasReached_GenerationNumberLowerThanCondition_False
public void HasReached_GenerationNumberLowerThanCondition_False()
{
var repository = new MockRepository();
var ga = repository.StrictMock<IGeneticAlgorithm>();
using (repository.Ordered())
{
ga.Expect(g => g.GenerationsNumber).Return(1);
ga.Expect(g => g.GenerationsNumber).Return(2);
ga.Expect(g => g.GenerationsNumber).Return(3);
ga.Expect(g => g.GenerationsNumber).Return(4);
ga.Expect(g => g.GenerationsNumber).Return(5);
ga.Expect(g => g.GenerationsNumber).Return(6);
ga.Expect(g => g.GenerationsNumber).Return(7);
ga.Expect(g => g.GenerationsNumber).Return(8);
ga.Expect(g => g.GenerationsNumber).Return(0);
}
repository.ReplayAll();
var target = new GenerationNumberTermination(10);
Assert.IsFalse(target.HasReached(ga));
for (int i = 0; i < 8; i++)
{
Assert.IsFalse(target.HasReached(ga));
}
}
示例9: Cross_ParentsWithDiffLength_Cross
public void Cross_ParentsWithDiffLength_Cross()
{
var target = new CutAndSpliceCrossover();
var chromosome1 = MockRepository.GenerateStub<ChromosomeBase>(4);
chromosome1.ReplaceGenes(0, new Gene[]
{
new Gene(1),
new Gene(2),
new Gene(3),
new Gene(4),
});
chromosome1.Expect(c => c.CreateNew()).Return(MockRepository.GenerateStub<ChromosomeBase>(4));
var chromosome2 = MockRepository.GenerateStub<ChromosomeBase>(5);
chromosome2.ReplaceGenes(0, new Gene[]
{
new Gene(5),
new Gene(6),
new Gene(7),
new Gene(8),
new Gene(9),
});
chromosome2.Expect(c => c.CreateNew()).Return(MockRepository.GenerateStub<ChromosomeBase>(5));
var repository = new MockRepository();
var rnd = repository.StrictMock<IRandomization>();
using (repository.Ordered())
{
rnd.Expect(r => r.GetInt(1, 4)).Return(2);
rnd.Expect(r => r.GetInt(1, 5)).Return(2);
}
repository.ReplayAll();
RandomizationProvider.Current = rnd;
var actual = target.Cross(new List<IChromosome>() { chromosome1, chromosome2 });
Assert.AreEqual(2, actual.Count);
Assert.AreEqual(5, actual[0].Length);
Assert.AreEqual(4, actual[1].Length);
Assert.AreEqual(1, actual[0].GetGene(0).Value);
Assert.AreEqual(2, actual[0].GetGene(1).Value);
Assert.AreEqual(3, actual[0].GetGene(2).Value);
Assert.AreEqual(8, actual[0].GetGene(3).Value);
Assert.AreEqual(9, actual[0].GetGene(4).Value);
Assert.AreEqual(5, actual[1].GetGene(0).Value);
Assert.AreEqual(6, actual[1].GetGene(1).Value);
Assert.AreEqual(7, actual[1].GetGene(2).Value);
Assert.AreEqual(4, actual[1].GetGene(3).Value);
}
示例10: testJsonStructure
public static void testJsonStructure(string json, JsonExpectationBlock expectation, string testname)
{
RhinoMocks.Logger = new TextWriterExpectationLogger(Console.Out);
System.Console.WriteLine("test: " + testname + "testing json=" + json);
var mocks = new MockRepository();
JsonExploreListener theMock = mocks.StrictMock<JsonExploreListener>();
using (mocks.Ordered())
{
expectation(theMock, json);
}
theMock.Replay();
(new JSONExplorerImpl()).explore(json, theMock);
theMock.VerifyAllExpectations();
}
示例11: HasReached_BestChromosomeHasLowerFitness_False
public void HasReached_BestChromosomeHasLowerFitness_False()
{
var repository = new MockRepository ();
var ga = repository.StrictMock<IGeneticAlgorithm> ();
using (repository.Ordered()) {
ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub() { Fitness = 0.4});
ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub() { Fitness = 0.499});
}
repository.ReplayAll ();
var target = new FitnessThresholdTermination (0.5);
Assert.IsFalse(target.HasReached(ga));
Assert.IsFalse(target.HasReached(ga));
}
示例12: HasReached_GenerationNumberGreaterOrEqualThanCondition_True
public void HasReached_GenerationNumberGreaterOrEqualThanCondition_True()
{
var repository = new MockRepository ();
var ga = repository.StrictMock<IGeneticAlgorithm> ();
using (repository.Ordered()) {
ga.Expect (g => g.GenerationsNumber).Return (10);
ga.Expect (g => g.GenerationsNumber).Return (11);
}
repository.ReplayAll ();
var target = new GenerationNumberTermination (10);
Assert.IsTrue (target.HasReached (ga));
Assert.IsTrue (target.HasReached (ga));
}
示例13: HasReached_TimeLowerThanMaxTime_False
public void HasReached_TimeLowerThanMaxTime_False()
{
var repository = new MockRepository ();
var ga = repository.StrictMock<IGeneticAlgorithm> ();
using (repository.Ordered()) {
ga.Expect (g => g.TimeEvolving).Return (TimeSpan.FromSeconds(0.1));
ga.Expect (g => g.TimeEvolving).Return (TimeSpan.FromSeconds(0.9));
}
repository.ReplayAll ();
var target = new TimeEvolvingTermination (TimeSpan.FromSeconds(1));
Assert.IsFalse(target.HasReached(ga));
Assert.IsFalse(target.HasReached(ga));
}
示例14: SetResultSelectsCorrectResult
public void SetResultSelectsCorrectResult()
{
MockRepository mocks = new MockRepository();
TestUserControl uc = new TestUserControl();
Result theResult = (Result)mocks.CreateMock(typeof(Result));
using (mocks.Ordered())
{
theResult.Navigate(uc);
}
mocks.ReplayAll();
uc.Results.Add("theResult", theResult);
uc.SetResult("theResult");
mocks.VerifyAll();
}
示例15: HasReached_StagnantButNotReachTheGenerationsNumber_False
public void HasReached_StagnantButNotReachTheGenerationsNumber_False()
{
var target = new FitnessStagnationTermination(4);
var repository = new MockRepository ();
var ga = repository.StrictMock<IGeneticAlgorithm> ();
using (repository.Ordered()) {
ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub () { Fitness = 0.1 } );
ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub () { Fitness = 0.1 } );
ga.Expect (g => g.BestChromosome).Return (new ChromosomeStub () { Fitness = 0.1 } );
}
repository.ReplayAll ();
Assert.IsFalse(target.HasReached(ga));
Assert.IsFalse(target.HasReached(ga));
Assert.IsFalse(target.HasReached(ga));
}