本文整理汇总了C#中AutoFake.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# AutoFake.Resolve方法的具体用法?C# AutoFake.Resolve怎么用?C# AutoFake.Resolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoFake
的用法示例。
在下文中一共展示了AutoFake.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes_Async
public async void ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes_Async()
{
using (var fake = new AutoFake(callsDoNothing: true))
{
fake.Provide<IConnectionConfigurationValues>(_connectionConfig);
this.ProvideTransport(fake);
var getCall = A.CallTo(() => fake.Resolve<IConnection>().Get(A<Uri>._));
Func<ElasticsearchResponse> badTask = () => { throw new Exception(); };
var t = new Task<ElasticsearchResponse>(badTask);
t.Start();
getCall.Returns(t);
var client = fake.Resolve<ElasticsearchClient>();
client.Settings.MaxRetries.Should().Be(_retries);
try
{
var result = await client.InfoAsync();
}
catch (Exception e)
{
Assert.AreEqual(e.GetType(), typeof(OutOfNodesException));
}
getCall.MustHaveHappened(Repeated.Exactly.Times(_retries + 1));
}
}
示例2: PreparePresentation
private static IMppPresentatie PreparePresentation(AutoFake fakeScope, string fileName)
{
var app = fakeScope.Resolve<IMppApplication>();
A.CallTo(() => fakeScope.Resolve<IMppFactory>().GetApplication()).Returns(app);
var pres = fakeScope.Resolve<IMppPresentatie>();
A.CallTo(() => app.Open(fileName, true)).Returns(pres);
return pres;
}
示例3: ByDefaultConcreteTypesAreResolvedToTheSameSharedInstance
public void ByDefaultConcreteTypesAreResolvedToTheSameSharedInstance()
{
using (var fake = new AutoFake())
{
var baz1 = fake.Resolve<Baz>();
var baz2 = fake.Resolve<Baz>();
Assert.AreSame(baz1, baz2);
}
}
示例4: ByDefaultAbstractTypesAreResolvedToTheSameSharedInstance
public void ByDefaultAbstractTypesAreResolvedToTheSameSharedInstance()
{
using (var fake = new AutoFake())
{
var bar1 = fake.Resolve<IBar>();
var bar2 = fake.Resolve<IBar>();
Assert.AreSame(bar1, bar2);
}
}
示例5: ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes_Async
public async void ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes_Async()
{
using (var fake = new AutoFake(callsDoNothing: true))
{
fake.Provide<IConnectionConfigurationValues>(_connectionConfig);
FakeCalls.ProvideDefaultTransport(fake);
var getCall = FakeCalls.GetCall(fake);
//return a started task that throws
Func<ElasticsearchResponse<Dictionary<string, object>>> badTask = () => { throw new Exception(); };
var t = new Task<ElasticsearchResponse<Dictionary<string, object>>>(badTask);
t.Start();
getCall.Returns(t);
var client = fake.Resolve<ElasticsearchClient>();
client.Settings.MaxRetries.Should().Be(_retries);
try
{
var result = await client.InfoAsync();
}
catch (AggregateException ae)
{
Assert.AreEqual(typeof(MaxRetryException), ae.InnerException.GetType());
}
catch (Exception e)
{
Assert.AreEqual(typeof(MaxRetryException), e.GetType());
}
getCall.MustHaveHappened(Repeated.Exactly.Times(_retries + 1));
}
}
示例6: Application_Opened
public void Application_Opened()
{
using (var fake = new AutoFake())
{
var app = fake.Resolve<IMppApplication>();
A.CallTo(() => fake.Resolve<IMppFactory>().GetApplication()).Returns(app);
var sut = fake.Resolve<mppt.PowerpointFunctions>();
var dependendFiles = A.Fake<IBuilderDependendFiles>();
A.CallTo(() => dependendFiles.FullTemplateTheme).Returns("\testbestand.ppt");
sut.PreparePresentation(GetEmptyLiturgie(), A.Fake<IBuilderBuildSettings>(), A.Fake<IBuilderBuildDefaults>(), dependendFiles, null);
sut.GeneratePresentation();
A.CallTo(() => app.Open(dependendFiles.FullTemplateTheme, true)).MustHaveHappened();
}
}
示例7: IfResponseIsKnowError_DoNotRetry_ThrowServerException
public void IfResponseIsKnowError_DoNotRetry_ThrowServerException(int status, string exceptionType, string exceptionMessage)
{
var response = CreateServerExceptionResponse(status, exceptionType, exceptionMessage);
using (var fake = new AutoFake(callsDoNothing: true))
{
var connectionPool = new StaticConnectionPool(new[]
{
new Uri("http://localhost:9200"),
new Uri("http://localhost:9201"),
});
var connectionConfiguration = new ConnectionConfiguration(connectionPool)
.ThrowOnElasticsearchServerExceptions()
.ExposeRawResponse(false);
fake.Provide<IConnectionConfigurationValues>(connectionConfiguration);
FakeCalls.ProvideDefaultTransport(fake);
var pingCall = FakeCalls.PingAtConnectionLevel(fake);
pingCall.Returns(FakeResponse.Ok(connectionConfiguration));
var getCall = FakeCalls.GetSyncCall(fake);
getCall.Returns(FakeResponse.Any(connectionConfiguration, status, response: response));
var client = fake.Resolve<ElasticsearchClient>();
var e = Assert.Throws<ElasticsearchServerException>(()=>client.Info());
AssertServerErrorsOnResponse(e, status, exceptionType, exceptionMessage);
//make sure a know ElasticsearchServerException does not cause a retry
//In this case we want to fail early
getCall.MustHaveHappened(Repeated.Exactly.Once);
}
}
示例8: FailEarlyIfTimeoutIsExhausted_Async
public void FailEarlyIfTimeoutIsExhausted_Async()
{
using (var fake = new AutoFake())
{
var dateTimeProvider = ProvideDateTimeProvider(fake);
var config = ProvideConfiguration(dateTimeProvider);
var connection = ProvideConnection(fake, config, dateTimeProvider);
var getCall = FakeCalls.GetCall(fake);
var ok = Task.FromResult(FakeResponse.Ok(config));
var bad = Task.FromResult(FakeResponse.Bad(config));
getCall.ReturnsNextFromSequence(
bad,
bad,
ok
);
var seenNodes = new List<Uri>();
getCall.Invokes((Uri u, IRequestConfiguration o) => seenNodes.Add(u));
var pingCall = FakeCalls.PingAtConnectionLevelAsync(fake);
pingCall.Returns(ok);
var client1 = fake.Resolve<ElasticsearchClient>();
//event though the third node should have returned ok, the first 2 calls took a minute
var e = Assert.Throws<MaxRetryException>(async () => await client1.InfoAsync());
e.Message.Should()
.StartWith("Retry timeout 00:01:00 was hit after retrying 1 times:");
IElasticsearchResponse response = null;
Assert.DoesNotThrow(async () => response = await client1.InfoAsync() );
response.Should().NotBeNull();
response.Success.Should().BeTrue();
}
}
示例9: ServerExceptionIsCaught_KeepResponse
public void ServerExceptionIsCaught_KeepResponse(int status, string exceptionType, string exceptionMessage)
{
var response = CreateServerExceptionResponse(status, exceptionType, exceptionMessage);
using (var fake = new AutoFake(callsDoNothing: true))
{
var connectionConfiguration = new ConnectionConfiguration()
.ExposeRawResponse(true);
fake.Provide<IConnectionConfigurationValues>(connectionConfiguration);
FakeCalls.ProvideDefaultTransport(fake);
var getCall = FakeCalls.GetSyncCall(fake);
getCall.Returns(FakeResponse.Bad(connectionConfiguration, response: response));
var client = fake.Resolve<ElasticsearchClient>();
var result = client.Info();
result.Success.Should().BeFalse();
AssertServerErrorsOnResponse(result, status, exceptionType, exceptionMessage);
result.ResponseRaw.Should().NotBeNull();
getCall.MustHaveHappened(Repeated.Exactly.Once);
}
}
示例10: ByDefaultFakesAreNotStrict
public void ByDefaultFakesAreNotStrict()
{
using (var fake = new AutoFake())
{
var foo = fake.Resolve<Foo>();
Assert.DoesNotThrow(() => foo.Go());
}
}
示例11: ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes
public void ThrowsOutOfNodesException_AndRetriesTheSpecifiedTimes()
{
using (var fake = new AutoFake(callsDoNothing: true))
{
fake.Provide<IConnectionConfigurationValues>(_connectionConfig);
this.ProvideTransport(fake);
var getCall = A.CallTo(() => fake.Resolve<IConnection>().GetSync(A<Uri>._));
getCall.Throws<Exception>();
var client = fake.Resolve<ElasticsearchClient>();
client.Settings.MaxRetries.Should().Be(_retries);
Assert.Throws<OutOfNodesException>(()=> client.Info());
getCall.MustHaveHappened(Repeated.Exactly.Times(_retries + 1));
}
}
示例12: TestContext
public void TestContext()
{
using (var fake = new AutoFake(false, false, false, null, AutofacInstaller.Register()))
{
//var listValueModel = GetListDataInCsv();
var sawEditorPullService = fake.Resolve<ICornerstoneListsRepository>();
var result = sawEditorPullService.GetListCornerstoneLists();
Console.WriteLine("List WorkerId: {0}", string.Join(",", result.Select(x => x.Id)));
}
}
示例13: SniffIsCalledAfterItHasGoneOutOfDate
public void SniffIsCalledAfterItHasGoneOutOfDate()
{
using (var fake = new AutoFake())
{
var dateTimeProvider = fake.Resolve<IDateTimeProvider>();
var nowCall = A.CallTo(()=>dateTimeProvider.Now());
nowCall.ReturnsNextFromSequence(
DateTime.UtcNow, //initial sniff time (set even if not sniff_on_startup
DateTime.UtcNow, //info call 1
DateTime.UtcNow, //info call 2
DateTime.UtcNow.AddMinutes(10), //info call 3
DateTime.UtcNow.AddMinutes(10), //set now after sniff 3
DateTime.UtcNow.AddMinutes(20), //info call 4
DateTime.UtcNow.AddMinutes(20), //set now after sniff 4
DateTime.UtcNow.AddMinutes(22) //info call 5
);
var uris = new[] { new Uri("http://localhost:9200") };
var connectionPool = new SniffingConnectionPool(uris);
var config = new ConnectionConfiguration(connectionPool)
.SniffLifeSpan(TimeSpan.FromMinutes(4));
fake.Provide<IConnectionConfigurationValues>(config);
var transport = FakeCalls.ProvideDefaultTransport(fake, dateTimeProvider);
var connection = fake.Resolve<IConnection>();
var sniffCall = FakeCalls.Sniff(fake, config, uris);
var pingCall = FakeCalls.PingAtConnectionLevel(fake);
pingCall.Returns(FakeResponse.Ok(config));
var getCall = FakeCalls.GetSyncCall(fake);
getCall.Returns(FakeResponse.Ok(config));
var client1 = fake.Resolve<ElasticsearchClient>();
var result = client1.Info(); //info call 1
result = client1.Info(); //info call 2
result = client1.Info(); //info call 3
result = client1.Info(); //info call 4
result = client1.Info(); //info call 5
sniffCall.MustHaveHappened(Repeated.Exactly.Twice);
nowCall.MustHaveHappened(Repeated.Exactly.Times(8));
}
}
示例14: CallInfo40000TimesOnMultipleThreads
public void CallInfo40000TimesOnMultipleThreads()
{
using (var fake = new AutoFake(callsDoNothing: true))
{
//set up connection configuration that holds a connection pool
//with '_uris' (see the constructor)
fake.Provide<IConnectionConfigurationValues>(_config);
//we want to use our special concurrencytestconnection
//this randonly throws on any node but 9200 and sniffing will represent a different
//view of the cluster each time but always holding node 9200
fake.Provide<IConnection>(new ConcurrencyTestConnection(this._config));
//prove a real Transport with its unspecified dependencies
//as fakes
FakeCalls.ProvideDefaultTransport(fake);
//create a real ElasticsearchClient with it unspecified dependencies as fakes
var client = fake.Resolve<ElasticsearchClient>();
int seen = 0;
//We'll call Info() 10.000 times on 4 threads
//This should not throw any exceptions even if connections sometime fail at a node level
//because node 9200 is always up and running
Assert.DoesNotThrow(()=>
{
Action a = () =>
{
for(var i=0;i<10000;i++)
{
client.Info<VoidResponse>();
Interlocked.Increment(ref seen);
}
};
var thread1 = new Thread(()=>a());
var thread2 = new Thread(()=>a());
var thread3 = new Thread(()=>a());
var thread4 = new Thread(()=>a());
thread1.Start();
thread2.Start();
thread3.Start();
thread4.Start();
thread1.Join();
thread2.Join();
thread3.Join();
thread4.Join();
});
//we should have seen 40.000 increments
//Sadly we can't use FakeItEasy's to ensure get is called 40.000 times
//because it internally uses fixed arrays that will overflow :)
seen.Should().Be(40000);
}
}
示例15: AConnectionMustBeMadeEvenIfAllNodesAreDead
public void AConnectionMustBeMadeEvenIfAllNodesAreDead()
{
using (var fake = new AutoFake(callsDoNothing: true))
{
//make sure we retry one more time then we have nodes
//original call + 4 retries == 5
fake.Provide<IConnectionConfigurationValues>(
new ConnectionConfiguration(_connectionPool)
.MaximumRetries(4)
);
//set up our GET to / to return 4 503's followed by a 200
var getCall = A.CallTo(() =>
fake.Resolve<IConnection>().GetSync<Dictionary<string, object>>(A<Uri>._, A<object>._));
getCall.ReturnsNextFromSequence(
ElasticsearchResponse<Dictionary<string, object>>.Create(_config, 503, "GET", "/", null),
ElasticsearchResponse<Dictionary<string, object>>.Create(_config, 503, "GET", "/", null),
ElasticsearchResponse<Dictionary<string, object>>.Create(_config, 503, "GET", "/", null),
ElasticsearchResponse<Dictionary<string, object>>.Create(_config, 503, "GET", "/", null),
ElasticsearchResponse<Dictionary<string, object>>.Create(_config, 200, "GET", "/", null)
);
var pingCall = A.CallTo(() => fake.Resolve<IConnection>().Ping(A<Uri>._));
pingCall.Returns(true);
//setup client
this.ProvideTransport(fake);
var client = fake.Resolve<ElasticsearchClient>();
//Do not throw because by miracle the 4th retry manages to give back a 200
//even if all nodes have been marked dead.
Assert.DoesNotThrow(()=> client.Info());
//original call + 4 retries == 5
getCall.MustHaveHappened(Repeated.Exactly.Times(5));
//ping must have been send out 4 times to the 4 nodes being used for the first time
pingCall.MustHaveHappened(Repeated.Exactly.Times(4));
}
}