本文整理汇总了C#中Microsoft.WindowsAzure.MobileServices.Test.TestHttpHandler.SetResponseContent方法的典型用法代码示例。如果您正苦于以下问题:C# TestHttpHandler.SetResponseContent方法的具体用法?C# TestHttpHandler.SetResponseContent怎么用?C# TestHttpHandler.SetResponseContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.MobileServices.Test.TestHttpHandler
的用法示例。
在下文中一共展示了TestHttpHandler.SetResponseContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}
示例2: 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);
}
}
示例3: DateUri
public async Task DateUri()
{
TestHttpHandler hijack = new TestHttpHandler();
IMobileServiceClient client = new MobileServiceClient("http://www.test.com", null, hijack);
IMobileServiceTable<DateExample> table = client.GetTable<DateExample>();
hijack.Response = new HttpResponseMessage(HttpStatusCode.OK);
hijack.SetResponseContent("[]");
// Verify a full UTC date
DateTime date = new DateTime(2009, 11, 21, 14, 22, 59, 860, DateTimeKind.Utc);
await table.Where(b => b.Date == date).ToEnumerableAsync();
Assert.EndsWith(hijack.Request.RequestUri.ToString(), "$filter=(DateExampleDate eq datetime'2009-11-21T14:22:59.860Z')");
// Local date is converted to UTC
hijack.Response = new HttpResponseMessage(HttpStatusCode.OK);
hijack.SetResponseContent("[]");
date = new DateTime(2009, 11, 21, 14, 22, 59, 860, DateTimeKind.Local);
await table.Where(b => b.Date == date).ToEnumerableAsync();
Assert.EndsWith(hijack.Request.RequestUri.ToString(), "Z')");
}
示例4: 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')");
}
示例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 = 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')");
}
示例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: 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);
}
示例8: 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);
}
示例9: 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"));
}
示例10: 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"]);
}
示例11: 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);
}
示例12: 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"));
}
示例13: SingleHttpHandlerConstructor
public async Task SingleHttpHandlerConstructor()
{
TestHttpHandler hijack = new TestHttpHandler();
IMobileServiceClient service =
new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, handlers: hijack);
MobileAppUriValidator mobileAppUriValidator = new MobileAppUriValidator(service);
// Ensure properties are copied over
Assert.AreEqual(MobileAppUriValidator.DummyMobileApp, service.MobileAppUri.ToString());
// Set the handler to return an empty array
hijack.SetResponseContent("[]");
JToken response = await service.GetTable("foo").ReadAsync("bar");
// Verify the handler was in the loop
Assert.StartsWith(hijack.Request.RequestUri.ToString(), mobileAppUriValidator.TableBaseUri);
}
示例14: ReadAsyncWithUserParameters
public async Task ReadAsyncWithUserParameters()
{
TestHttpHandler hijack = new TestHttpHandler();
hijack.SetResponseContent("{\"Count\":1, People: [{\"Id\":\"12\", \"String\":\"Hey\"}] }");
IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
var userDefinedParameters = new Dictionary<string, string>() { { "tags", "#pizza #beer" } };
IMobileServiceTable table = service.GetTable("tests");
JToken people = await table.ReadAsync("$filter=id eq 12", userDefinedParameters);
Assert.Contains(hijack.Request.RequestUri.ToString(), "tests");
Assert.Contains(hijack.Request.RequestUri.AbsoluteUri, "tags=%23pizza%20%23beer");
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: SingleHttpHandlerConstructor
public async Task SingleHttpHandlerConstructor()
{
string appUrl = "http://www.test.com/";
string appKey = "secret...";
TestHttpHandler hijack = new TestHttpHandler();
IMobileServiceClient service =
new MobileServiceClient(new Uri(appUrl), appKey, hijack);
// Ensure properties are copied over
Assert.AreEqual(appUrl, service.ApplicationUri.ToString());
Assert.AreEqual(appKey, service.ApplicationKey);
// Set the handler to return an empty array
hijack.SetResponseContent("[]");
JToken response = await service.GetTable("foo").ReadAsync("bar");
// Verify the handler was in the loop
Assert.StartsWith(hijack.Request.RequestUri.ToString(), appUrl);
}