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


C# AutoFake.Provide方法代码示例

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


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

示例1: TestInitializer

        public void TestInitializer()
        {
            // initialize fake context
            _fakeContext = InitializeFakeContext<FacilitiesController>();

            // explicitly create fake dependencies that need to be intercepted
            //  (all other fake dependencies will be implicitly created by _fakeContext.Resolve<>)
            _fakeBusinessFacade = A.Fake<IBusinessFacade>();
            _fakeLoadedSubscriber = A.Fake<ILoadedSubscriber>();
            _fakeCurrentLocation = A.Fake<ILoadedLocation>();
            _fakeCurrentUser = A.Fake<ILoggedInUser>();
            _fakePermissions = A.Fake<IPermissions>();

            // provide fake dependencies to context
            _fakeContext.Provide(_fakeBusinessFacade);
            _fakeContext.Provide(_fakeLoadedSubscriber);
            _fakeContext.Provide(_fakeCurrentLocation);
            _fakeContext.Provide(_fakeCurrentUser);
            _fakeContext.Provide(_fakePermissions);

            // create system-under-test instance
            _facilitiesControllerForTest = _fakeContext.Resolve<FacilitiesController>();

            // create fake data
            _usiForTest = TestDataRepository.GetUsiForTest();
            _locationIdForTest = TestDataRepository.GetLocationIdForTest();
            _serviceAddressControlNumberForTests = TestDataRepository.GetServiceAddressControlNumberForTest();
            _dpiRegionForTests = TestDataRepository.GetDpiRegionForTest();
        }
开发者ID:borealwinter,项目名称:simpl,代码行数:29,代码来源:FacilitiesControllerTests.cs

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

示例3: 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

示例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: 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

示例7: 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

示例8: 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);
                //prove a real HttpTransport with its unspecified dependencies
                //as fakes

                var connection = fake.Provide<IConnection>(new ConcurrencyTestConnection(this._config));
                this.ProvideTransport(fake);
                //create a real ElasticsearchClient with it unspecified dependencies as fakes
                var client = fake.Resolve<ElasticsearchClient>();
                int seen = 0;
                Assert.DoesNotThrow(()=>
                {
                    Action a = () =>
                    {
                        for(var i=0;i<10000;i++)
                        {
                            client.Info();
                            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();

                });
                seen.Should().Be(40000);
            }
        }
开发者ID:kowalot,项目名称:elasticsearch-net,代码行数:42,代码来源:ConcurrencyTests.cs

示例9: 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

示例10: ThrowsException

        public void ThrowsException()
        {
            using (var fake = new AutoFake(callsDoNothing: true))
            {
                fake.Provide<IConnectionConfigurationValues>(_connectionConfig);
                FakeCalls.ProvideDefaultTransport(fake);

                var getCall = FakeCalls.GetSyncCall(fake);
                getCall.Throws<Exception>();

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

                Assert.Throws<Exception>(() => client.Info());
                getCall.MustHaveHappened(Repeated.Exactly.Once);

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

示例11: ShouldNotRetryOn500

		public void ShouldNotRetryOn500()
		{
			using (var fake = new AutoFake(callsDoNothing: true))
			{
				fake.Provide<IConnectionConfigurationValues>(_connectionConfig);
				FakeCalls.ProvideDefaultTransport(fake);

				var getCall = FakeCalls.GetSyncCall(fake);
				getCall.Returns(FakeResponse.Any(_connectionConfig, 500));

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

				Assert.DoesNotThrow(() => client.Info());
				getCall.MustHaveHappened(Repeated.Exactly.Once);

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

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

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

示例13: ShouldNotRetryWhenMaxRetriesIs0_Async

		public void ShouldNotRetryWhenMaxRetriesIs0_Async()
		{
			using (var fake = new AutoFake(callsDoNothing: true))
			{
				var connectionConfiguration = new ConnectionConfiguration().MaximumRetries(0);
				fake.Provide<IConnectionConfigurationValues>(connectionConfiguration);
				FakeCalls.ProvideDefaultTransport(fake);

				var getCall = FakeCalls.GetCall(fake);
				getCall.Returns(FakeResponse.Bad(connectionConfiguration));

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

				Assert.DoesNotThrow(async () => await client.InfoAsync());
				getCall.MustHaveHappened(Repeated.Exactly.Once);

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

示例14: Call

		private void Call(int status, string exceptionType, string exceptionMessage, AutoFake fake, MemoryStream response, bool exposeRawResponse = false)
		{
			var connectionConfiguration = new ConnectionConfiguration()
				.ThrowOnElasticsearchServerExceptions()
				.ExposeRawResponse(exposeRawResponse);

			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 e = Assert.Throws<ElasticsearchServerException>(()=>client.Info());
			AssertServerErrorsException(e, status, exceptionType, exceptionMessage);
			getCall.MustHaveHappened(Repeated.Exactly.Once);
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:18,代码来源:ThrownElasticsearchServerExceptions.cs

示例15: ShouldNotRetryOn400_Async

		public async void ShouldNotRetryOn400_Async()
		{
			using (var fake = new AutoFake(callsDoNothing: true))
			{
				fake.Provide<IConnectionConfigurationValues>(_connectionConfig);
				FakeCalls.ProvideDefaultTransport(fake);

				var getCall = FakeCalls.GetCall(fake);
				var task = Task.FromResult(FakeResponse.Any(_connectionConfig, 400));
				getCall.Returns(task);

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

				var result = await client.InfoAsync();
				getCall.MustHaveHappened(Repeated.Exactly.Once);

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


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