本文整理汇总了C#中Mock.FakeFetch方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.FakeFetch方法的具体用法?C# Mock.FakeFetch怎么用?C# Mock.FakeFetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.FakeFetch方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Users_get_associated_test
public void Users_get_associated_test()
{
var mock = new Mock<StacManClient>(FilterBehavior.Strict, null);
//http://api.stackexchange.com/2.0/users/1998/associated?pagesize=2
mock.FakeFetch(response: @"{""items"":[{""site_name"":""Stack Overflow"",""site_url"":""http://stackoverflow.com"",""user_id"":2749,""reputation"":4365,""account_id"":1998,""creation_date"":1219613204,""badge_counts"":{""gold"":1,""silver"":13,""bronze"":26},""last_access_date"":1334611626,""answer_count"":144,""question_count"":20},{""site_name"":""Server Fault"",""site_url"":""http://serverfault.com"",""user_id"":31532,""reputation"":101,""account_id"":1998,""creation_date"":1263334764,""badge_counts"":{""gold"":0,""silver"":0,""bronze"":3},""last_access_date"":1334610908,""answer_count"":0,""question_count"":0}],""quota_remaining"":-212787,""quota_max"":300,""has_more"":true}");
var client = mock.Object;
var result = client.Users.GetAssociated(new int[] { 1998 }, pagesize: 2).Result;
Assert.IsTrue(result.Success);
var networkUser = result.Data.Items.First();
Assert.AreEqual("Stack Overflow", networkUser.SiteName);
Assert.AreEqual("http://stackoverflow.com", networkUser.SiteUrl);
Assert.AreEqual(2749, networkUser.UserId);
Assert.AreEqual(4365, networkUser.Reputation);
Assert.AreEqual(1998, networkUser.AccountId);
Assert.AreEqual(1219613204L.ToDateTime(), networkUser.CreationDate);
Assert.AreEqual(1, networkUser.BadgeCounts.Gold);
Assert.AreEqual(13, networkUser.BadgeCounts.Silver);
Assert.AreEqual(26, networkUser.BadgeCounts.Bronze);
Assert.AreEqual(1334611626L.ToDateTime(), networkUser.LastAccessDate);
Assert.AreEqual(144, networkUser.AnswerCount);
Assert.AreEqual(20, networkUser.QuestionCount);
Assert2.Throws<Exceptions.FilterException>(() => { var t = networkUser.UserType; });
}
示例2: Backoff_test
public void Backoff_test()
{
var mockSlow = new Mock<StacManClient>(FilterBehavior.Strict, null);
var mockFast = new Mock<StacManClient>(FilterBehavior.Strict, null);
//http://api.stackexchange.com/2.0/users?pagesize=1&site=stackoverflow
mockSlow.FakeFetch(response: @"{""backoff"":1,""items"":[{""user_id"":22656,""user_type"":""registered"",""creation_date"":1222430705,""display_name"":""Jon Skeet"",""profile_image"":""http://www.gravatar.com/avatar/6d8ebb117e8d83d74ea95fbdd0f87e13?d=identicon&r=PG"",""reputation"":431980,""reputation_change_day"":365,""reputation_change_week"":2286,""reputation_change_month"":9666,""reputation_change_quarter"":9666,""reputation_change_year"":44922,""age"":35,""last_access_date"":1335550327,""last_modified_date"":1335533187,""is_employee"":false,""link"":""http://stackoverflow.com/users/22656/jon-skeet"",""website_url"":""http://csharpindepth.com"",""location"":""Reading, United Kingdom"",""account_id"":11683,""badge_counts"":{""gold"":124,""silver"":1896,""bronze"":3221},""accept_rate"":95}],""quota_remaining"":109,""quota_max"":300,""has_more"":true}");
mockFast.FakeFetch(response: @"{""items"":[{""user_id"":22656,""user_type"":""registered"",""creation_date"":1222430705,""display_name"":""Jon Skeet"",""profile_image"":""http://www.gravatar.com/avatar/6d8ebb117e8d83d74ea95fbdd0f87e13?d=identicon&r=PG"",""reputation"":431980,""reputation_change_day"":365,""reputation_change_week"":2286,""reputation_change_month"":9666,""reputation_change_quarter"":9666,""reputation_change_year"":44922,""age"":35,""last_access_date"":1335550327,""last_modified_date"":1335533187,""is_employee"":false,""link"":""http://stackoverflow.com/users/22656/jon-skeet"",""website_url"":""http://csharpindepth.com"",""location"":""Reading, United Kingdom"",""account_id"":11683,""badge_counts"":{""gold"":124,""silver"":1896,""bronze"":3221},""accept_rate"":95}],""quota_remaining"":109,""quota_max"":300,""has_more"":true}");
var clientSlow = mockSlow.Object;
var clientFast = mockFast.Object;
Action<StacManClient, Action<long>> measure = (client, verifyElapsedMs) =>
{
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
var result = client.Users.GetAll("stackoverflow", pagesize: 1).Result;
var result2 = client.Users.GetAll("stackoverflow", pagesize: 1).Result;
verifyElapsedMs(stopwatch.ElapsedMilliseconds);
};
measure(clientSlow, elapsedMs => Assert.IsTrue(elapsedMs >= 1000));
measure(clientFast, elapsedMs => Assert.IsTrue(elapsedMs < 1000));
clientSlow.RespectBackoffs = false;
measure(clientSlow, elapsedMs => Assert.IsTrue(elapsedMs < 1000));
}
示例3: Info_get_test
public void Info_get_test()
{
var mock = new Mock<StacManClient>(FilterBehavior.Strict, null);
//http://api.stackexchange.com/2.0/info?site=english
mock.FakeFetch(response: @"{""items"":[{""total_questions"":14647,""total_unanswered"":15,""total_accepted"":10674,""total_answers"":41975,""questions_per_minute"":0.01,""answers_per_minute"":0.02,""total_comments"":112674,""total_votes"":251459,""total_badges"":41800,""badges_per_minute"":0.02,""total_users"":17118,""new_active_users"":1,""api_revision"":""2012.4.12.2100""}],""quota_remaining"":291,""quota_max"":300,""has_more"":false}");
var client = mock.Object;
var result = client.Info.Get("english").Result;
Assert.IsTrue(result.Success);
var info = result.Data.Items.Single();
Assert.AreEqual(14647, info.TotalQuestions);
Assert.AreEqual(15, info.TotalUnanswered);
Assert.AreEqual(10674, info.TotalAccepted);
Assert.AreEqual(41975, info.TotalAnswers);
Assert.AreEqual(.01m, info.QuestionsPerMinute);
Assert.AreEqual(.02m, info.AnswersPerMinute);
Assert.AreEqual(112674, info.TotalComments);
Assert.AreEqual(251459, info.TotalVotes);
Assert.AreEqual(41800, info.TotalBadges);
Assert.AreEqual(.02m, info.BadgesPerMinute);
Assert.AreEqual(17118, info.TotalUsers);
Assert.AreEqual(1, info.NewActiveUsers);
Assert.AreEqual("2012.4.12.2100", info.ApiRevision);
Assert2.Throws<Exceptions.FilterException>(() => { var s = info.Site; });
}
示例4: Test_response_debugging_properties
public void Test_response_debugging_properties()
{
var mock = new Mock<StacManClient>(FilterBehavior.Strict, "myappkey");
//http://api.stackexchange.com/2.0/suggested-edits?pagesize=2&site=superuser
mock.FakeFetch(response: @"{""items"":[{""suggested_edit_id"":10345,""post_id"":410422,""post_type"":""question"",""comment"":""Removed unnecessary greetings"",""creation_date"":1333996736,""proposing_user"":{""user_id"":111438,""display_name"":""dnbrv"",""reputation"":348,""user_type"":""registered"",""profile_image"":""http://www.gravatar.com/avatar/0299470f4dcad8b4d79fd01c5dc7be4a?d=identicon&r=PG"",""link"":""http://superuser.com/users/111438/dnbrv""}},{""suggested_edit_id"":10344,""post_id"":410423,""post_type"":""question"",""comment"":""updated info"",""creation_date"":1333995585,""approval_date"":1333997046,""proposing_user"":{""user_id"":127397,""display_name"":""James Wilson"",""reputation"":3,""user_type"":""unregistered"",""profile_image"":""http://www.gravatar.com/avatar/ace280d5491b40c2645d856bf20337a3?d=identicon&r=PG"",""link"":""http://superuser.com/users/127397/james-wilson""}}],""quota_remaining"":262,""quota_max"":300,""has_more"":true}");
var client = mock.Object;
var response = client.SuggestedEdits.GetAll("superuser", pagesize: 2).Result;
Assert.IsTrue(response.ApiUrl.Contains("site=superuser"));
Assert.IsTrue(response.ApiUrl.Contains("pagesize=2"));
Assert.IsTrue(response.ApiUrl.Contains("key=myappkey"));
Assert.IsNotNull(response.RawData);
}
示例5: Api_web_exception_response
public void Api_web_exception_response()
{
var mock = new Mock<StacManClient>(FilterBehavior.Strict, null);
var client = mock.Object;
mock.FakeFetch(throws: new System.Net.WebException("timeout"));
var response = client.Users.GetAll("gaming.stackexchange.com").Result;
Assert.IsFalse(response.Success);
Assert.IsNull(response.Data);
Assert.IsInstanceOfType(response.Error, typeof(System.Net.WebException));
Assert.IsFalse(response.ReceivedApiResponse);
Assert.IsNotNull(response.ApiUrl);
Assert.IsNull(response.RawData);
}
示例6: Tags_get_all_test
public void Tags_get_all_test()
{
var mock = new Mock<StacManClient>(FilterBehavior.Strict, null);
//http://api.stackexchange.com/2.0/tags?page=3&pagesize=2&order=desc&sort=popular&site=gaming
mock.FakeFetch(response: @"{""items"":[{""name"":""league-of-legends"",""count"":768,""is_required"":false,""is_moderator_only"":false,""has_synonyms"":true},{""name"":""pc"",""count"":607,""is_required"":false,""is_moderator_only"":false,""has_synonyms"":false}],""quota_remaining"":-47478,""quota_max"":300,""has_more"":true}");
var client = mock.Object;
var result = client.Tags.GetAll("gaming", page: 3, pagesize: 2, order: Order.Desc, sort: Tags.Sort.Popular).Result;
Assert.IsTrue(result.Success);
var tag = result.Data.Items.Skip(1).First();
Assert.AreEqual("pc", tag.Name);
Assert.AreEqual(607, tag.Count);
Assert.IsFalse(tag.IsRequired);
Assert.IsFalse(tag.IsModeratorOnly);
Assert.IsFalse(tag.HasSynonyms);
Assert.IsNull(tag.UserId);
Assert2.Throws<Exceptions.FilterException>(() => { var d = tag.LastActivityDate; });
}
示例7: Stack_Exchange_API_Exception_response
public void Stack_Exchange_API_Exception_response()
{
var mock = new Mock<StacManClient>(FilterBehavior.Strict, null);
//http://api.stackexchange.com/2.0/inbox?access_token=foo
mock.FakeFetch(response: @"{""error_id"":405,""error_name"":""key_required"",""error_message"":""`key` is required when `access_token` is passed.""}");
var client = mock.Object;
var response = client.Inbox.Get("foo").Result;
Assert.IsFalse(response.Success);
Assert.IsTrue(response.ReceivedApiResponse);
Assert.IsNotNull(response.RawData);
Assert.IsInstanceOfType(response.Error, typeof(Exceptions.StackExchangeApiException));
Assert.AreEqual(405, ((Exceptions.StackExchangeApiException)response.Error).ErrorId);
Assert.AreEqual("key_required", ((Exceptions.StackExchangeApiException)response.Error).ErrorName);
Assert.AreEqual("`key` is required when `access_token` is passed.", ((Exceptions.StackExchangeApiException)response.Error).ErrorMessage);
Assert.IsNull(response.Data.Items);
Assert.AreEqual(405, response.Data.ErrorId);
Assert.AreEqual("key_required", response.Data.ErrorName);
Assert.AreEqual("`key` is required when `access_token` is passed.", response.Data.ErrorMessage);
}
示例8: Users_get_all_test
public void Users_get_all_test()
{
var mock = new Mock<StacManClient>(FilterBehavior.Strict, null);
//http://api.stackexchange.com/2.0/users?pagesize=1&order=desc&min=1&max=1000&sort=reputation&inname=doug&site=webapps
mock.FakeFetch(response: @"{""items"":[{""user_id"":183,""user_type"":""registered"",""creation_date"":1277932837,""display_name"":""Doug Harris"",""profile_image"":""http://www.gravatar.com/avatar/731e7de87c241fce562d03b23770b5cf?d=identicon&r=PG"",""reputation"":545,""reputation_change_day"":0,""reputation_change_week"":0,""reputation_change_month"":0,""reputation_change_quarter"":0,""reputation_change_year"":15,""age"":92,""last_access_date"":1332536617,""last_modified_date"":1332297406,""is_employee"":false,""link"":""http://webapps.stackexchange.com/users/183/doug-harris"",""website_url"":""http://delicious.com/dharris"",""location"":""Washington, DC"",""account_id"":46903,""badge_counts"":{""gold"":1,""silver"":4,""bronze"":8},""accept_rate"":25}],""quota_remaining"":-210785,""quota_max"":300,""has_more"":true}");
var client = mock.Object;
var result = client.Users.GetAll("webapps", pagesize: 1, order: Order.Desc, min: 1, max: 1000, sort: Users.Sort.Reputation, inname: "doug").Result;
Assert.IsTrue(result.Success);
var user = result.Data.Items.Single();
Assert.AreEqual(183, user.UserId);
Assert.AreEqual(Users.UserType.Registered, user.UserType);
Assert.AreEqual("Doug Harris", user.DisplayName);
Assert.AreEqual("http://www.gravatar.com/avatar/731e7de87c241fce562d03b23770b5cf?d=identicon&r=PG", user.ProfileImage);
Assert.AreEqual(545, user.Reputation);
Assert.AreEqual(0, user.ReputationChangeDay);
Assert.AreEqual(0, user.ReputationChangeWeek);
Assert.AreEqual(0, user.ReputationChangeMonth);
Assert.AreEqual(0, user.ReputationChangeQuarter);
Assert.AreEqual(15, user.ReputationChangeYear);
Assert.AreEqual(92, user.Age);
Assert.AreEqual(1332536617L.ToDateTime(), user.LastAccessDate);
Assert.AreEqual(1332297406L.ToDateTime(), user.LastModifiedDate);
Assert.IsFalse(user.IsEmployee);
Assert.AreEqual("http://webapps.stackexchange.com/users/183/doug-harris", user.Link);
Assert.AreEqual("http://delicious.com/dharris", user.WebsiteUrl);
Assert.AreEqual("Washington, DC", user.Location);
Assert.AreEqual(46903, user.AccountId);
Assert.AreEqual(1, user.BadgeCounts.Gold);
Assert.AreEqual(4, user.BadgeCounts.Silver);
Assert.AreEqual(8, user.BadgeCounts.Bronze);
Assert.AreEqual(25, user.AcceptRate);
Assert.IsNull(user.TimedPenaltyDate);
}