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


C# Tests.MockHttpClientFactory类代码示例

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


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

示例1: TestFailedBulkGetDoesntChangeLastSequence

        public void TestFailedBulkGetDoesntChangeLastSequence()
        {
            if (!Boolean.Parse((string)Runtime.Properties["replicationTestsEnabled"]))
            {
                Assert.Inconclusive("Replication tests disabled.");
                return;
            }
                
            var fakeFactory = new MockHttpClientFactory(false);
            fakeFactory.HttpHandler.SetResponder("_bulk_get", (request) =>
            {
                var str = request.Content.ReadAsStringAsync().Result;
                if(str.IndexOf("doc2") != -1) {
                    Log.D(Tag, "Rejecting this bulk get because it looks like the first batch");
                    throw new OperationCanceledException();
                }

                Log.D(Tag, "Letting this bulk get through");
                return new RequestCorrectHttpMessage();
            });
            manager.DefaultHttpClientFactory = fakeFactory;
            Manager.DefaultOptions.MaxRevsToGetInBulk = 10;
            Manager.DefaultOptions.MaxOpenHttpConnections = 8;
            Manager.DefaultOptions.RequestTimeout = TimeSpan.FromSeconds(5);

            CreatePullAndTest((int)(Manager.DefaultOptions.MaxRevsToGetInBulk * 1.5), repl => {
                Log.D(Tag, "Document count increased to {0} with last sequence '{1}'", database.DocumentCount, repl.LastSequence);
                Assert.IsTrue(database.DocumentCount > 0, "Didn't get docs from second bulk get batch");
                Assert.AreEqual("0", repl.LastSequence, "LastSequence was advanced");
            });

            fakeFactory.HttpHandler.ClearResponders();
            var pull = database.CreatePullReplication(GetReplicationURL());
            RunReplication(pull);
            Assert.AreEqual(pull.ChangesCount, pull.CompletedChangesCount);
            Assert.AreNotEqual(pull.LastSequence, "0");
        }
开发者ID:woxihuanjia,项目名称:couchbase-lite-net,代码行数:37,代码来源:ReplicationTest.cs

示例2: TestHeaders

        public void TestHeaders()
        {
            if (!Boolean.Parse((string)GetProperty("replicationTestsEnabled")))
            {
                Assert.Inconclusive("Replication tests disabled.");
                return;
            }

            var mockHttpClientFactory = new MockHttpClientFactory(false);
            manager.DefaultHttpClientFactory = mockHttpClientFactory;

            var mockHttpHandler = mockHttpClientFactory.HttpHandler;

            using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
                var remote = remoteDb.RemoteUri;
                var puller = database.CreatePullReplication(remote);
                var headers = new Dictionary<string, string>();
                headers["foo"] = "bar";

                var pusher = database.CreatePushReplication (remote);
                pusher.Headers = headers;
                pusher.Start ();
                Sleep (5000);
                pusher.Stop ();

                ValidateHttpHeaders (mockHttpHandler);
                mockHttpHandler.ClearCapturedRequests ();

                puller.Headers = headers;
                puller.Start();
                Sleep(5000);
                puller.Stop();

                ValidateHttpHeaders (mockHttpHandler);
            }
        }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:36,代码来源:ReplicationTest.cs

示例3: TestServerDoesNotSupportMultipart

        public void TestServerDoesNotSupportMultipart() {
            if (!Boolean.Parse((string)GetProperty("replicationTestsEnabled")))
            {
                Assert.Inconclusive("Replication tests disabled.");
                return;
            }

            Assert.AreEqual(0, database.GetLastSequenceNumber());

            var properties1 = new Dictionary<string, object>() {
                { "dynamic", 1 }
            };

            var doc = CreateDocumentWithProperties(database, properties1);
            var rev1 = doc.CurrentRevision;

            var unsavedRev2 = doc.CreateRevision();
            var attachmentStream = GetAsset("attachment.png");
            unsavedRev2.SetAttachment("attachment.png", "image/png", attachmentStream);
            var rev2 = unsavedRev2.Save();
            attachmentStream.Dispose();
            Assert.IsNotNull(rev2);
            unsavedRev2.Dispose();

            var httpClientFactory = new MockHttpClientFactory();
            var httpHandler = httpClientFactory.HttpHandler; 
            httpHandler.AddResponderFakeLocalDocumentUpdate404();

            var responders = new List<MockHttpRequestHandler.HttpResponseDelegate>();
            responders.Add((request) => 
            {
                var json = "{\"error\":\"Unsupported Media Type\",\"reason\":\"missing\"}";
                return MockHttpRequestHandler.GenerateHttpResponseMessage(HttpStatusCode.UnsupportedMediaType, 
                    "Unsupported Media Type", json);
            });

            responders.Add((request) => 
            {
                var props = new Dictionary<string, object>()
                {
                    {"id", doc.Id},
                    {"ok", true},
                    {"rev", doc.CurrentRevisionId}

                };
                return MockHttpRequestHandler.GenerateHttpResponseMessage(props);
            });

            MockHttpRequestHandler.HttpResponseDelegate chainResponder = (request) =>
            {
                if (responders.Count > 0) {
                    var responder = responders[0];
                    responders.RemoveAt(0);
                    return responder(request);
                }
                return null;
            };

            httpHandler.SetResponder(doc.Id, chainResponder);
            manager.DefaultHttpClientFactory = httpClientFactory;

            using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
                var pusher = database.CreatePushReplication(remoteDb.RemoteUri);
                RunReplication(pusher);

                var count = 0;
                foreach (var request in httpHandler.CapturedRequests) {
                    if (request.Method == HttpMethod.Put && request.RequestUri.PathAndQuery.Contains(doc.Id)) {
                        var isMultipartContent = (request.Content is MultipartContent);
                        if (count == 0) {
                            Assert.IsTrue(isMultipartContent);
                        }
                        else {
                            Assert.IsFalse(isMultipartContent);
                        }
                        count++;
                    }
                }
            }
        }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:80,代码来源:ReplicationTest.cs

示例4: TestBulkPullPermanentExceptionSurrender

        public void TestBulkPullPermanentExceptionSurrender() {
            if (!Boolean.Parse((string)GetProperty("replicationTestsEnabled")))
            {
                Assert.Inconclusive("Replication tests disabled.");
                return;
            }

            Log.Domains.Sync.Level = Log.LogLevel.Debug;
            var fakeFactory = new MockHttpClientFactory(false);
            FlowControl flow = new FlowControl(new FlowItem[]
            {
                new ExceptionThrower(new SocketException()) { ExecutionCount = -1 },
            });

            fakeFactory.HttpHandler.SetResponder("_bulk_get", (request) => 
                flow.ExecuteNext<HttpResponseMessage>());
            manager.DefaultHttpClientFactory = fakeFactory;

            using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
                CreatePullAndTest(20, remoteDb, repl => Assert.IsTrue(database.GetDocumentCount() < 20, "Somehow got all the docs"));
            }
        }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:22,代码来源:ReplicationTest.cs

示例5: TestContinuousReplicationErrorNotification

        public void TestContinuousReplicationErrorNotification() {
            if (!Boolean.Parse((string)GetProperty("replicationTestsEnabled")))
            {
                Assert.Inconclusive("Replication tests disabled.");
                return;
            }

            var httpClientFactory = new MockHttpClientFactory();
            manager.DefaultHttpClientFactory = httpClientFactory;

            var httpHandler = httpClientFactory.HttpHandler; 
            httpHandler.AddResponderThrowExceptionAllRequests();

            using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
                var pusher = database.CreatePushReplication(remoteDb.RemoteUri);
                pusher.Continuous = true;

                var signal = new CountdownEvent(1);
                var observer = new ReplicationErrorObserver(signal);
                pusher.Changed += observer.Changed;
                pusher.Start();

                CreateDocuments(database, 10);

                var success = signal.Wait(TimeSpan.FromSeconds(30));
                Assert.IsTrue(success);

                StopReplication(pusher);
            }
        }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:30,代码来源:ReplicationTest.cs

示例6: RunPushReplicationWithTransientError

        private void RunPushReplicationWithTransientError(Int32 errorCode, string statusMessage, Boolean expectError) 
        {
            var properties1 = new Dictionary<string, object>() 
            {
                {"doc1", "testPushReplicationTransientError"}
            };
            CreateDocumentWithProperties(database, properties1);

            var httpClientFactory = new MockHttpClientFactory(false);
            var httpHandler = httpClientFactory.HttpHandler; 
            manager.DefaultHttpClientFactory = httpClientFactory;

            MockHttpRequestHandler.HttpResponseDelegate sentinal = MockHttpRequestHandler.FakeBulkDocs;

            var responders = new List<MockHttpRequestHandler.HttpResponseDelegate>();
            responders.Add(MockHttpRequestHandler.TransientErrorResponder(errorCode, statusMessage));
            MockHttpRequestHandler.HttpResponseDelegate chainResponder = (request) =>
            {
                if (responders.Count > 0) {
                    var responder = responders[0];
                    responders.RemoveAt(0);
                    return responder(request);
                }

                return sentinal(request);
            };

            httpHandler.SetResponder("_bulk_docs", chainResponder);

            // Create a replication observer to wait until replication finishes
            var replicationDoneSignal = new CountdownEvent(1);
            var replicationFinishedObserver = new ReplicationObserver(replicationDoneSignal);
            using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
                var pusher = database.CreatePushReplication(remoteDb.RemoteUri);
                pusher.Changed += replicationFinishedObserver.Changed;

                // save the checkpoint id for later usage
                var checkpointId = pusher.RemoteCheckpointDocID();

                // kick off the replication
                pusher.Start();

                // wait for it to finish
                var success = replicationDoneSignal.Wait(TimeSpan.FromSeconds(30));
                Assert.IsTrue(success);

                if (expectError) {
                    Assert.IsNotNull(pusher.LastError);
                }
                else {
                    Assert.IsNull(pusher.LastError);
                }

                // workaround for the fact that the replicationDoneSignal.Await() call could unblock before all
                // the statements in Replication.Stopped() have even had a chance to execute.
                Sleep(500);

                var localLastSequence = database.LastSequenceWithCheckpointId(checkpointId);
                if (expectError) {
                    Assert.Null(localLastSequence);
                }
                else {
                    Assert.IsNotNull(localLastSequence);
                }
            }
        }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:66,代码来源:ReplicationTest.cs

示例7: TestAllLeafRevisionsArePushed

        public void TestAllLeafRevisionsArePushed()
        {
            var httpClientFactory = new MockHttpClientFactory();
            var httpHandler = httpClientFactory.HttpHandler; 
            httpHandler.AddResponderRevDiffsAllMissing();
            httpHandler.AddResponderFakeLocalDocumentUpdate404();
            httpHandler.ResponseDelayMilliseconds = 250;
            manager.DefaultHttpClientFactory = httpClientFactory;

            var doc = database.CreateDocument();
            var rev1a = doc.CreateRevision().Save();
            var rev2a = rev1a.CreateRevision().Save();
            var rev3a = rev2a.CreateRevision().Save();

            // delete the branch we've been using, then create a new one to replace it
            var rev4a = rev3a.DeleteDocument();
            var rev2b = rev1a.CreateRevision().Save(true);

            Assert.AreEqual(rev2b.Id, doc.CurrentRevisionId);

            // sync with remote DB -- should push both leaf revisions
            var pusher = database.CreatePushReplication(GetReplicationURL());
            RunReplication(pusher);
            Assert.IsNull(pusher.LastError);

            var foundRevsDiff = false;
            var capturedRequests = httpHandler.CapturedRequests;
            foreach (var httpRequest in capturedRequests) 
            {
                var uriString = httpRequest.RequestUri.ToString();
                if (uriString.EndsWith("_revs_diff", StringComparison.Ordinal))
                {
                    foundRevsDiff = true;
                    var jsonMap = MockHttpRequestHandler.GetJsonMapFromRequest(httpRequest);
                    var revisionIds = ((JArray)jsonMap.Get(doc.Id)).Values<string>().ToList();
                    Assert.AreEqual(2, revisionIds.Count);
                    Assert.IsTrue(revisionIds.Contains(rev4a.Id));
                    Assert.IsTrue(revisionIds.Contains(rev2b.Id));
                }
            }

            Assert.IsTrue(foundRevsDiff);
        }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:43,代码来源:ReplicationTest.cs

示例8: TestLongRemovedChangesFeed

        [Test] // This test takes nearly 5 minutes to run, so only run when needed
        #endif
        public void TestLongRemovedChangesFeed()
        {
            var random = new Random();
            var changesFeed = new StringBuilder("{\"results\":[");
            const int limit = 100000;
            HashSet<string> removedIDSet = new HashSet<string>();
            for (var i = 1; i < limit; i++) {
                var removed = random.NextDouble() >= 0.5;
                if (removed) {
                    var removedID = Misc.CreateGUID();
                    changesFeed.AppendFormat("{{\"seq\":\"{0}\",\"id\":\"{1}\",\"removed\":[\"fake\"]," +
                        "\"changes\":[{{\"rev\":\"1-deadbeef\"}}]}},",
                        i, removedID);
                    removedIDSet.Add(removedID);
                } else {
                    changesFeed.AppendFormat("{{\"seq\":\"{0}\",\"id\":\"{1}\",\"changes\":[{{\"rev\":\"1-deadbeef\"}}]}},",
                        i, Misc.CreateGUID());
                }
            }

            changesFeed.AppendFormat("{{\"seq\":\"{0}\",\"id\":\"{1}\",\"changes\":[{{\"rev\":\"1-deadbeef\"}}]}}]," +
                "last_seq: \"{0}\"}}",
                limit, Misc.CreateGUID());

            var factory = new MockHttpClientFactory(false);
            factory.HttpHandler.SetResponder("_changes", req =>
            {
                var response = new HttpResponseMessage(HttpStatusCode.OK);
                var changesString = changesFeed.ToString();
                response.Content = new StringContent(changesString);

                return response;
            });

            factory.HttpHandler.SetResponder("_bulk_get", req =>
            {
                var contentStream = req.Content.ReadAsStreamAsync().Result;
                var content = Manager.GetObjectMapper().ReadValue<IDictionary<string, object>>(contentStream);

                var responseBody = new StringBuilder("--67aac1bcad803590b9a9e1999fc539438b3363fab35a24c17990188b222f\r\n");
                foreach(var obj in content["docs"] as IEnumerable) {
                    var dict = obj.AsDictionary<string, object>();
                    var nonexistent = removedIDSet.Contains(dict.GetCast<string>("id"));
                    if(nonexistent) {
                        return new HttpResponseMessage(HttpStatusCode.InternalServerError); // Just so we can know
                    } else {
                        responseBody.Append("Content-Type: application/json\r\n\r\n");
                        responseBody.AppendFormat("{{\"_id\":\"{0}\",\"_rev\":\"1-deadbeef\",\"foo\":\"bar\"}}\r\n", dict["id"]);
                    }

                    responseBody.Append("--67aac1bcad803590b9a9e1999fc539438b3363fab35a24c17990188b222f\r\n");
                }

                responseBody.Remove(responseBody.Length - 2, 2);
                responseBody.Append("--");

                var retVal = new HttpResponseMessage(HttpStatusCode.OK);
                var responseString = responseBody.ToString();
                retVal.Content = new StringContent(responseString);
                retVal.Content.Headers.Remove("Content-Type");
                retVal.Content.Headers.TryAddWithoutValidation("Content-Type", "multipart/mixed; boundary=\"67aac1bcad803590b9a9e1999fc539438b3363fab35a24c17990188b222f\"");

                return retVal;
            });

            manager.DefaultHttpClientFactory = factory;
            using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
                var puller = database.CreatePullReplication(remoteDb.RemoteUri);
                RunReplication(puller);
                Assert.AreEqual(ReplicationStatus.Stopped, puller.Status);
                Assert.AreNotEqual(limit, puller.ChangesCount);
                Assert.AreNotEqual(limit, puller.CompletedChangesCount);
                Assert.AreEqual(limit.ToString(), puller.LastSequence);
            }

            Sleep(1000);
        }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:79,代码来源:ReplicationTest.cs

示例9: ChangeTrackerTestClient

 public ChangeTrackerTestClient(CountDownLatch stoppedSignal, CountDownLatch changedSignal)
 {
     this.stoppedSignal = stoppedSignal;
     this.changedSignal = changedSignal;
     HttpClientFactory = new MockHttpClientFactory();
 }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:6,代码来源:ChangeTrackerTest.cs

示例10: TestHeaders

        public void TestHeaders()
        {
            var mockHttpClientFactory = new MockHttpClientFactory();
            manager.DefaultHttpClientFactory = mockHttpClientFactory;

            var mockHttpHandler = mockHttpClientFactory.HttpHandler;
            mockHttpHandler.AddResponderThrowExceptionAllRequests();

            Uri remote = GetReplicationURL();
            Replication puller = database.CreatePullReplication(remote);
            var headers = new Dictionary<string, string>();
            headers["foo"] = "bar";
            puller.Headers = headers;
            RunReplication(puller);
            Assert.IsNotNull(puller.LastError);

            var foundFooHeader = false;
            var requests = mockHttpHandler.CapturedRequests;

            foreach (var request in requests)
            {
                var requestHeaders = request.Headers.GetValues("foo");
                foreach (var requestHeader in requestHeaders)
                {
                    foundFooHeader = true;
                    Assert.AreEqual("bar", requestHeader);
                }
            }
            Assert.IsTrue(foundFooHeader);
        }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:30,代码来源:ReplicationTest.cs

示例11: TestChangeTrackerBackoffInvalidJson

 public void TestChangeTrackerBackoffInvalidJson() 
 {
     var factory = new MockHttpClientFactory();
     var httpHandler = (MockHttpRequestHandler)factory.HttpHandler;
     httpHandler.AddResponderReturnInvalidChangesFeedJson();
     TestChangeTrackerBackoff(factory);
 }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:7,代码来源:ChangeTrackerTest.cs

示例12: TestChangeTrackerBackoffExceptions

 public void TestChangeTrackerBackoffExceptions()
 {
     var factory = new MockHttpClientFactory();
     var httpHandler = (MockHttpRequestHandler)factory.HttpHandler;
     httpHandler.AddResponderThrowExceptionAllRequests();
     TestChangeTrackerBackoff(factory);
 }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:7,代码来源:ChangeTrackerTest.cs

示例13: TestChangeTrackerBackoff

        private void TestChangeTrackerBackoff(MockHttpClientFactory httpClientFactory)
        {
            var changeTrackerFinishedSignal = new CountDownLatch(1);
            var client = new ChangeTrackerTestClient(changeTrackerFinishedSignal, null);
            client.HttpClientFactory = httpClientFactory;

            var testUrl = GetReplicationURL();
            var scheduler = new SingleTaskThreadpoolScheduler();
            var changeTracker = new ChangeTracker(testUrl, ChangeTrackerMode.LongPoll, 0, false, client, new TaskFactory(scheduler));

            changeTracker.UsePost = IsSyncGateway(testUrl);
            changeTracker.Start();

            // sleep for a few seconds
            Thread.Sleep(15 * 1000);

            // make sure we got less than 10 requests in those 10 seconds (if it was hammering, we'd get a lot more)
            var handler = client.HttpRequestHandler;
            Assert.IsTrue(handler.CapturedRequests.Count < 25);
            Assert.IsTrue(changeTracker.backoff.NumAttempts > 0, "Observed attempts: {0}".Fmt(changeTracker.backoff.NumAttempts));

            handler.ClearResponders();
            handler.AddResponderReturnEmptyChangesFeed();

            // at this point, the change tracker backoff should cause it to sleep for about 3 seconds
            // and so lets wait 3 seconds until it wakes up and starts getting valid responses
            Thread.Sleep(3 * 1000);

            // now find the delta in requests received in a 2s period
            int before = handler.CapturedRequests.Count;
            Thread.Sleep(2 * 1000);
            int after = handler.CapturedRequests.Count;

            // assert that the delta is high, because at this point the change tracker should
            // be hammering away
            Assert.IsTrue((after - before) > 25);

            // the backoff numAttempts should have been reset to 0
            Assert.IsTrue(changeTracker.backoff.NumAttempts == 0);

            changeTracker.Stop();

            var success = changeTrackerFinishedSignal.Await(TimeSpan.FromSeconds(30));
            Assert.IsTrue(success);
        }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:45,代码来源:ChangeTrackerTest.cs

示例14: TestAllLeafRevisionsArePushed

        public void TestAllLeafRevisionsArePushed()
        {
            if (!Boolean.Parse((string)GetProperty("replicationTestsEnabled")))
            {
                Assert.Inconclusive("Replication tests disabled.");
                return;
            }

            var httpClientFactory = new MockHttpClientFactory();
            var httpHandler = httpClientFactory.HttpHandler; 
            httpHandler.AddResponderRevDiffsAllMissing();
            httpHandler.AddResponderFakeLocalDocumentUpdate404();
            httpHandler.ResponseDelayMilliseconds = 250;
            manager.DefaultHttpClientFactory = httpClientFactory;

            var doc = database.CreateDocument();
            var rev1a = doc.CreateRevision().Save();
            var rev2a = rev1a.CreateRevision().Save();
            var rev3a = rev2a.CreateRevision().Save();

            // delete the branch we've been using, then create a new one to replace it
            var rev4a = rev3a.DeleteDocument();
            var unsaved = rev1a.CreateRevision();
            unsaved.SetUserProperties(new Dictionary<string, object> { { "foo", "bar" } });
            var rev2b = unsaved.Save(true);

            Assert.AreEqual(rev2b.Id, doc.CurrentRevisionId);

            using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
                // sync with remote DB -- should push both leaf revisions
                var pusher = database.CreatePushReplication(remoteDb.RemoteUri);
                RunReplication(pusher);
                Assert.IsNull(pusher.LastError);

                var foundRevsDiff = false;
                var capturedRequests = httpHandler.CapturedRequests;
                foreach (var httpRequest in capturedRequests) {
                    var uriString = httpRequest.RequestUri.ToString();
                    if (uriString.EndsWith("_revs_diff", StringComparison.Ordinal)) {
                        foundRevsDiff = true;
                        var jsonMap = MockHttpRequestHandler.GetJsonMapFromRequest(httpRequest);
                        var revisionIds = ((JArray)jsonMap.Get(doc.Id)).Values<string>().ToList();
                        Assert.AreEqual(2, revisionIds.Count);
                        Assert.IsTrue(revisionIds.Contains(rev4a.Id));
                        Assert.IsTrue(revisionIds.Contains(rev2b.Id));
                    }
                }

                Assert.IsTrue(foundRevsDiff);
            }
        }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:51,代码来源:ReplicationTest.cs

示例15: TestContinuousReplicationErrorNotification

        public void TestContinuousReplicationErrorNotification() {
            if (!Boolean.Parse((string)Runtime.Properties["replicationTestsEnabled"]))
            {
                Assert.Inconclusive("Replication tests disabled.");
                return;
            }

            var httpClientFactory = new MockHttpClientFactory();
            manager.DefaultHttpClientFactory = httpClientFactory;

            var httpHandler = httpClientFactory.HttpHandler; 
            httpHandler.AddResponderThrowExceptionAllRequests();

            var pusher = database.CreatePushReplication(GetReplicationURL());
            pusher.Continuous = true;

            var signal = new CountdownEvent(1);
            var observer = new ReplicationErrorObserver(signal);
            pusher.Changed += observer.Changed;
            pusher.Start();

            var success = signal.Wait(TimeSpan.FromSeconds(30));
            Assert.IsTrue(success);

            pusher.Stop();
        }
开发者ID:ertrupti9,项目名称:couchbase-lite-net,代码行数:26,代码来源:ReplicationTest.cs


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