Skip to content

Commit

Permalink
upgrade to .net 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
w8tcha committed Dec 26, 2023
1 parent 50152c0 commit 504cb51
Show file tree
Hide file tree
Showing 45 changed files with 152 additions and 174 deletions.
3 changes: 2 additions & 1 deletion OEmbed.Core.Tests/GlobalUsings.cs
@@ -1,5 +1,6 @@
// Global using directives

#if NET7_0_OR_GREATER
global using System.Threading.Tasks;

#endif
global using Xunit;
8 changes: 4 additions & 4 deletions OEmbed.Core.Tests/OEmbed.Core.Tests.csproj
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProductVersion />
<TargetFrameworks>net481;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net481;net7.0;net8.0</TargetFrameworks>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<IsTestProject>true</IsTestProject>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
3 changes: 1 addition & 2 deletions OEmbed.Core.Tests/ProviderTests/CodePenTests.cs
Expand Up @@ -29,7 +29,7 @@ public void EmbedTest(string url)

#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://codepen.io/team/HMPD/pen/vjZwwr")]
[InlineData("https://codepen.io/meodai/pen/GRyjQoZ")]
Expand All @@ -42,5 +42,4 @@ public async Task EmbedAsyncTest(string url)
Assert.NotNull(actual);
}
#endif

}
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/DailyMotionTests.cs
Expand Up @@ -30,7 +30,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://www.dailymotion.com/video/x87cx3z")]
[InlineData("https://dai.ly/x87cx3z")]
Expand Down
4 changes: 2 additions & 2 deletions OEmbed.Core.Tests/ProviderTests/DeezerTests.cs
Expand Up @@ -2,7 +2,7 @@

public class DeezerTests : IProviderTests
{
[Theory]
[Theory]
[InlineData("https://www.deezer.com/us/album/217565572")]
[InlineData("https://www.deezer.com/us/track/1286394242")]
[InlineData("https://www.deezer.com/us/playlist/8664185942")]
Expand Down Expand Up @@ -30,7 +30,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://www.deezer.com/us/album/217565572")]
[InlineData("https://www.deezer.com/us/track/1286394242")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/DeviantArtTests.cs
Expand Up @@ -28,7 +28,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://www.deviantart.com/wlop/art/Sunshine2-905829772")]
[InlineData("https://www.deviantart.com/art/Sunshine2-905829772")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/FacebookTests.cs
Expand Up @@ -35,7 +35,7 @@ public void EmbedTest(string url)

#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[InlineData("https://www.facebook.com/iu.loen/posts/501755841318628")]
[InlineData("https://www.facebook.com/iu.loen/photos/281842976643250")]
[InlineData("https://www.facebook.com/photo.php?fbid=281842976643250&set=pb.100044526485652.-2207520000..&type=3")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/FlickrTests.cs
Expand Up @@ -27,7 +27,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://flickr.com/photos/josbuurmansphotography/50553575881")]
public async Task EmbedAsyncTest(string url)
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/GiphyTests.cs
Expand Up @@ -37,7 +37,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://giphy.com/gifs/confused-iu-looking-up-l2YWwjl8T5tdGiaf6")]
[InlineData("https://www.giphy.com/gifs/confused-iu-looking-up-l2YWwjl8T5tdGiaf6")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/GitHubGistTests.cs
Expand Up @@ -27,7 +27,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://gist.github.com/skabber/54099")]
public async Task EmbedAsyncTest(string url)
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/IProviderTests.cs
Expand Up @@ -11,7 +11,7 @@ public interface IProviderTests
void EmbedTest(string url);
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
Task EmbedAsyncTest(string url);
#endif
}
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/InstagramTests.cs
Expand Up @@ -41,7 +41,7 @@ public void EmbedTest(string url)

#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[InlineData("https://www.instagram.com/dlwlrma/")]
[InlineData("https://www.instagram.com/p/1XSKgBAGz-/")]
[InlineData("https://www.instagram.com/tv/CHLVnWVAF9I/")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/PinterestTests.cs
Expand Up @@ -27,7 +27,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://www.pinterest.com/pin/6896205669260457/")]
public async Task EmbedAsyncTest(string url)
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/RedditTests.cs
Expand Up @@ -27,7 +27,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://www.reddit.com/r/Showerthoughts/comments/2safxv/we_should_start_keeping_giraffes_a_secret_from/cno7zic")]
public async Task EmbedAsyncTest(string url)
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/SoundCloudTests.cs
Expand Up @@ -31,7 +31,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://soundcloud.com/blackpinkofficial")]
[InlineData("https://soundcloud.com/blackpinkofficial/whistle")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/SpotifyTests.cs
Expand Up @@ -39,7 +39,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://open.spotify.com/artist/3HqSLMAZ3g3d5poNaI7GOU")]
[InlineData("https://open.spotify.com/album/2xEH7SRzJq7LgA0fCtTlxH")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/TiktokTests.cs
Expand Up @@ -33,7 +33,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://m.tiktok.com/v/6934593663062265094.html")]
[InlineData("https://www.tiktok.com/@faaaariii_/video/6934593663062265094")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/TwitterTests.cs
Expand Up @@ -35,7 +35,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("http://twitter.com/panpianoatelier/status/1500450869590241286")]
[InlineData("http://www.twitter.com/panpianoatelier/status/1500450869590241286")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/VimeoTests.cs
Expand Up @@ -39,7 +39,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://vimeo.com/22439234")]
[InlineData("https://vimeo.com/22439234?embedded=true&source=video_title&owner=910279")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core.Tests/ProviderTests/YouTubeTests.cs
Expand Up @@ -54,7 +54,7 @@ public void EmbedTest(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
[Theory]
[InlineData("https://youtu.be/LKWFkELeYwc")]
[InlineData("http://youtu.be/LKWFkELeYwc")]
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core/Extensions/ServiceCollectionExtensions.cs
@@ -1,4 +1,4 @@
#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
namespace OEmbed.Core.Extensions;

using Microsoft.AspNetCore.Http;
Expand Down
4 changes: 3 additions & 1 deletion OEmbed.Core/GlobalUsings.cs
Expand Up @@ -3,4 +3,6 @@
global using System;
global using System.Collections.Generic;
global using System.Text.RegularExpressions;
global using System.Threading.Tasks;
#if NET7_0_OR_GREATER
global using System.Threading.Tasks;
#endif
2 changes: 1 addition & 1 deletion OEmbed.Core/Interfaces/IOEmbed.cs
Expand Up @@ -28,7 +28,7 @@ public interface IOEmbed
Response Embed(string url);
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
/// <summary>
/// Embeds the specified URL.
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions OEmbed.Core/OEmbed.Core.csproj
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net481;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net481;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Description>C# oEmbed consumer library for .NET Framwork 4.8.1 and .NET (Core) 6/7</Description>
<PackageTags>oembed;embed</PackageTags>
Expand All @@ -10,14 +10,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Runtime.Caching" Version="7.0.0" />
<PackageReference Include="System.Runtime.Caching" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

Expand Down
23 changes: 11 additions & 12 deletions OEmbed.Core/OEmbed.cs
Expand Up @@ -5,7 +5,7 @@
#endif
using System.Linq;
using System.Net;
#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
using System.Net.Http;
#endif
using System.Runtime.Caching;
Expand All @@ -14,39 +14,38 @@

using Newtonsoft.Json;


public class OEmbed : IOEmbed
{
public OEmbed()
{
this.Providers = new ProviderList().GetProviders();

this.options = new Options();
this._options = new Options();

var type = typeof(OEmbed);
var assemblyName = type.Assembly.GetName();

var agent = $"{type.Namespace}/{assemblyName!.Version!.Major}.{assemblyName!.Version!.Minor}";

#if NET481
this.userAgent = agent;
this._userAgent = agent;
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
this.httpClient = new HttpClient();
this.httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(agent);
#endif
}

#if NET481
private readonly string userAgent;
private readonly string _userAgent;
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
private readonly HttpClient httpClient;
#endif

private readonly Options options;
private readonly Options _options;

private static readonly MemoryCache Cache = MemoryCache.Default;

Expand Down Expand Up @@ -107,7 +106,7 @@ public Response Embed(string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
/// <summary>
/// Embeds the specified URL.
/// </summary>
Expand Down Expand Up @@ -168,7 +167,7 @@ private Response GetJson(Provider provider, string url)

var webRequest = (HttpWebRequest)WebRequest.Create(endpoint);

webRequest.UserAgent = this.userAgent;
webRequest.UserAgent = this._userAgent;

try
{
Expand All @@ -187,7 +186,7 @@ private Response GetJson(Provider provider, string url)

var response = JsonConvert.DeserializeObject<Response>(content);

if (this.options.EnableCache)
if (this._options.EnableCache)
{
Cache.Add(url, response, DateTimeOffset.Now.AddDays(1));
}
Expand All @@ -201,7 +200,7 @@ private Response GetJson(Provider provider, string url)
}
#endif

#if NET6_0_OR_GREATER
#if NET7_0_OR_GREATER
/// <summary>
/// Get the oEmbed JSON
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion OEmbed.Core/Provider.cs
Expand Up @@ -20,7 +20,7 @@ public abstract record Provider
/// Gets or sets the matches.
/// </summary>
/// <value>The matches.</value>
public List<Regex> Matches { get; set; } = new();
public List<Regex> Matches { get; set; } = [];

/// <summary>
/// Gets or sets the endpoint.
Expand Down
11 changes: 7 additions & 4 deletions OEmbed.Core/ProviderList.cs
Expand Up @@ -10,9 +10,12 @@ public class ProviderList
/// <returns>List&lt;Provider&gt;.</returns>
public List<Provider> GetProviders()
{
return new List<Provider>(typeof(Provider)
.Assembly.GetTypes()
.Where(t => t.IsSubclassOf(typeof(Provider)) && !t.IsAbstract)
.Select(t => (Provider)Activator.CreateInstance(t)));
return
[
..typeof(Provider)
.Assembly.GetTypes()
.Where(t => t.IsSubclassOf(typeof(Provider)) && !t.IsAbstract)
.Select(t => (Provider)Activator.CreateInstance(t))
];
}
}
4 changes: 2 additions & 2 deletions OEmbed.Core/Providers/CodePenProvider.cs
Expand Up @@ -8,10 +8,10 @@ public record CodePenProvider : Provider
public CodePenProvider()
{
this.Name = "CodePen";
this.Hosts = new List<string> { "codepen.io" };
this.Hosts = ["codepen.io"];

this.AddMatches(@"/(?:team/)?(?:[\w]+)/pen/([\w]+)/?");

this.Endpoint = "https://codepen.io/api/oembed";
}
}

0 comments on commit 504cb51

Please sign in to comment.