本文整理汇总了C#中Microsoft.WindowsAzure.MobileServices.Test.TestHttpHandler类的典型用法代码示例。如果您正苦于以下问题:C# TestHttpHandler类的具体用法?C# TestHttpHandler怎么用?C# TestHttpHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestHttpHandler类属于Microsoft.WindowsAzure.MobileServices.Test命名空间,在下文中一共展示了TestHttpHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadAsyncWithStringIdTypeAndStringIdResponseContent
public async Task ReadAsyncWithStringIdTypeAndStringIdResponseContent()
{
string[] testIdData = IdTestData.ValidStringIds.Concat(
IdTestData.EmptyStringIds).Concat(
IdTestData.InvalidStringIds).ToArray();
foreach (string testId in testIdData)
{
TestHttpHandler hijack = new TestHttpHandler();
// Make the testId JSON safe
string jsonTestId = testId.Replace("\\", "\\\\").Replace("\"", "\\\"");
hijack.SetResponseContent("[{\"id\":\"" + jsonTestId + "\",\"String\":\"Hey\"}]");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
IMobileServiceTable<StringIdType> table = service.GetTable<StringIdType>();
IEnumerable<StringIdType> results = await table.ReadAsync();
StringIdType[] items = results.ToArray();
Assert.AreEqual(1, items.Count());
Assert.AreEqual(testId, items[0].Id);
Assert.AreEqual("Hey", items[0].String);
}
}
示例2: ReadAsync_WithRelativeUri_Generic
public async Task ReadAsync_WithRelativeUri_Generic()
{
var data = new[]
{
new
{
ServiceUri = "http://www.test.com",
QueryUri = "/about?$filter=a eq b&$orderby=c",
RequestUri = "http://www.test.com/about?$filter=a eq b&$orderby=c"
},
new
{
ServiceUri = "http://www.test.com/",
QueryUri = "/about?$filter=a eq b&$orderby=c",
RequestUri = "http://www.test.com/about?$filter=a eq b&$orderby=c"
}
};
foreach (var item in data)
{
var hijack = new TestHttpHandler();
hijack.SetResponseContent("[{\"col1\":\"Hey\"}]");
IMobileServiceClient service = new MobileServiceClient(item.ServiceUri, "secret...", hijack);
IMobileServiceTable<ToDo> table = service.GetTable<ToDo>();
await table.ReadAsync<ToDo>(item.QueryUri);
Assert.AreEqual("TT", hijack.Request.Headers.GetValues("X-ZUMO-FEATURES").First());
Assert.AreEqual(item.RequestUri, hijack.Request.RequestUri.ToString());
}
}
示例3: PullAsync_Cancels_WhenCancellationTokenIsCancelled
public async Task PullAsync_Cancels_WhenCancellationTokenIsCancelled()
{
var store = new MobileServiceLocalStoreMock();
var handler = new MobileServiceSyncHandlerMock();
handler.TableOperationAction = op => Task.Delay(TimeSpan.MaxValue).ContinueWith<JObject>(t => null); // long slow operation
var hijack = new TestHttpHandler();
hijack.OnSendingRequest = async req =>
{
await Task.Delay(1000);
return req;
};
IMobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);
await service.SyncContext.InitializeAsync(store, handler);
IMobileServiceSyncTable table = service.GetSyncTable("someTable");
using (var cts = new CancellationTokenSource())
{
Task pullTask = table.PullAsync(null, null, null, cancellationToken: cts.Token);
cts.Cancel();
var ex = await ThrowsAsync<Exception>(() => pullTask);
Assert.IsTrue((ex is OperationCanceledException || ex is TaskCanceledException));
Assert.AreEqual(pullTask.Status, TaskStatus.Canceled);
}
}
示例4: DoesNotRewireSingleWiredDelegatingHandler
public void DoesNotRewireSingleWiredDelegatingHandler()
{
string appUrl = MobileAppUriValidator.DummyMobileApp;
TestHttpHandler innerHandler = new TestHttpHandler();
DelegatingHandler wiredHandler = new TestHttpHandler();
wiredHandler.InnerHandler = innerHandler;
IMobileServiceClient service = new MobileServiceClient(appUrl, handlers: wiredHandler);
Assert.AreEqual(wiredHandler.InnerHandler, innerHandler, "The prewired handler passed in should not have been rewired");
}
示例5: DateOffsetUri
public async Task DateOffsetUri()
{
TestHttpHandler hijack = new TestHttpHandler();
IMobileServiceClient client = new MobileServiceClient("http://www.test.com", null, hijack);
IMobileServiceTable<DateOffsetExample> table = client.GetTable<DateOffsetExample>();
hijack.Response.StatusCode = HttpStatusCode.OK;
hijack.SetResponseContent("[]");
DateTimeOffset date = new DateTimeOffset(2009, 11, 21, 14, 22, 59, 860, TimeSpan.FromHours(-8));
await table.Where(b => b.Date == date).ToEnumerableAsync();
Assert.EndsWith(hijack.Request.RequestUri.ToString(), "$filter=(DateOffsetExampleDate eq datetimeoffset'2009-11-21T14:22:59.8600000-08:00')");
}
示例6: ReadAsync_WithAbsoluteUri_Generic
public async Task ReadAsync_WithAbsoluteUri_Generic()
{
var hijack = new TestHttpHandler();
hijack.SetResponseContent("[{\"col1\":\"Hey\"}]");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
IMobileServiceTable<ToDo> table = service.GetTable<ToDo>();
await table.ReadAsync<ToDo>("http://www.test.com/about?$filter=a eq b&$orderby=c");
Assert.AreEqual("TT,LH", hijack.Request.Headers.GetValues("X-ZUMO-FEATURES").First());
Assert.AreEqual("http://www.test.com/about?$filter=a eq b&$orderby=c", hijack.Request.RequestUri.ToString());
}
示例7: DateOffsetUri
public async Task DateOffsetUri()
{
TestHttpHandler hijack = new TestHttpHandler();
IMobileServiceClient client = new MobileServiceClient("http://www.test.com", null, hijack);
IMobileServiceTable<DateOffsetExample> table = client.GetTable<DateOffsetExample>();
hijack.Response = new HttpResponseMessage(HttpStatusCode.OK);
hijack.SetResponseContent("[]");
var date = DateTimeOffset.Parse("2009-11-21T06:22:59.8600000-08:00");
await table.Where(b => b.Date == date).ToEnumerableAsync();
Assert.EndsWith(hijack.Request.RequestUri.ToString(), "$filter=(DateOffsetExampleDate eq datetimeoffset'2009-11-21T06:22:59.8600000-08:00')");
}
示例8: LookupAsyncGeneric
public async Task LookupAsyncGeneric()
{
TestHttpHandler hijack = new TestHttpHandler();
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
IMobileServiceTable<StringType> table = service.GetTable<StringType>();
hijack.SetResponseContent("{\"id\":12,\"String\":\"Hello\"}");
StringType expected = await table.LookupAsync(12);
Assert.Contains(hijack.Request.RequestUri.ToString(), "12");
Assert.AreEqual(12, expected.Id);
Assert.AreEqual("Hello", expected.String);
}
示例9: ReadAsyncWithStringIdTypeAndNullIdResponseContent
public async Task ReadAsyncWithStringIdTypeAndNullIdResponseContent()
{
TestHttpHandler hijack = new TestHttpHandler();
hijack.SetResponseContent("[{\"id\":null,\"String\":\"Hey\"}]");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
IMobileServiceTable<StringIdType> table = service.GetTable<StringIdType>();
IEnumerable<StringIdType> results = await table.ReadAsync();
StringIdType[] items = results.ToArray();
Assert.AreEqual(1, items.Count());
Assert.AreEqual(null, items[0].Id);
Assert.AreEqual("Hey", items[0].String);
}
示例10: PushAsync_FeatureHeaderPresent
public async Task PushAsync_FeatureHeaderPresent()
{
var hijack = new TestHttpHandler();
hijack.AddResponseContent("{\"id\":\"abc\",\"String\":\"Hey\"}");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
var store = new MobileServiceLocalStoreMock();
await service.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
IMobileServiceSyncTable table = service.GetSyncTable("someTable");
JObject item1 = new JObject() { { "id", "abc" } };
await table.InsertAsync(item1);
await service.SyncContext.PushAsync();
Assert.AreEqual(hijack.Requests[0].Headers.GetValues("X-ZUMO-FEATURES").First(), "TU,OL");
}
示例11: LookupAsyncGenericWithUserParameters
public async Task LookupAsyncGenericWithUserParameters()
{
var userDefinedParameters = new Dictionary<string, string>() { { "state", "CA" } };
TestHttpHandler hijack = new TestHttpHandler();
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
IMobileServiceTable<StringType> table = service.GetTable<StringType>();
hijack.SetResponseContent("{\"id\":12,\"String\":\"Hello\"}");
StringType expected = await table.LookupAsync(12, userDefinedParameters);
Assert.Contains(hijack.Request.RequestUri.ToString(), "12");
Assert.Contains(hijack.Request.RequestUri.Query, "state=CA");
Assert.AreEqual(12, expected.Id);
Assert.AreEqual("Hello", expected.String);
}
示例12: ReadAsyncGeneric
public async Task ReadAsyncGeneric()
{
TestHttpHandler hijack = new TestHttpHandler();
hijack.SetResponseContent("[{\"id\":12,\"String\":\"Hey\"}]");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
IMobileServiceTable<StringType> table = service.GetTable<StringType>();
IEnumerable<StringType> results = await table.ReadAsync();
StringType[] people = results.Cast<StringType>().ToArray();
Assert.Contains(hijack.Request.RequestUri.ToString(), "StringType");
Assert.AreEqual(1, people.Count());
Assert.AreEqual(12, people[0].Id);
Assert.AreEqual("Hey", people[0].String);
}
示例13: ReadAsync_ModifiesStringId_IfItContainsIsoDateValue
[AsyncTestMethod] // this is the default buggy behavior that we've already shipped
public async Task ReadAsync_ModifiesStringId_IfItContainsIsoDateValue()
{
var hijack = new TestHttpHandler();
hijack.SetResponseContent(@"[{
""id"": ""2014-01-29T23:01:33.444Z"",
""__createdAt"": ""2014-01-29T23:01:33.444Z""
}]");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
IMobileServiceTable<ToDoWithSystemPropertiesType> table = service.GetTable<ToDoWithSystemPropertiesType>();
IEnumerable<ToDoWithSystemPropertiesType> results = await table.ReadAsync();
ToDoWithSystemPropertiesType item = results.First();
Assert.AreEqual(item.Id, "01/29/2014 23:01:33");
Assert.AreEqual(item.CreatedAt, DateTime.Parse("2014-01-29T23:01:33.444Z"));
}
示例14: ReadAsync
public async Task ReadAsync()
{
TestHttpHandler hijack = new TestHttpHandler();
hijack.SetResponseContent("{\"Count\":1, People: [{\"Id\":\"12\", \"String\":\"Hey\"}] }");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
IMobileServiceTable table = service.GetTable("tests");
JToken people = await table.ReadAsync("$filter=id eq 12");
Assert.Contains(hijack.Request.RequestUri.ToString(), "tests");
Assert.Contains(hijack.Request.RequestUri.ToString(), "$filter=id eq 12");
Assert.AreEqual(1, (int)people["Count"]);
Assert.AreEqual(12, (int)people["People"][0]["Id"]);
Assert.AreEqual("Hey", (string)people["People"][0]["String"]);
}
示例15: ReadAsync_DoesNotModifyStringId_IfItContainsIsoDateValueAndSerializerIsConfiguredToNotParseDates
[AsyncTestMethod] // user has to set the serializer setting to round trip dates in string fields correctly
public async Task ReadAsync_DoesNotModifyStringId_IfItContainsIsoDateValueAndSerializerIsConfiguredToNotParseDates()
{
var hijack = new TestHttpHandler();
hijack.SetResponseContent(@"[{
""id"": ""2014-01-29T23:01:33.444Z"",
""__createdAt"": ""2014-01-29T23:01:33.444Z""
}]");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
service.SerializerSettings.DateParseHandling = DateParseHandling.None;
IMobileServiceTable<ToDoWithSystemPropertiesType> table = service.GetTable<ToDoWithSystemPropertiesType>();
IEnumerable<ToDoWithSystemPropertiesType> results = await table.ReadAsync();
ToDoWithSystemPropertiesType item = results.First();
Assert.AreEqual(item.Id, "2014-01-29T23:01:33.444Z");
Assert.AreEqual(item.CreatedAt, DateTime.Parse("2014-01-29T23:01:33.444Z"));
}