Skip to content

Commit

Permalink
Add some tests for TwitterExperimentalMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
supermomonga committed Jul 1, 2023
1 parent 10414c4 commit 75fd4fd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using MoEmbed.Providers;

using System;

using Xunit;

namespace MoEmbed.Models.Metadata
{
public class TwitterMetadataTest
{
[Theory]
[InlineData(
463440424141459456L,
"US Department of the Interior",
"Sunsets don't get much better than this one over @GrandTetonNPS. #nature #sunset pic.twitter.com/YuKy2rcjyU"
)]
public void FetchAsyncTest(long tweetId, string expectedDisplayName, string expectedDescription)
{
var uri = $"https://twitter.com/Interior/status/{tweetId}";
var target = new TwitterMetadataProvider().GetMetadata(
new ConsumerRequest(new Uri(uri)));

var data = target.FetchAsync(
new RequestContext(
new MetadataService(),
new ConsumerRequest(new Uri(uri))))
.GetAwaiter().GetResult();

Assert.Equal(expectedDisplayName, data.Title);
Assert.Equal(expectedDescription, data.Description);
}
}
}
33 changes: 29 additions & 4 deletions MoEmbed.Core.Tests/Models/Metadata/TwitterMetadataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

namespace MoEmbed.Models.Metadata
{
public class TwitterMetadataTest
public class TwitterExperimentalMetadataTest
{
[Theory]
[InlineData(
463440424141459456L,
"US Department of the Interior",
"Sunsets don't get much better than this one over @GrandTetonNPS. #nature #sunset pic.twitter.com/YuKy2rcjyU"
"https://pbs.twimg.com/profile_images/432081479/DOI_LOGO_normal.jpg",
"Sunsets don't get much better than this one over @GrandTetonNPS. #nature #sunset http://t.co/YuKy2rcjyU"
)]
public void FetchAsyncTest(long tweetId, string expectedDisplayName, string expectedDescription)
public void FetchAsyncTest(long tweetId, string expectedDisplayName, string expectedProfileImageUrl, string expectedDescription)
{
var uri = $"https://twitter.com/Interior/status/{tweetId}";
var target = new TwitterMetadataProvider().GetMetadata(
var target = new TwitterExperimentalMetadataProvider().GetMetadata(
new ConsumerRequest(new Uri(uri)));

var data = target.FetchAsync(
Expand All @@ -27,7 +28,31 @@ public void FetchAsyncTest(long tweetId, string expectedDisplayName, string expe
.GetAwaiter().GetResult();

Assert.Equal(expectedDisplayName, data.Title);
Assert.Equal(expectedProfileImageUrl, data.MetadataImage.Thumbnail.Url);
Assert.Equal(expectedDescription, data.Description);
}

[Theory]
[InlineData(
463440424141459456L,
"https://twitter.com/Interior/status/463440424141459456/photo/1",
"https://pbs.twimg.com/media/Bm54nBCCYAACwBi.jpg"
)]
public void SingleImageTest(long tweetId, string expectedLocation, string expectedRawUrl)
{
var uri = $"https://twitter.com/Interior/status/{tweetId}";
var target = new TwitterExperimentalMetadataProvider().GetMetadata(
new ConsumerRequest(new Uri(uri)));

var data = target.FetchAsync(
new RequestContext(
new MetadataService(),
new ConsumerRequest(new Uri(uri))))
.GetAwaiter().GetResult();

Assert.Equal(1, data.Medias.Count);
Assert.Equal(expectedLocation, data.Medias[0].Location);
Assert.Equal(expectedRawUrl, data.Medias[0].RawUrl);
}
}
}

0 comments on commit 75fd4fd

Please sign in to comment.