public void AddDocument(string docId, IDictionary <string, object> properties)
        {
            var docJson = Manager.GetObjectMapper().WriteValueAsString(properties);
            // push a document to server
            var replicationUrlTrailingDoc1 = new Uri(string.Format("{0}/{1}", _remoteUri, docId));
            var pathToDoc1 = new Uri(replicationUrlTrailingDoc1, docId);

            LiteTestCase.WriteDebug("Send http request to " + pathToDoc1);
            try
            {
                HttpResponseMessage response;
                var request = new HttpRequestMessage();
                request.Headers.Add("Accept", "*/*");

                var postTask = _httpClient.PutAsync(pathToDoc1.AbsoluteUri, new StringContent(docJson, Encoding.UTF8, "application/json"));
                response = postTask.Result;
                var statusLine = response.StatusCode;
                LiteTestCase.WriteDebug("Got response: " + statusLine);
                Assert.IsTrue(statusLine == HttpStatusCode.Created);
            }
            catch (ProtocolViolationException e)
            {
                Assert.IsNull(e, "Got ClientProtocolException: " + e.Message);
            }
            catch (IOException e)
            {
                Assert.IsNull(e, "Got IOException: " + e.Message);
            }

            WorkaroundSyncGatewayRaceCondition();
        }
        private Stream GetAsset(string name)
        {
            var assetPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".Assets." + name;

            LiteTestCase.WriteDebug("Fetching assembly resource: " + assetPath);
            var stream = GetType().Assembly.GetManifestResourceStream(assetPath);

            return(stream);
        }
        public void VerifyDocumentExists(string docId)
        {
            var pathToDoc = _remoteUri.AppendPath(docId);

            LiteTestCase.WriteDebug("Send http request to " + pathToDoc);

            var httpRequestDoneSignal = new CountdownEvent(1);

            Task.Factory.StartNew(() =>
            {
                HttpResponseMessage response;
                string responseString = null;
                try
                {
                    var responseTask = _httpClient.GetAsync(pathToDoc.ToString());
                    response         = responseTask.Result;
                    var statusLine   = response.StatusCode;
                    Assert.IsTrue(statusLine == HttpStatusCode.OK);
                    if (statusLine == HttpStatusCode.OK)
                    {
                        var responseStringTask = response.Content.ReadAsStringAsync();
                        responseStringTask.Wait(TimeSpan.FromSeconds(10));
                        responseString = responseStringTask.Result;
                        Assert.IsTrue(responseString.Contains(docId));
                        LiteTestCase.WriteDebug("result: " + responseString);
                    }
                    else
                    {
                        var statusReason = response.ReasonPhrase;
                        response.Dispose();
                        throw new IOException(statusReason);
                    }
                }
                catch (ProtocolViolationException e)
                {
                    Assert.IsNull(e, "Got ClientProtocolException: " + e.Message);
                }
                catch (IOException e)
                {
                    Assert.IsNull(e, "Got IOException: " + e.Message);
                }

                httpRequestDoneSignal.Signal();
            });

            var result = httpRequestDoneSignal.Wait(TimeSpan.FromSeconds(30));

            Assert.IsTrue(result, "Could not retrieve the new doc from the sync gateway.");
        }