本文整理汇总了C#中Rhino.Mocks.MockRepository.ReplayAll方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.ReplayAll方法的具体用法?C# MockRepository.ReplayAll怎么用?C# MockRepository.ReplayAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rhino.Mocks.MockRepository
的用法示例。
在下文中一共展示了MockRepository.ReplayAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
}
示例2: RunOnceBeforeAny
public virtual void RunOnceBeforeAny()
{
// Initialize NBuilder settings
BuilderSetup.SetDefaultPropertyNamer(new NonDefaultNonRepeatingPropertyNamer(new ReflectionUtil()));
// Create a mock repository for new mocks
mocks = new MockRepository();
EstablishContext();
// Stop recording
mocks.ReplayAll();
try
{
// Allow execution of code just prior to test execution
BeforeExecuteTest();
// Execute the test
ExecuteTest();
}
finally
{
// Allow cleanup surrounding test execution, prior to final cleanup
AfterExecuteTest();
}
}
示例3: Do3Classic
public void Do3Classic()
{
var mockRepository = new MockRepository();
var view = mockRepository.StrictMock<IButtonView>();
var model = mockRepository.StrictMock<IToggleModel>();
model.VisibilityStateChanged += null;
IEventRaiser visibilityChanged = LastCall.GetEventRaiser();
view.Clicked += null;
IEventRaiser clicked = LastCall.GetEventRaiser();
var presenter = new ButtonPresenter(model);
presenter.ConnectView(view);
mockRepository.BackToRecordAll();
//mockRepository.Playback();
Expect.Call(model.ToggleVisibility);
Expect.Call(() => model.VisibilityStateChanged += null).IgnoreArguments();
Expect.Call(() => view.SetCheckedState(CheckedState.Checked));
mockRepository.ReplayAll();
clicked.Raise();
visibilityChanged.Raise(VisibilityState.Visible);
mockRepository.VerifyAll();
}
示例4: GetById_Calls_GigDAO_Method_GetById_Once_And_Returns_A_Gig
public void GetById_Calls_GigDAO_Method_GetById_Once_And_Returns_A_Gig()
{
MockRepository mocks = new MockRepository();
Guid gigId = Guid.NewGuid();
Gig gig = new Gig();
gig.ID = gigId;
IGigDAO gigDAO = mocks.DynamicMock<IGigDAO>();
GigManager gigManager = new GigManager();
gigManager.GigDAO = gigDAO;
Expect.Call(gigDAO.GetById(gigId))
.Constraints(Is.Equal(gigId))
.Repeat.Once()
.Return(gig);
mocks.ReplayAll();
Gig result = gigManager.GetByID(gigId);
mocks.VerifyAll();
Assert.AreEqual(gig.ID, result.ID);
}
示例5: GetMatchNonMatchTest
public static void GetMatchNonMatchTest(
string headerName,
string[] values,
bool existsInStore,
bool expectReturnNull,
HttpStatusCode expectedStatus = HttpStatusCode.Unused)
{
// setup
var mocks = new MockRepository();
var entityTagStore = mocks.StrictMock<IEntityTagStore>();
var entityTagHandler = new CachingHandler(entityTagStore);
var request = new HttpRequestMessage(HttpMethod.Get, TestUrl);
request.Headers.Add(headerName, values);
TimedEntityTagHeaderValue entityTagHeaderValue = new TimedEntityTagHeaderValue("\"12345678\"");
if(values.Length>0) // if
entityTagStore.Expect(x => x.TryGetValue(Arg<CacheKey>.Matches(etg => etg.ResourceUri == entityTagHandler.UriTrimmer(new Uri(TestUrl))),
out Arg<TimedEntityTagHeaderValue>.Out(entityTagHeaderValue).Dummy)).Return(existsInStore);
mocks.ReplayAll();
// run
var matchNoneMatch = entityTagHandler.GetIfMatchNoneMatch();
// verify
Task<HttpResponseMessage> resultTask = matchNoneMatch(request);
Assert.That(expectReturnNull ^ resultTask != null, "result was not as expected");
if(resultTask!=null && expectedStatus != HttpStatusCode.Unused)
{
Assert.AreEqual(expectedStatus, resultTask.Result.StatusCode, "Status code");
}
mocks.VerifyAll();
}
示例6: CreateMockedDataBaseObjects
/// <summary>
/// Creates a mocked datareader and loads it with row data ready to replay
/// </summary>
/// <param name="mocks">The mock repository object that all the tests are running with</param>
/// <param name="procedureName">The name of the procedure you want to call</param>
/// <param name="creator">The new DataReaderCreator object</param>
/// <param name="reader">The new DataReader object</param>
/// <param name="testRowData">A list of test row data to load the reader with</param>
static public void CreateMockedDataBaseObjects(MockRepository mocks, string procedureName, out IDnaDataReaderCreator creator, out IDnaDataReader reader, List<TestDatabaseRow> testRowData)
{
reader = CreateMockedIDnaDataReader(mocks, testRowData);
creator = mocks.DynamicMock<IDnaDataReaderCreator>();
creator.Stub(x => x.CreateDnaDataReader(procedureName)).Return(reader);
mocks.ReplayAll();
}
示例7: 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;
}
示例8: Search
public void Search()
{
// Basic integration test: search algorithms are already extensively tested with InMemoryIndexBase
MockRepository mocks = new MockRepository();
IIndexConnector conn = mocks.StrictMock<IIndexConnector>();
ScrewTurn.Wiki.SearchEngine.IWordFetcher fetcher = mocks.StrictMock<ScrewTurn.Wiki.SearchEngine.IWordFetcher>();
ScrewTurn.Wiki.SearchEngine.Word dummy = null;
Expect.Call(fetcher.TryGetWord("test", out dummy)).Return(false);
Expect.Call(fetcher.TryGetWord("query", out dummy)).Return(false);
fetcher.Dispose();
LastCall.On(fetcher);
Expect.Call(conn.GetWordFetcher()).Return(fetcher);
mocks.ReplayAll();
SqlIndex index = new SqlIndex(conn);
Assert.AreEqual(0, index.Search(new ScrewTurn.Wiki.SearchEngine.SearchParameters("test query")).Count, "Wrong search result count");
mocks.VerifyAll();
}
示例9: TestCachingContinuation
public static void TestCachingContinuation(
string method,
bool existsInStore,
bool addVaryHeader,
bool addLastModifiedHeader,
bool alreadyHasLastModified,
string[] varyByHeader)
{
// setup
var mocks = new MockRepository();
var request = new HttpRequestMessage(new HttpMethod(method), TestUrl);
request.Headers.Add(HttpHeaderNames.Accept, "text/xml");
request.Headers.Add(HttpHeaderNames.AcceptLanguage, "en-GB");
var entityTagStore = mocks.StrictMock<IEntityTagStore>();
var cachingHandler = new CachingHandler(entityTagStore, varyByHeader)
{
AddLastModifiedHeader = addLastModifiedHeader,
AddVaryHeader = addVaryHeader
};
var entityTagHeaderValue = new TimedEntityTagHeaderValue("\"12345678\"");
var entityTagKey = new EntityTagKey(TestUrl, new string[0]);
cachingHandler.EntityTagKeyGenerator = (x, y) => entityTagKey;
cachingHandler.ETagValueGenerator = (x, y) => new EntityTagHeaderValue(entityTagHeaderValue.Tag);
entityTagStore.Expect(x => x.TryGet(Arg<EntityTagKey>.Matches(etg => etg.ResourceUri == TestUrl),
out Arg<TimedEntityTagHeaderValue>.Out(entityTagHeaderValue).Dummy)).Return(existsInStore);
if (!existsInStore || request.Method == HttpMethod.Put || request.Method == HttpMethod.Post)
{
entityTagStore.Expect(
x => x.AddOrUpdate(Arg<EntityTagKey>.Matches(etk => etk == entityTagKey),
Arg<TimedEntityTagHeaderValue>.Matches(ethv => ethv.Tag == entityTagHeaderValue.Tag)));
}
mocks.ReplayAll();
var response = new HttpResponseMessage();
response.Content = new ByteArrayContent(new byte[0]);
if(alreadyHasLastModified)
response.Content.Headers.Add(HttpHeaderNames.LastModified, DateTimeOffset.Now.ToString("r"));
var cachingContinuation = cachingHandler.GetCachingContinuation(request);
var taskCompletionSource = new TaskCompletionSource<HttpResponseMessage>();
taskCompletionSource.SetResult(response);
// run
var httpResponseMessage = cachingContinuation(taskCompletionSource.Task);
// test
if(addLastModifiedHeader)
{
Assert.That(httpResponseMessage.Content.Headers.Any(x=>x.Key == HttpHeaderNames.LastModified),
"LastModified does not exist");
}
if(!addLastModifiedHeader && !alreadyHasLastModified)
{
Assert.That(!httpResponseMessage.Content.Headers.Any(x => x.Key == HttpHeaderNames.LastModified),
"LastModified exists");
}
}
示例10: GigController_Should_Contain_Index_Method_Which_Accepts_GigID_And_Returns_A_Gig
public void GigController_Should_Contain_Index_Method_Which_Accepts_GigID_And_Returns_A_Gig()
{
MockRepository mocks = new MockRepository();
Guid gigId = Guid.NewGuid();
Gig gig = new Gig();
gig.ID = gigId;
//Mock the GigManager
IGigManager gigManager = mocks.DynamicMock<IGigManager>();
GigController gigController = new GigController();
gigController.GigManager = gigManager;
Expect.Call(gigManager.GetByID(gigId))
.Constraints(Is.Equal(gigId))
.Repeat.Once()
.Return(gig);
mocks.ReplayAll();
ViewResult result = (ViewResult)gigController.Index(gigId);
Gig returnedData = (Gig)(result.ViewData.Model);
mocks.VerifyAll();
Assert.IsNotNull(returnedData);
Assert.AreEqual(gig.ID, returnedData.ID);
}
示例11: TestCacheInvalidationForPost
public static void TestCacheInvalidationForPost(string method)
{
const string relatedUrl = "http://api/SomeLocationUrl/";
// setup
var locationUrl = new Uri(relatedUrl);
var mocks = new MockRepository();
var request = new HttpRequestMessage(new HttpMethod(method), TestUrl);
string routePattern = "http://myserver/api/stuffs/*";
var entityTagStore = mocks.StrictMock<IEntityTagStore>();
var cachingHandler = new CachingHandler(new HttpConfiguration(), entityTagStore)
{
};
var entityTagKey = new CacheKey(TestUrl, new string[0], routePattern);
var response = new HttpResponseMessage();
response.Headers.Location = locationUrl;
var invalidateCacheForPost = cachingHandler.PostInvalidationRule(entityTagKey, request, response);
if(method == "POST")
{
entityTagStore.Expect(x => x.RemoveAllByRoutePattern("/SomeLocationUrl/")).Return(1);
}
mocks.ReplayAll();
// run
invalidateCacheForPost();
// verify
mocks.VerifyAll();
}
示例12: Simple
public void Simple()
{
var list = GetTestList();
var mockRepository = new MockRepository();
var trackingList = mockRepository.StrictMock<IList<int>>();
// All items should be visited...
trackingList.Add(1);
trackingList.Add(2);
trackingList.Add(3);
trackingList.Add(8);
trackingList.Add(5);
mockRepository.ReplayAll();
var generalVisitor = new GeneralVisitor<int>(
delegate (int value) {
trackingList.Add(value);
return false;
}
);
list.AcceptVisitor(generalVisitor);
mockRepository.VerifyAll();
}
示例13: TestIndirectBlocks
public void TestIndirectBlocks()
{
var repository = new MockRepository();
var mockDiskAccess = repository.DynamicMock<IDirectDiskAccess>();
var mockAllocator = repository.StrictMock<IBlockAllocator>();
const int blocksToAllocate = 2000;
var list = new List<Address>();
for (int i = 0; i < blocksToAllocate; ++i)
{
list.Add(new Address((ulong)i * Constants.BlockSizeBytes));
}
Expect.Call(mockAllocator.AllocateBlocks(blocksToAllocate)).IgnoreArguments().Return(list.ToArray());
Expect.Call(mockAllocator.AllocateBlocks(1)).IgnoreArguments().Return(new[] { new Address(0) }).Repeat.Times(3); // indirect block allocation
Expect.Call(() => mockAllocator.FreeBlocks(null)).IgnoreArguments().Repeat.Any();
var storage = new BlockAddressStorage(mockDiskAccess, mockAllocator, new Address(0), new Address(0));
repository.ReplayAll();
storage.AddBlocks(2000);
storage.GetBlockStartAddress(12);
storage.GetBlockStartAddress(1024);
storage.GetBlockStartAddress(1024 + 12);
storage.GetBlockStartAddress(1999);
Assert.Throws<IndexOutOfRangeException>(() => storage.GetBlockStartAddress(2000));
repository.VerifyAll();
}
示例14: Initalize_Sets_URL_On_View
public void Initalize_Sets_URL_On_View()
{
MockRepository repo = new MockRepository();
IOptionsView mockOptionsView = repo.StrictMock<IOptionsView>();
ISettingsOriginator mockSettingsOriginator = repo.StrictMock<ISettingsOriginator>();
ISettingsMemento mockSettingsMemento = repo.StrictMock<ISettingsMemento>();
ISetting urlSetting = repo.StrictMock<ISetting>();
ISetting userNameSetting = repo.StrictMock<ISetting>();
ISetting passwordSetting = repo.StrictMock<ISetting>();
string url = "http://www.google.com";
string userName = "mockUser";
string password = "mockPass";
urlSetting.Expect(set => set.Value).Return(url);
userNameSetting.Expect(set => set.Value).Return(userName);
passwordSetting.Expect(set => set.Value).Return(password);
mockSettingsOriginator.Expect(org => org.Get("TrackerURL")).Return(urlSetting);
mockSettingsOriginator.Expect(org => org.Get("UserName")).Return(userNameSetting);
mockSettingsOriginator.Expect(org => org.Get("Password")).Return(passwordSetting);
mockSettingsOriginator.Expect(org => org.GetMemento()).Return(mockSettingsMemento);
mockOptionsView.Expect(view => view.URL).SetPropertyWithArgument(url);
mockOptionsView.Expect(view => view.UserName).SetPropertyWithArgument(userName);
mockOptionsView.Expect(view => view.Password).SetPropertyWithArgument(password);
repo.ReplayAll();
IOptionsPresenter pres = new OptionsPresenter(mockOptionsView, mockSettingsOriginator);
pres.Initalize();
mockOptionsView.VerifyAllExpectations();
mockSettingsOriginator.VerifyAllExpectations();
urlSetting.VerifyAllExpectations();
}
示例15: Setup
public void Setup()
{
basketRepository = MockRepository.GenerateStub<IRepository<Basket>>();
unitOfWorkManager = MockRepository.GenerateStub<IUnitOfWorkManager>();
userService = MockRepository.GenerateStub<IUserService>();
postageService = MockRepository.GenerateStub<IPostageService>();
countryRepository = MockRepository.GenerateStub<IRepository<Country>>();
cardTypeRepository = MockRepository.GenerateStub<IRepository<CardType>>();
orderRepository = MockRepository.GenerateStub<IRepository<Order>>();
subscriptionRepository = MockRepository.GenerateStub<IRepository<MailingListSubscription>>();
emailService = MockRepository.GenerateStub<IEmailService>();
var mocks = new MockRepository(); //TODO: No need to partial mock once email sending is fixed
controller = new CheckoutController(
basketRepository,
userService,
postageService,
countryRepository,
cardTypeRepository,
orderRepository,
unitOfWorkManager,
emailService,
subscriptionRepository
);
mocks.ReplayAll();
userService.Expect(us => us.CurrentUser).Return(new User { UserId = 4, RoleId = Role.AdministratorId });
}