当前位置: 首页>>代码示例>>C#>>正文


C# AutoFake类代码示例

本文整理汇总了C#中AutoFake的典型用法代码示例。如果您正苦于以下问题:C# AutoFake类的具体用法?C# AutoFake怎么用?C# AutoFake使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AutoFake类属于命名空间,在下文中一共展示了AutoFake类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProvideTransport

		private ITransport ProvideTransport(AutoFake fake)
		{
			var dateTimeParam = new TypedParameter(typeof(IDateTimeProvider), null);
			var memoryStreamParam = new TypedParameter(typeof(IMemoryStreamProvider), null);
			var serializerParam = new TypedParameter(typeof(IElasticsearchSerializer), null);
			return fake.Provide<ITransport, Transport>(dateTimeParam, serializerParam, memoryStreamParam);
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:7,代码来源:StaticConnectionPoolTests.cs

示例2: 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));

			}
		}
开发者ID:kowalot,项目名称:elasticsearch-net,代码行数:27,代码来源:RetryTests.cs

示例3: 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();
			}
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:35,代码来源:DontRetryAfterDefaultTimeoutTests.cs

示例4: IfResponseIsKnowError_DoNotRetry_ThrowServerException_Async

		public void IfResponseIsKnowError_DoNotRetry_ThrowServerException_Async(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.PingAtConnectionLevelAsync(fake);
				pingCall.Returns(FakeResponse.OkAsync(connectionConfiguration));

				var getCall = FakeCalls.GetCall(fake);
				getCall.Returns(FakeResponse.AnyAsync(connectionConfiguration, status, response: response));

				var client = fake.Resolve<ElasticsearchClient>();

				var e = Assert.Throws<ElasticsearchServerException>(async ()=>await client.InfoAsync());
				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);

			}
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:35,代码来源:ServerExceptionRetryHandlingTests.cs

示例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));

			}
		}
开发者ID:paigecook,项目名称:elasticsearch-net,代码行数:33,代码来源:RetryTests.cs

示例6: 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);

            }
        }
开发者ID:herqueles3,项目名称:elasticsearch-net,代码行数:26,代码来源:ElasticsearchServerExceptions.cs

示例7: ServerExceptionIsCaught_DiscardResponse

		public void ServerExceptionIsCaught_DiscardResponse(int status, string exceptionType, string exceptionMessage)
		{
			var response = CreateServerExceptionResponse(status, exceptionType, exceptionMessage);
			using (var fake = new AutoFake(callsDoNothing: true))
			{
				this.Call(status, exceptionType, exceptionMessage, fake, response);
			}
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:8,代码来源:ThrownElasticsearchServerExceptions.cs

示例8: ServerExceptionIsCaught_KeepResponse_Async

		public void ServerExceptionIsCaught_KeepResponse_Async(int status, string exceptionType, string exceptionMessage)
		{
			var response = CreateServerExceptionResponse(status, exceptionType, exceptionMessage);
			using (var fake = new AutoFake(callsDoNothing: true))
			{
				this.CallAsync(status, exceptionType, exceptionMessage, fake, response, exposeRawResponse: true);
			}
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:8,代码来源:ThrownElasticsearchServerExceptions.cs

示例9: 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;
 }
开发者ID:ErikDeRoos,项目名称:koningskerk-beamteam,代码行数:8,代码来源:PowerpointFunctionsTests.cs

示例10: ByDefaultFakesAreNotStrict

 public void ByDefaultFakesAreNotStrict()
 {
     using (var fake = new AutoFake())
     {
         var foo = fake.Resolve<Foo>();
         Assert.DoesNotThrow(() => foo.Go());
     }
 }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:8,代码来源:AutoFakeFixture.cs

示例11: 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 result = this.Call(status, exceptionType, exceptionMessage, fake, response, exposeRawResponse: true);
				result.ResponseRaw.Should().NotBeNull();
			}
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:9,代码来源:ElasticsearchServerExceptions.cs

示例12: ServerExceptionIsCaught_DiscardResponse_Async

		public async void ServerExceptionIsCaught_DiscardResponse_Async(int status, string exceptionType, string exceptionMessage)
		{
			var response = CreateServerExceptionResponse(status, exceptionType, exceptionMessage);
			using (var fake = new AutoFake(callsDoNothing: true))
			{
				var result = await this.CallAsync(status, exceptionType, exceptionMessage, fake, response);
				result.ResponseRaw.Should().BeNull();
			}
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:9,代码来源:ElasticsearchServerExceptions.cs

示例13: ByDefaultAbstractTypesAreResolvedToTheSameSharedInstance

        public void ByDefaultAbstractTypesAreResolvedToTheSameSharedInstance()
        {
            using (var fake = new AutoFake())
            {
                var bar1 = fake.Resolve<IBar>();
                var bar2 = fake.Resolve<IBar>();

                Assert.AreSame(bar1, bar2);
            }
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:10,代码来源:AutoFakeFixture.cs

示例14: 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)));
     }
 }
开发者ID:linhtuan48,项目名称:DemoDbContext,代码行数:10,代码来源:DemoDbcontext.cs

示例15: ByDefaultConcreteTypesAreResolvedToTheSameSharedInstance

        public void ByDefaultConcreteTypesAreResolvedToTheSameSharedInstance()
        {
            using (var fake = new AutoFake())
            {
                var baz1 = fake.Resolve<Baz>();
                var baz2 = fake.Resolve<Baz>();

                Assert.AreSame(baz1, baz2);
            }
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:10,代码来源:AutoFakeFixture.cs


注:本文中的AutoFake类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。