• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# AutoFake类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ProvideDefaultTransport

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


示例17: 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);
            }
        }
开发者ID:herqueles3,项目名称:elasticsearch-net,代码行数:53,代码来源:ConcurrencyTests.cs


示例18: SniffCalledOnceAndEachEnpointPingedOnce

		public void SniffCalledOnceAndEachEnpointPingedOnce()
		{
			using (var fake = new AutoFake(callsDoNothing: true))
			{
				//It's recommended to only have on instance of your connection pool
				//Be sure to register it as Singleton in your IOC
				var uris = new[] { new Uri("http://localhost:9200"), new Uri("http://localhost:9201") };
				var connectionPool = new SniffingConnectionPool(uris);
				var config = new ConnectionConfiguration(connectionPool)
					.SniffOnStartup();
				fake.Provide<IConnectionConfigurationValues>(config);

				var pingCall = FakeCalls.PingAtConnectionLevel(fake);
				pingCall.Returns(FakeResponse.Ok(config));
				var sniffCall = FakeCalls.Sniff(fake, config, uris);
				var getCall = FakeCalls.GetSyncCall(fake);
				getCall.Returns(FakeResponse.Ok(config));

				var transport1 = FakeCalls.ProvideRealTranportInstance(fake);
				var transport2 = FakeCalls.ProvideRealTranportInstance(fake);
				var transport3 = FakeCalls.ProvideRealTranportInstance(fake);
				var transport4 = FakeCalls.ProvideRealTranportInstance(fake);

				transport1.Should().NotBe(transport2);

				var client1 = new ElasticsearchClient(config, transport: transport1);
				client1.Info();
				client1.Info();
				client1.Info();
				client1.Info();
				var client2 = new ElasticsearchClient(config, transport: transport2); 
				client2.Info();
				client2.Info();
				client2.Info();
				client2.Info();
				var client3 = new ElasticsearchClient(config, transport: transport3); 
				client3.Info();
				client3.Info();
				client3.Info();
				client3.Info();
				var client4 = new ElasticsearchClient(config, transport: transport4); 
				client4.Info();
				client4.Info();
				client4.Info();
				client4.Info();

				sniffCall.MustHaveHappened(Repeated.Exactly.Once);
				//sniff validates first node, one new node should be pinged before usage.
				pingCall.MustHaveHappened(Repeated.Exactly.Once);
			}
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:51,代码来源:SniffingConnectionPoolTests.cs


示例19: Application_Saved

            public void Application_Saved(string saveAsFileName)
            {
                using (var fake = new AutoFake())
                {
                    var dependendFiles = A.Fake<IBuilderDependendFiles>();
                    A.CallTo(() => dependendFiles.FullTemplateTheme).Returns("\testbestand.ppt");
                    var pres = PreparePresentation(fake, dependendFiles.FullTemplateTheme);
                    var sut = fake.Resolve<mppt.PowerpointFunctions>();
                    sut.PreparePresentation(GetEmptyLiturgie(), A.Fake<IBuilderBuildSettings>(), A.Fake<IBuilderBuildDefaults>(), dependendFiles, saveAsFileName);

                    sut.GeneratePresentation();

                    A.CallTo(() => pres.OpslaanAls(saveAsFileName)).MustHaveHappened();
                }
            }
开发者ID:ErikDeRoos,项目名称:koningskerk-beamteam,代码行数:15,代码来源:PowerpointFunctionsTests.cs


示例20: SniffAsync

        public static IReturnValueConfiguration<Task<ElasticsearchResponse<Stream>>> SniffAsync(
			AutoFake fake, 
			IConnectionConfigurationValues configurationValues = null,
			IList<Uri> nodes = null
			)
        {
            var sniffCall = A.CallTo(() => fake.Resolve<IConnection>().Get(
                A<Uri>.That.Matches(IsSniffUrl()),
                A<IRequestConnectionConfiguration>._));
            if (nodes == null) return sniffCall;
            var stream = SniffResponse(nodes);
            var response = FakeResponse.Ok(configurationValues, "GET", "/_nodes/_all/clear", stream);
            sniffCall.Returns(Task.FromResult(response));
            return sniffCall;
        }
开发者ID:herqueles3,项目名称:elasticsearch-net,代码行数:15,代码来源:FakeCalls.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AutoIndentEventArgs类代码示例发布时间:2022-05-24
下一篇:
C# AuthorizationContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap