Skip to content

Commit

Permalink
"Queuecaster" feature enhancement (#294)
Browse files Browse the repository at this point in the history
* add consolewrapper interface
* make unit tests run (most of the time) with my JBL speaker device
* make unit tests run sequencally and with 'agrerssive' m ultithreading (The PlayandStop/PlayandPause do fail if not set!)
* removed duplicated mediastatus event.
* prepare tests to show Cast messages (ILogger) in testoutput and have possibility to test for log content
* QueueLoad works.
* QueueLoad, QueueNext, QueuePrev works.
* added queue query requests
* fix logging test
* move needed runsettings to vs Xunit.runner.json file
* all unit tests run allways ok now (Media Channel tests always make new session - never join existing!). Allow Sequence tests to have different slow play timings.
* allow ChromecastClient constructor to pass iLogger or ILoggerFactory if needed without need for own serviceCollection.
* fix the stop test only sending stop once!
* refactor unit tests - now aLL work always with both of my devices!
* test and fix for #226
* do not asume any Device Names in UnitTest
* Use only One Item Object and this is called QueueItem in the Cast Documentation.
  • Loading branch information
RobertK66 authored Jul 3, 2024
1 parent 0cf0484 commit 9ada45b
Show file tree
Hide file tree
Showing 29 changed files with 701 additions and 139 deletions.
4 changes: 2 additions & 2 deletions SharpCaster.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B2AED87-CDE7-4B71-A5B6-19512202FF60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B2AED87-CDE7-4B71-A5B6-19512202FF60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B2AED87-CDE7-4B71-A5B6-19512202FF60}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{7B2AED87-CDE7-4B71-A5B6-19512202FF60}.Debug|Any CPU.Build.0 = Release|Any CPU
{7B2AED87-CDE7-4B71-A5B6-19512202FF60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B2AED87-CDE7-4B71-A5B6-19512202FF60}.Release|Any CPU.Build.0 = Release|Any CPU
{C8C0A3A8-C6AC-4E1B-8D3B-E6764C45C35B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
65 changes: 49 additions & 16 deletions Sharpcaster.Test/ChromecastApplicationTester.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
using Xunit;
using Sharpcaster.Test.customChannel;
using System;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace Sharpcaster.Test
{
[Collection("SingleCollection")]
public class ChromecastApplicationTester
{
private ITestOutputHelper output;
public ChromecastApplicationTester(ITestOutputHelper outputHelper) {
output = outputHelper;
}

[Fact]
public async void ConnectToChromecastAndLaunchApplication()
public async Task ConnectToChromecastAndLaunchApplication()
{
var chromecast = await TestHelper.FindChromecast();
var client = new ChromecastClient();
Expand All @@ -17,7 +27,7 @@ public async void ConnectToChromecastAndLaunchApplication()
}

[Fact]
public async void ConnectToChromecastAndLaunchApplicationTwice()
public async Task ConnectToChromecastAndLaunchApplicationTwice()
{
var chromecast = await TestHelper.FindChromecast();
var client = new ChromecastClient();
Expand All @@ -35,24 +45,31 @@ public async void ConnectToChromecastAndLaunchApplicationTwice()


[Fact]
public async void ConnectToChromecastAndLaunchApplicationTwiceWithoutJoining()
public async Task ConnectToChromecastAndLaunchApplicationTwiceWithoutJoining()
{
var chromecast = await TestHelper.FindChromecast();
var client = new ChromecastClient();
var status = await client.ConnectChromecast(chromecast);
status = await client.LaunchApplicationAsync("B3419EF5");
var client = await TestHelper.CreateAndConnectClient(output);

var status = await client.LaunchApplicationAsync("B3419EF5");

var firstLaunchTransportId = status.Applications[0].TransportId;
await client.DisconnectAsync();

status = await client.ConnectChromecast(chromecast);
status = await client.ConnectChromecast(TestHelper.CurrentReceiver);
status = await client.LaunchApplicationAsync("B3419EF5", false);

Assert.Equal(firstLaunchTransportId, status.Applications[0].TransportId);
// ??????
// My JBL Device (almost every time - but not always ) makes a new ID here!!!! (The other device - ChromecastAudio DOES NOT!?)
if (TestHelper.CurrentReceiver.Model.Contains("JBL")) {
Assert.NotEqual(firstLaunchTransportId, status.Applications[0].TransportId);
} else {
Assert.Equal(firstLaunchTransportId, status.Applications[0].TransportId);
}


}

[Fact]
public async void ConnectToChromecastAndLaunchApplicationAThenLaunchApplicationB()
public async Task ConnectToChromecastAndLaunchApplicationAThenLaunchApplicationB()
{
var chromecast = await TestHelper.FindChromecast();
var client = new ChromecastClient();
Expand All @@ -70,18 +87,34 @@ public async void ConnectToChromecastAndLaunchApplicationAThenLaunchApplicationB
}

[Fact]
public async void ConnectToChromecastAndLaunchApplicationOnceAndJoinIt()
public async Task ConnectToChromecastAndLaunchApplicationOnceAndJoinIt()
{
var chromecast = await TestHelper.FindChromecast();
var client = new ChromecastClient();
var status = await client.ConnectChromecast(chromecast);
status = await client.LaunchApplicationAsync("B3419EF5");
var client = await TestHelper.CreateAndConnectClient(output);
var status = await client.LaunchApplicationAsync("B3419EF5");

var firstLaunchTransportId = status.Applications[0].TransportId;

status = await client.LaunchApplicationAsync("B3419EF5");


Assert.Equal(firstLaunchTransportId, status.Applications[0].TransportId);

}

//Seems like this isn't really working anymore and just loading a white screen
[Fact]
public async Task ConnectToChromecastAndLaunchWebPage()
{
var client = await TestHelper.CreateConnectAndLoadAppClient(output, "5CB45E5A");

var req = new WebMessage
{
Type = "loc",
Url = "https://www.google.com/"
};


await client.SendAsync("urn:x-cast:com.url.cast", req, "receiver-0");
}
}
}
6 changes: 4 additions & 2 deletions Sharpcaster.Test/ChromecastConnectionTester.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Xunit;
using System.Threading.Tasks;
using Xunit;

namespace Sharpcaster.Test
{
[Collection("SingleCollection")]
public class ChromecastConnectionTester
{
[Fact]
public async void SearchChromecastsAndConnectToIt()
public async Task SearchChromecastsAndConnectToIt()
{
var chromecast = await TestHelper.FindChromecast();
var client = new ChromecastClient();
Expand Down
7 changes: 2 additions & 5 deletions Sharpcaster.Test/LoggingTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
using Sharpcaster.Interfaces;
using Sharpcaster.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Sharpcaster.Test
{
[Collection("SingleCollection")]
public class LoggingTester
{

Expand Down Expand Up @@ -62,7 +59,7 @@ where t.GetTypeInfo().IsClass && !t.GetTypeInfo().IsAbstract && messageInterface
}

var client = new ChromecastClient(serviceCollection);
Assert.True(logMessageFirst == "[RECEIVER_STATUS,INVALID_REQUEST,LOAD_CANCELLED,LOAD_FAILED,MEDIA_STATUS,PING,CLOSE]");
Assert.Equal("[RECEIVER_STATUS,QUEUE_CHANGE,QUEUE_ITEM_IDS,QUEUE_ITEMS,INVALID_REQUEST,LOAD_CANCELLED,LOAD_FAILED,MEDIA_STATUS,PING,CLOSE]", logMessageFirst);
}
}
}
10 changes: 6 additions & 4 deletions Sharpcaster.Test/MdnsChromecastLocatorTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
using Sharpcaster.Models;
using System;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace Sharpcaster.Test
{
[Collection("SingleCollection")]
public class MdnsChromecastLocatorTester
{
[Fact]
public async void SearchChromecasts()
public async Task SearchChromecasts()
{
IChromecastLocator locator = new MdnsChromecastLocator();
var chromecasts = await locator.FindReceiversAsync();
Assert.NotEmpty(chromecasts);
}

[Fact]
public async void SearchChromecastsTrickerEvent()
public async Task SearchChromecastsTrickerEvent()
{
int counter = 0;
IChromecastLocator locator = new MdnsChromecastLocator();
Expand All @@ -31,7 +33,7 @@ public async void SearchChromecastsTrickerEvent()
}

[Fact]
public async void SearchChromecastsWithTooShortTimeout()
public async Task SearchChromecastsWithTooShortTimeout()
{
IChromecastLocator locator = new MdnsChromecastLocator();
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
Expand All @@ -42,7 +44,7 @@ public async void SearchChromecastsWithTooShortTimeout()


[Fact]
public async void SearchChromecastsCancellationToken()
public async Task SearchChromecastsCancellationToken()
{
IChromecastLocator locator = new MdnsChromecastLocator();
var source = new CancellationTokenSource(TimeSpan.FromMilliseconds(1500));
Expand Down
Loading

0 comments on commit 9ada45b

Please sign in to comment.