Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Initial dotnet 9 version and AOT #306

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore SharpCaster.sln
- name: tag
Expand Down
6 changes: 6 additions & 0 deletions SharpCaster.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharpcaster", "Sharpcaster\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharpcaster.Test", "Sharpcaster.Test\Sharpcaster.Test.csproj", "{C8C0A3A8-C6AC-4E1B-8D3B-E6764C45C35B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sharpcaster.Test.Aot", "Sharpcaster.Test.Aot\Sharpcaster.Test.Aot.csproj", "{AA4C0985-3C97-496E-AF38-ADD0DC285A4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{C8C0A3A8-C6AC-4E1B-8D3B-E6764C45C35B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8C0A3A8-C6AC-4E1B-8D3B-E6764C45C35B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8C0A3A8-C6AC-4E1B-8D3B-E6764C45C35B}.Release|Any CPU.Build.0 = Release|Any CPU
{AA4C0985-3C97-496E-AF38-ADD0DC285A4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA4C0985-3C97-496E-AF38-ADD0DC285A4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA4C0985-3C97-496E-AF38-ADD0DC285A4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA4C0985-3C97-496E-AF38-ADD0DC285A4C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
40 changes: 40 additions & 0 deletions Sharpcaster.Test.Aot/JsonTesting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Sharpcaster.Extensions;
using Sharpcaster.Interfaces;
using Sharpcaster.Messages.Connection;
using Sharpcaster.Messages.Heartbeat;
using System.Text.Json;

namespace Sharpcaster.Test.Aot
{
[TestClass]
public sealed class JsonTesting
{
[TestMethod]
public void TestConnectMessageSerialization()
{
IMessage connectMessage = new ConnectMessage();
var requestId = ((IMessageWithId)connectMessage).RequestId;

var output = JsonSerializer.Serialize(connectMessage, SharpcasteSerializationContext.Default.ConnectMessage);
Assert.AreEqual("{\"requestId\":" + requestId + ",\"type\":\"CONNECT\"}", output);
}

[TestMethod]
public void TestPingMessageSerialization()
{
IMessage pingMessage = new PingMessage();

var output = JsonSerializer.Serialize(pingMessage, SharpcasteSerializationContext.Default.PingMessage);
Assert.AreEqual("{\"type\":\"PING\"}", output);
}

[TestMethod]
public void TestPingMessageDeserialization()
{
const string input = "{\"type\":\"PING\"}";
var message = JsonSerializer.Deserialize(input, SharpcasteSerializationContext.Default.PingMessage);

Assert.AreEqual("PING", message?.Type);
}
}
}
1 change: 1 addition & 0 deletions Sharpcaster.Test.Aot/MSTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
40 changes: 40 additions & 0 deletions Sharpcaster.Test.Aot/Sharpcaster.Test.Aot.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="MSTest.Sdk/3.6.1">

<PropertyGroup>
<TargetFramework>net9.0-windows</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<publishAoT>true</publishAoT>
<!--
Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
-->
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Sharpcaster\Sharpcaster.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.CodeCoverage.MSBuild" Version="17.13.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Testing.Extensions.CodeCoverage" Version="17.13.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Testing.Extensions.TrxReport" Version="1.5.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Testing.Platform.MSBuild" Version="1.5.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="MSTest.TestFramework" Version="3.7.0" />
</ItemGroup>

</Project>
34 changes: 10 additions & 24 deletions Sharpcaster.Test/ChromecastApplicationTester.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Sharpcaster.Models;
using Sharpcaster.Test.customChannel;
using Sharpcaster.Test.customMessage;
using Sharpcaster.Test.helper;
using System.Text.Json;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -18,7 +20,7 @@ public ChromecastApplicationTester(ITestOutputHelper outputHelper, ChromecastDev
}

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
[MemberData(nameof(ChromecastReceiversFilter.GetChromecastUltra), MemberType = typeof(ChromecastReceiversFilter))]
public async Task ConnectToChromecastAndLaunchApplication(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
Expand All @@ -31,7 +33,7 @@ public async Task ConnectToChromecastAndLaunchApplication(ChromecastReceiver rec
}

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
[MemberData(nameof(ChromecastReceiversFilter.GetChromecastUltra), MemberType = typeof(ChromecastReceiversFilter))]
public async Task ConnectToChromecastAndLaunchApplicationTwice(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
Expand All @@ -47,26 +49,8 @@ public async Task ConnectToChromecastAndLaunchApplicationTwice(ChromecastReceive
Assert.Equal(firstLaunchTransportId, status.Application.TransportId);
}

[Theory(Skip = "This does not pass any more. Now my JBL reacts as the other device - not changing the Transport ID !?")]
[MemberData(nameof(ChromecastReceiversFilter.GetJblSpeaker), MemberType = typeof(ChromecastReceiversFilter))]
public async Task ConnectToChromecastAndLaunchApplicationTwiceWithoutJoining1(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
var client = await TestHelper.CreateAndConnectClient(output, receiver);
var status = await client.LaunchApplicationAsync("B3419EF5");

var firstLaunchTransportId = status.Application.TransportId;
await client.DisconnectAsync();

_ = await client.ConnectChromecast(receiver);
status = await client.LaunchApplicationAsync("B3419EF5", false);

// My JBL Device (almost every time - but not always ) makes a new ID here!!!! (The other device - ChromecastAudio DOES NOT!?)
Assert.NotEqual(firstLaunchTransportId, status.Application.TransportId);
}

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetDefaultDevice), MemberType = typeof(ChromecastReceiversFilter))]
[MemberData(nameof(ChromecastReceiversFilter.GetAny), MemberType = typeof(ChromecastReceiversFilter))]
public async Task ConnectToChromecastAndLaunchApplicationTwiceWithoutJoining2(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
Expand All @@ -84,7 +68,7 @@ public async Task ConnectToChromecastAndLaunchApplicationTwiceWithoutJoining2(Ch
}

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
[MemberData(nameof(ChromecastReceiversFilter.GetChromecastUltra), MemberType = typeof(ChromecastReceiversFilter))]
public async Task ConnectToChromecastAndLaunchApplicationAThenLaunchApplicationB(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
Expand All @@ -101,7 +85,7 @@ public async Task ConnectToChromecastAndLaunchApplicationAThenLaunchApplicationB
}

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
[MemberData(nameof(ChromecastReceiversFilter.GetAny), MemberType = typeof(ChromecastReceiversFilter))]
public async Task ConnectToChromecastAndLaunchApplicationOnceAndJoinIt(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
Expand Down Expand Up @@ -129,7 +113,9 @@ public async Task ConnectToChromecastAndLaunchWebPage(ChromecastReceiver receive
SessionId = client.GetChromecastStatus().Application.SessionId
};

await client.SendAsync(null, "urn:x-cast:com.boombatower.chromecast-dashboard", req, client.GetChromecastStatus().Application.SessionId);
var requestPayload = JsonSerializer.Serialize(req, WebMessageSerializationContext.Default.WebMessage);

await client.SendAsync(null, "urn:x-cast:com.boombatower.chromecast-dashboard", requestPayload, client.GetChromecastStatus().Application.SessionId);
await Task.Delay(5000);
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sharpcaster.Test/ChromecastConnectionTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using Xunit.Abstractions;
using Sharpcaster.Test.helper;
using Sharpcaster.Models.Media;
using System;
using System.Linq;
using System.Collections.Generic;

namespace Sharpcaster.Test
{
Expand All @@ -22,7 +22,7 @@ public ChromecastConnectionTester(ITestOutputHelper outputHelper, ChromecastDevi
}

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
[MemberData(nameof(ChromecastReceiversFilter.GetAny), MemberType = typeof(ChromecastReceiversFilter))]
public async Task SearchChromecastsAndConnectToIt(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
Expand Down Expand Up @@ -76,7 +76,7 @@ public async Task TestingHeartBeat(ChromecastReceiver receiver)
int commandsToRun = 10;

//We are setting up an event to listen to status change. Because we don't know when the video has started to play
client.MediaChannel.StatusChanged += (object sender, EventArgs e) =>
client.MediaChannel.StatusChanged += (object sender, MediaStatus e) =>
{
_autoResetEvent.Set();
};
Expand Down
25 changes: 25 additions & 0 deletions Sharpcaster.Test/JsonTester.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.VisualBasic;
using Sharpcaster.Extensions;
using Sharpcaster.Interfaces;
using Sharpcaster.Messages.Connection;
using System.Text.Json;
using Xunit;

namespace Sharpcaster.Test
{
[Collection("SingleCollection")]
public class JsonTester
{
[Fact]
public void TestConnectMessage()
{
IMessage connectMessage = new ConnectMessage();
var requestId = (connectMessage as IMessageWithId).RequestId;

var output = JsonSerializer.Serialize(connectMessage, SharpcasteSerializationContext.Default.ConnectMessage);
Assert.Equal("{\"requestId\":" + requestId + ",\"type\":\"CONNECT\"}", output);
}


}
}
4 changes: 2 additions & 2 deletions Sharpcaster.Test/LoggingTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public void TestLogging()
List<string> logLines = [];
_ = TestHelper.GetClientWithTestOutput(output, assertableLog: logLines);

Assert.Equal("[addUserResponse,getInfoResponse,LAUNCH_ERROR,RECEIVER_STATUS,QUEUE_CHANGE,QUEUE_ITEM_IDS,QUEUE_ITEMS,DEVICE_UPDATED,MULTIZONE_STATUS,ERROR,INVALID_REQUEST,LOAD_CANCELLED,LOAD_FAILED,MEDIA_STATUS,PING,CLOSE]", logLines[0]);
Assert.Equal("MessageTypes: [addUserResponse,getInfoResponse,LAUNCH_ERROR,RECEIVER_STATUS,QUEUE_CHANGE,QUEUE_ITEM_IDS,QUEUE_ITEMS,DEVICE_UPDATED,MULTIZONE_STATUS,ERROR,INVALID_REQUEST,LOAD_CANCELLED,LOAD_FAILED,MEDIA_STATUS,PING,CLOSE,LAUNCH_STATUS]", logLines[0]);
}

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
[MemberData(nameof(ChromecastReceiversFilter.GetAny), MemberType = typeof(ChromecastReceiversFilter))]
public async Task TestPlayMediaWorksWithoutLogging(ChromecastReceiver receiver)
{
ChromecastClient client = new();
Expand Down
Loading
Loading