public async Task Wikipedia() { // arrange IClient client = this.ConstructClient("https://en.wikipedia.org/"); // act WikipediaMetadata response = await client .GetAsync("w/api.php") .WithArguments(new { action = "query", meta = "siteinfo", siprop = "general", format = "json" }) .As <WikipediaMetadata>(); this.AssertResponse(response, "First request"); }
/// <summary>Performs assertions on the specified Wikimedia metadata.</summary> /// <param name="response">The metadata to assert.</param> /// <param name="expected">The expected metadata.</param> /// <param name="prefix">The property name prefix to use within assertion exceptions.</param> private void AssertResponse(WikipediaMetadata response, WikipediaMetadata.WikipediaGeneral expected, string prefix) { // assert Assert.IsNotNull(response, prefix + " metadata is null"); Assert.IsNotNull(response.Query, prefix + " metadata.Query is null."); Assert.IsNotNull(response.Query.General, prefix + " metadata.Query.General is null."); response.Query.General .AssertValue(p => p.ArticlePath, expected.ArticlePath) .AssertValue(p => p.Base, expected.Base) .AssertValue(p => p.Language, expected.Language) .AssertValue(p => p.MainPage, expected.MainPage) .AssertValue(p => p.MaxUploadSize, expected.MaxUploadSize) .AssertValue(p => p.ScriptPath, expected.ScriptPath) .AssertValue(p => p.Server, expected.Server) .AssertValue(p => p.SiteName, expected.SiteName) .AssertValue(p => p.Time.Date, expected.Time.Date) .AssertValue(p => p.VariantArticlePath, expected.VariantArticlePath) .AssertValue(p => p.WikiID, expected.WikiID); }
/// <summary>Performs assertions on the specified Wikimedia metadata.</summary> /// <param name="response">The metadata to assert.</param> /// <param name="prefix">The property name prefix to use within assertion exceptions.</param> protected void AssertResponse(WikipediaMetadata response, string prefix) { // assert Assert.IsNotNull(response, prefix + " metadata is null"); Assert.IsNotNull(response.Query, prefix + " metadata.Query is null."); Assert.IsNotNull(response.Query.General, prefix + " metadata.Query.General is null."); response.Query.General .AssertValue(p => p.ArticlePath, "/wiki/$1") .AssertValue(p => p.Base, "https://en.wikipedia.org/wiki/Main_Page") .AssertValue(p => p.Language, "en") .AssertValue(p => p.MainPage, "Main Page") .AssertValue(p => p.MaxUploadSize, 4294967296) .AssertValue(p => p.ScriptPath, "/w") .AssertValue(p => p.Server, "//en.wikipedia.org") .AssertValue(p => p.SiteName, "Wikipedia") .AssertValue(p => p.Time.Date, DateTime.UtcNow.Date) .AssertValue(p => p.VariantArticlePath, false) .AssertValue(p => p.WikiID, "enwiki"); }