當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。