本文整理汇总了C#中ObjectPool.Borrow方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectPool.Borrow方法的具体用法?C# ObjectPool.Borrow怎么用?C# ObjectPool.Borrow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectPool
的用法示例。
在下文中一共展示了ObjectPool.Borrow方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle_is_invalidated_when_invalidate_is_not_set
public void Handle_is_invalidated_when_invalidate_is_not_set()
{
var mogileFsMock = MockRepository.GenerateStub<IMogileFs>();
var mogileFsFactory = MockRepository.GenerateStub<IObjectPoolFactory<IMogileFs>>();
mogileFsFactory.Stub(x => x.CreateInstance()).Return(mogileFsMock);
var pool = new ObjectPool<IMogileFs>(mogileFsFactory);
using (pool.Borrow()) {
}
using (pool.Borrow()) {
}
mogileFsFactory.AssertWasCalled(x => x.CreateInstance(), options => options.Repeat.Twice());
}
示例2: Instance_is_reused_when_invalidate_is_set_to_false
public void Instance_is_reused_when_invalidate_is_set_to_false()
{
var mogileFsMock = MockRepository.GenerateStub<IMogileFs>();
var mogileFsFactory = MockRepository.GenerateStub<IObjectPoolFactory<IMogileFs>>();
mogileFsFactory.Stub(x => x.CreateInstance()).Return(mogileFsMock);
var pool = new ObjectPool<IMogileFs>(mogileFsFactory);
using (var x = pool.Borrow())
{
x.Invalidate = false;
}
using (var x = pool.Borrow())
{
x.Invalidate = false;
}
mogileFsFactory.AssertWasCalled(x => x.CreateInstance(), options => options.Repeat.Once());
}
示例3: When_handle_is_borrowed_invalidate_is_set_to_true
public void When_handle_is_borrowed_invalidate_is_set_to_true()
{
var mogileFsMock = MockRepository.GenerateStub<IMogileFs>();
var mogileFsFactory = MockRepository.GenerateStub<IObjectPoolFactory<IMogileFs>>();
mogileFsFactory.Expect(x => x.CreateInstance())
.Return(mogileFsMock);
var pool = new ObjectPool<IMogileFs>(mogileFsFactory);
using (var obj = pool.Borrow())
{
Assert.AreEqual(true, obj.Invalidate);
}
mogileFsFactory.AssertWasCalled(x => x.CreateInstance());
}
示例4: ExternalResource
public ExternalResource( ObjectPool<InternalResource> pool )
{
this._pool = pool;
this._internalResource = pool.Borrow();
}