public async Task SynchronizeInsertShouldRemoveIdAndTimestamp() { ISynchronizer synchronizer = new TimestampSynchronizer(this.storage.Object); #region Setup HttpRequestMessage req = null; string sendjson = null; this.storage.Setup(iss => iss.GetStoredData(It.IsAny<string>(), It.Is<IQueryOptions>(iqo => iqo.Filter.RawValue.Equals("status ne 0")))).Returns(() => { return Task.FromResult(new JArray(JObject.Parse( @"{ ""id"": ""B1A60844-236A-43EA-851F-7DCD7D5755FA"", ""status"": 1, ""__version"": ""00000000"", ""text"": ""text"" }" ))); }); this.http.Setup(h => h.SendAsync(It.IsAny<HttpRequestMessage>())) .Returns<HttpRequestMessage>(async r => { req = r; sendjson = await r.Content.ReadAsStringAsync(); return new HttpResponseMessage() { Content = responseContent }; }); #endregion await synchronizer.UploadChanges(new Uri("http://localhost/tables/table/"), this.http.Object); Assert.IsNotNull(req); IDictionary<string, JToken> obj = JObject.Parse(sendjson); Assert.IsTrue(obj.ContainsKey("id")); Assert.IsFalse(obj.ContainsKey("status")); Assert.IsFalse(obj.ContainsKey("__version")); Assert.AreEqual(HttpMethod.Post, req.Method); }
public async Task SynchronizeDeleteShouldAddIdAndVersionToUrlAndSendEmptyBody() { ISynchronizer synchronizer = new TimestampSynchronizer(this.storage.Object); #region Setup HttpRequestMessage req = null; this.storage.Setup(iss => iss.GetStoredData(It.IsAny<string>(), It.Is<IQueryOptions>(iqo => iqo.Filter.RawValue.Equals("status ne 0")))).Returns(() => { return Task.FromResult(new JArray(JObject.Parse( @"{ ""id"": ""B1A60844-236A-43EA-851F-7DCD7D5755FA"", ""status"": 3, ""__version"": ""00000000"", ""text"": ""text"" }" ))); }); this.http.Setup(h => h.SendAsync(It.IsAny<HttpRequestMessage>())) .Callback<HttpRequestMessage>(r => req = r) .Returns(() => Task.FromResult(new HttpResponseMessage() { Content = responseContent })); #endregion await synchronizer.UploadChanges(new Uri("http://localhost/tables/table/"), this.http.Object); Assert.IsNotNull(req); HttpContent sendContent = req.Content; Assert.IsNull(sendContent); Assert.AreEqual(HttpMethod.Delete, req.Method); Assert.IsTrue(req.RequestUri.OriginalString.EndsWith("B1A60844-236A-43EA-851F-7DCD7D5755FA?version=00000000")); }