Skip to content

Commit ba15862

Browse files
xiaojingheshahabhijeet
authored andcommitted
Add BingNewsSearch SDK (#3938)
1 parent c64893c commit ba15862

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5740
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetPathOfFileAbove('AzSdk.test.reference.props'))" />
3+
<PropertyGroup>
4+
<Description>Microsoft.Azure.CognitiveServices.Search.NewsSearch.Tests Class Library</Description>
5+
<AssemblyName>Microsoft.Azure.CognitiveServices.Search.NewsSearch.Tests</AssemblyName>
6+
<VersionPrefix>1.1.0-preview</VersionPrefix>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<TargetFramework>netcoreapp1.1</TargetFramework>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
15+
<ProjectReference Include="..\BingNewsSearch\Microsoft.Azure.CognitiveServices.Search.NewsSearch.csproj" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<None Update="SessionRecords\**\*.json">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
26+
</ItemGroup>
27+
28+
</Project>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using Microsoft.Azure.Test.HttpRecorder;
2+
using Microsoft.Azure.CognitiveServices.Search.NewsSearch;
3+
using Microsoft.Azure.CognitiveServices.Search.NewsSearch.Models;
4+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
5+
using System.Linq;
6+
using Xunit;
7+
8+
namespace SearchSDK.Tests
9+
{
10+
public class NewsSearchTests
11+
{
12+
private static string SubscriptionKey = "fake";
13+
14+
[Fact]
15+
public void NewsSearch()
16+
{
17+
using (MockContext context = MockContext.Start(this.GetType().FullName))
18+
{
19+
HttpMockServer.Initialize(this.GetType().FullName, "NewsSearch");
20+
21+
INewsSearchAPI client = new NewsSearchAPI(new ApiKeyServiceClientCredentials(SubscriptionKey), HttpMockServer.CreateInstance());
22+
23+
var resp = client.News.SearchAsync(query: "tom cruise").Result;
24+
25+
Assert.NotNull(resp);
26+
Assert.NotNull(resp.Value);
27+
Assert.True(resp.Value.Count > 0);
28+
29+
var news = resp.Value[0];
30+
Assert.NotNull(news.Name);
31+
Assert.NotNull(news.Url);
32+
Assert.NotNull(news.Description);
33+
Assert.NotNull(news.DatePublished);
34+
Assert.NotNull(news.Provider);
35+
Assert.NotNull(news.Provider[0].Name);
36+
}
37+
}
38+
39+
[Fact]
40+
public void NewsCategory()
41+
{
42+
using (MockContext context = MockContext.Start(this.GetType().FullName))
43+
{
44+
HttpMockServer.Initialize(this.GetType().FullName, "NewsCategory");
45+
46+
INewsSearchAPI client = new NewsSearchAPI(new ApiKeyServiceClientCredentials(SubscriptionKey), HttpMockServer.CreateInstance());
47+
48+
var resp = client.News.CategoryAsync(category: "sports").Result;
49+
50+
Assert.NotNull(resp);
51+
Assert.NotNull(resp.Value);
52+
Assert.True(resp.Value.Count > 0);
53+
54+
var news = resp.Value[0];
55+
Assert.NotNull(news.Name);
56+
Assert.NotNull(news.Url);
57+
Assert.NotNull(news.Description);
58+
Assert.NotNull(news.DatePublished);
59+
Assert.NotNull(news.Provider);
60+
Assert.NotNull(news.Category);
61+
Assert.NotNull(news.Provider[0].Name);
62+
}
63+
}
64+
65+
[Fact]
66+
public void NewsTrending()
67+
{
68+
using (MockContext context = MockContext.Start(this.GetType().FullName))
69+
{
70+
HttpMockServer.Initialize(this.GetType().FullName, "NewsTrending");
71+
72+
INewsSearchAPI client = new NewsSearchAPI(new ApiKeyServiceClientCredentials(SubscriptionKey), HttpMockServer.CreateInstance());
73+
74+
var resp = client.News.TrendingAsync().Result;
75+
76+
Assert.NotNull(resp);
77+
Assert.NotNull(resp.Value);
78+
Assert.True(resp.Value.Count > 0);
79+
80+
var trendingTopic = resp.Value[0];
81+
Assert.NotNull(trendingTopic.Name);
82+
Assert.NotNull(trendingTopic.WebSearchUrl);
83+
Assert.NotNull(trendingTopic.NewsSearchUrl);
84+
Assert.NotNull(trendingTopic.Image);
85+
Assert.NotNull(trendingTopic.Image.Url);
86+
Assert.NotNull(trendingTopic.Query);
87+
Assert.NotNull(trendingTopic.Query.Text);
88+
}
89+
}
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/bing/v7.0/news?category=sports",
5+
"RequestMethod": "GET",
6+
"RequestHeaders": {
7+
"User-Agent": [
8+
"FxVersion/4.6.25211.01",
9+
"Microsoft.CognitiveServices.Vision.Face.FaceAPI/1.0.0"
10+
]
11+
},
12+
"ResponseBody": "{\r\n\"_type\": \"News\",\r\n\"totalEstimatedMatches\": 46,\r\n\"value\": [{\r\n \"_type\": \"NewsArticle\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"ZDNet\"\r\n }],\r\n \"datePublished\": \"2017-11-16T14:15:00Z\",\r\n \"category\": \"ScienceAndTechnology\",\r\n \"name\": \"Surface Book 2 (15-inch): <b>Microsoft</b> supersizes its most powerful portable PC\",\r\n \"url\": \"http://www.zdnet.com/product/microsoft-surface-book-2/\",\r\n \"description\": \"Don&#39;t call it Surface Pro 5. The latest iteration of the Surface Pro loses the model number, keeps the kickstand, and adds mostly subtle refinements. Read More For the past five days, I&#39;ve been using a Surface Book 2 in place of my everyday PC, a first ...\"\r\n},\r\n{\r\n \"_type\": \"NewsArticle\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"CNET\"\r\n }],\r\n \"datePublished\": \"2017-11-17T06:13:00Z\",\r\n \"video\": {\r\n \"_type\": \"VideoObject\",\r\n \"name\": \"Microsoft Surface Book 2 (15-inch)\",\r\n \"thumbnailUrl\": \"https://www.bing.com/th?id=ON.C362047C8A293C48E4DBF9FCF1C99DD2&pid=News\",\r\n \"allowHttpsEmbed\": true,\r\n \"thumbnail\": {\r\n \"_type\": \"ImageObject\",\r\n \"width\": 480,\r\n \"height\": 269\r\n }\r\n },\r\n \"category\": \"ScienceAndTechnology\",\r\n \"name\": \"<b>Microsoft</b> Surface Book 2 (15-inch) review:\",\r\n \"url\": \"https://www.cnet.com/products/microsoft-surface-book-2/review/\",\r\n \"description\": \"<b>Microsoft</b> Surface Book 2 - 15&quot; - Core i7 8650U - 16 GB RAM - 512 GB SSD - English - North America fux00001 $2,899.00 <b>Microsoft</b> Surface Book 2 - 15&quot; - Core i7 8650U - 16 GB RAM - 256 GB SSD - English - North America hnr00001 $2,499.00 <b>Microsoft</b> Surface Book ...\",\r\n \"image\": {\r\n \"_type\": \"ImageObject\",\r\n \"thumbnail\": {\r\n \"_type\": \"ImageObject\",\r\n \"contentUrl\": \"https://www.bing.com/th?id=ON.4A5C3F257DA120C0D7778A4A764A0292&pid=News\",\r\n \"width\": 700,\r\n \"height\": 393\r\n }\r\n }\r\n},\r\n{\r\n \"_type\": \"NewsArticle\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"PC Magazine\"\r\n }],\r\n \"datePublished\": \"2017-11-17T04:27:00Z\",\r\n \"category\": \"ScienceAndTechnology\",\r\n \"name\": \"12 Reasons <b>Microsoft</b>&#39;s Edge Browser Rocks (No, Really)\",\r\n \"url\": \"https://www.pcmag.com/feature/357262/12-reasons-microsoft-s-edge-browser-rocks-no-really\",\r\n \"description\": \"At just two years old, Edge is the new kid on the web browser block, but what it lacks in maturity, it makes up for in speed and convenience. Development has been swift. With each major Windows 10 release, Edge improves. Windows 10 Fall Creators Update ...\",\r\n \"image\": {\r\n \"_type\": \"ImageObject\",\r\n \"thumbnail\": {\r\n \"_type\": \"ImageObject\",\r\n \"contentUrl\": \"https://www.bing.com/th?id=ON.D6CC6169ECD49465AACCC1327B37283E&pid=News\",\r\n \"width\": 700,\r\n \"height\": 394\r\n }\r\n }\r\n},\r\n{\r\n \"_type\": \"NewsArticle\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"Business Insider\"\r\n }],\r\n \"datePublished\": \"2017-11-16T23:58:00Z\",\r\n \"clusteredArticles\": [{\r\n \"_type\": \"NewsArticle\",\r\n \"name\": \"REVIEW: <b>Microsoft</b>&#39;s newest laptop is my new favorite computer (MSFT)\",\r\n \"url\": \"https://www.msn.com/en-us/money/other/review-microsofts-newest-laptop-is-my-new-favorite-computer-msft/ar-BBF2svf\",\r\n \"description\": \"It may have been the company&#39;s first-ever laptop, but when I tested it last year a few months after it debuted, I immediately liked it better than any of Apple&#39;s MacBooks that I&#39;d ever used. I now have a new favorite computer, and it&#39;s the successor to my ...\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"Business Insider on MSN.com\"\r\n }],\r\n \"datePublished\": \"2017-11-17T01:59:00Z\",\r\n \"category\": \"ScienceAndTechnology\"\r\n }],\r\n \"category\": \"ScienceAndTechnology\",\r\n \"name\": \"REVIEW: <b>Microsoft</b>&#39;s newest laptop is a powerful alternative to any of Apple&#39;s MacBooks or iPads\",\r\n \"url\": \"http://www.businessinsider.com/microsoft-surface-book-2-review-2017-11\",\r\n \"description\": \"<b>Microsoft</b>&#39;s original Surface Book was my favorite computer. It may have been the company&#39;s first-ever laptop, but when I tested it last year a few months after it debuted, I immediately liked it better than any of Apple&#39;s MacBooks that I&#39;d ever used.\",\r\n \"image\": {\r\n \"_type\": \"ImageObject\",\r\n \"thumbnail\": {\r\n \"_type\": \"ImageObject\",\r\n \"contentUrl\": \"https://www.bing.com/th?id=ON.7CEEFC996C222EA79BC65ABFE9356D63&pid=News\",\r\n \"width\": 700,\r\n \"height\": 524\r\n }\r\n }\r\n}]}",
13+
"ResponseHeaders": {
14+
"Content-Type": [
15+
"application/json; charset=utf-8"
16+
],
17+
"Expires": [
18+
"-1"
19+
],
20+
"Cache-Control": [
21+
"no-cache"
22+
],
23+
"Date": [
24+
"Wed, 30 Aug 2017 02:34:12 GMT"
25+
],
26+
"Pragma": [
27+
"no-cache"
28+
],
29+
"X-AspNet-Version": [
30+
"4.0.30319"
31+
],
32+
"X-Powered-By": [
33+
"ASP.NET"
34+
],
35+
"apim-request-id": [
36+
"2c1699ea-16ef-4ab2-a3ba-05c35aa3c1a6"
37+
],
38+
"Strict-Transport-Security": [
39+
"max-age=31536000; includeSubDomains; preload"
40+
],
41+
"x-content-type-options": [
42+
"nosniff"
43+
]
44+
},
45+
"StatusCode": 200
46+
}
47+
],
48+
"Names": {},
49+
"Variables": {}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/bing/v7.0/news/search?q=tom%20cruise",
5+
"RequestMethod": "GET",
6+
"RequestHeaders": {
7+
"User-Agent": [
8+
"FxVersion/4.6.25211.01",
9+
"Microsoft.CognitiveServices.Vision.Face.FaceAPI/1.0.0"
10+
]
11+
},
12+
"ResponseBody": "{\r\n\"_type\": \"News\",\r\n\"totalEstimatedMatches\": 46,\r\n\"value\": [{\r\n \"_type\": \"NewsArticle\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"ZDNet\"\r\n }],\r\n \"datePublished\": \"2017-11-16T14:15:00Z\",\r\n \"category\": \"ScienceAndTechnology\",\r\n \"name\": \"Surface Book 2 (15-inch): <b>Microsoft</b> supersizes its most powerful portable PC\",\r\n \"url\": \"http://www.zdnet.com/product/microsoft-surface-book-2/\",\r\n \"description\": \"Don&#39;t call it Surface Pro 5. The latest iteration of the Surface Pro loses the model number, keeps the kickstand, and adds mostly subtle refinements. Read More For the past five days, I&#39;ve been using a Surface Book 2 in place of my everyday PC, a first ...\"\r\n},\r\n{\r\n \"_type\": \"NewsArticle\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"CNET\"\r\n }],\r\n \"datePublished\": \"2017-11-17T06:13:00Z\",\r\n \"video\": {\r\n \"_type\": \"VideoObject\",\r\n \"name\": \"Microsoft Surface Book 2 (15-inch)\",\r\n \"thumbnailUrl\": \"https://www.bing.com/th?id=ON.C362047C8A293C48E4DBF9FCF1C99DD2&pid=News\",\r\n \"allowHttpsEmbed\": true,\r\n \"thumbnail\": {\r\n \"_type\": \"ImageObject\",\r\n \"width\": 480,\r\n \"height\": 269\r\n }\r\n },\r\n \"category\": \"ScienceAndTechnology\",\r\n \"name\": \"<b>Microsoft</b> Surface Book 2 (15-inch) review:\",\r\n \"url\": \"https://www.cnet.com/products/microsoft-surface-book-2/review/\",\r\n \"description\": \"<b>Microsoft</b> Surface Book 2 - 15&quot; - Core i7 8650U - 16 GB RAM - 512 GB SSD - English - North America fux00001 $2,899.00 <b>Microsoft</b> Surface Book 2 - 15&quot; - Core i7 8650U - 16 GB RAM - 256 GB SSD - English - North America hnr00001 $2,499.00 <b>Microsoft</b> Surface Book ...\",\r\n \"image\": {\r\n \"_type\": \"ImageObject\",\r\n \"thumbnail\": {\r\n \"_type\": \"ImageObject\",\r\n \"contentUrl\": \"https://www.bing.com/th?id=ON.4A5C3F257DA120C0D7778A4A764A0292&pid=News\",\r\n \"width\": 700,\r\n \"height\": 393\r\n }\r\n }\r\n},\r\n{\r\n \"_type\": \"NewsArticle\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"PC Magazine\"\r\n }],\r\n \"datePublished\": \"2017-11-17T04:27:00Z\",\r\n \"category\": \"ScienceAndTechnology\",\r\n \"name\": \"12 Reasons <b>Microsoft</b>&#39;s Edge Browser Rocks (No, Really)\",\r\n \"url\": \"https://www.pcmag.com/feature/357262/12-reasons-microsoft-s-edge-browser-rocks-no-really\",\r\n \"description\": \"At just two years old, Edge is the new kid on the web browser block, but what it lacks in maturity, it makes up for in speed and convenience. Development has been swift. With each major Windows 10 release, Edge improves. Windows 10 Fall Creators Update ...\",\r\n \"image\": {\r\n \"_type\": \"ImageObject\",\r\n \"thumbnail\": {\r\n \"_type\": \"ImageObject\",\r\n \"contentUrl\": \"https://www.bing.com/th?id=ON.D6CC6169ECD49465AACCC1327B37283E&pid=News\",\r\n \"width\": 700,\r\n \"height\": 394\r\n }\r\n }\r\n},\r\n{\r\n \"_type\": \"NewsArticle\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"Business Insider\"\r\n }],\r\n \"datePublished\": \"2017-11-16T23:58:00Z\",\r\n \"clusteredArticles\": [{\r\n \"_type\": \"NewsArticle\",\r\n \"name\": \"REVIEW: <b>Microsoft</b>&#39;s newest laptop is my new favorite computer (MSFT)\",\r\n \"url\": \"https://www.msn.com/en-us/money/other/review-microsofts-newest-laptop-is-my-new-favorite-computer-msft/ar-BBF2svf\",\r\n \"description\": \"It may have been the company&#39;s first-ever laptop, but when I tested it last year a few months after it debuted, I immediately liked it better than any of Apple&#39;s MacBooks that I&#39;d ever used. I now have a new favorite computer, and it&#39;s the successor to my ...\",\r\n \"provider\": [{\r\n \"_type\": \"Organization\",\r\n \"name\": \"Business Insider on MSN.com\"\r\n }],\r\n \"datePublished\": \"2017-11-17T01:59:00Z\",\r\n \"category\": \"ScienceAndTechnology\"\r\n }],\r\n \"category\": \"ScienceAndTechnology\",\r\n \"name\": \"REVIEW: <b>Microsoft</b>&#39;s newest laptop is a powerful alternative to any of Apple&#39;s MacBooks or iPads\",\r\n \"url\": \"http://www.businessinsider.com/microsoft-surface-book-2-review-2017-11\",\r\n \"description\": \"<b>Microsoft</b>&#39;s original Surface Book was my favorite computer. It may have been the company&#39;s first-ever laptop, but when I tested it last year a few months after it debuted, I immediately liked it better than any of Apple&#39;s MacBooks that I&#39;d ever used.\",\r\n \"image\": {\r\n \"_type\": \"ImageObject\",\r\n \"thumbnail\": {\r\n \"_type\": \"ImageObject\",\r\n \"contentUrl\": \"https://www.bing.com/th?id=ON.7CEEFC996C222EA79BC65ABFE9356D63&pid=News\",\r\n \"width\": 700,\r\n \"height\": 524\r\n }\r\n }\r\n}]}",
13+
"ResponseHeaders": {
14+
"Content-Type": [
15+
"application/json; charset=utf-8"
16+
],
17+
"Expires": [
18+
"-1"
19+
],
20+
"Cache-Control": [
21+
"no-cache"
22+
],
23+
"Date": [
24+
"Wed, 30 Aug 2017 02:34:12 GMT"
25+
],
26+
"Pragma": [
27+
"no-cache"
28+
],
29+
"X-AspNet-Version": [
30+
"4.0.30319"
31+
],
32+
"X-Powered-By": [
33+
"ASP.NET"
34+
],
35+
"apim-request-id": [
36+
"2c1699ea-16ef-4ab2-a3ba-05c35aa3c1a6"
37+
],
38+
"Strict-Transport-Security": [
39+
"max-age=31536000; includeSubDomains; preload"
40+
],
41+
"x-content-type-options": [
42+
"nosniff"
43+
]
44+
},
45+
"StatusCode": 200
46+
}
47+
],
48+
"Names": {},
49+
"Variables": {}
50+
}

0 commit comments

Comments
 (0)