Skip to content

Commit

Permalink
Small format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapanila committed Oct 25, 2024
1 parent 4f13a8d commit 86928f0
Show file tree
Hide file tree
Showing 26 changed files with 130 additions and 80 deletions.
11 changes: 7 additions & 4 deletions Sharpcaster.Test/ChromecastApplicationTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
namespace Sharpcaster.Test
{
[Collection("SingleCollection")]
public class ChromecastApplicationTester : IClassFixture<ChromecastDevicesFixture> {
public class ChromecastApplicationTester : IClassFixture<ChromecastDevicesFixture>
{

private ITestOutputHelper output;
public ChromecastApplicationTester(ITestOutputHelper outputHelper, ChromecastDevicesFixture fixture) {
public ChromecastApplicationTester(ITestOutputHelper outputHelper, ChromecastDevicesFixture fixture)
{
output = outputHelper;
output.WriteLine("Fixture has found " + ChromecastDevicesFixture.Receivers?.Count + " receivers with " + fixture.GetSearchesCnt() + " searche(s).");
}
Expand Down Expand Up @@ -68,7 +70,8 @@ public async Task ConnectToChromecastAndLaunchApplicationTwiceWithoutJoining1(Ch

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetDefaultDevice), MemberType = typeof(ChromecastReceiversFilter))]
public async Task ConnectToChromecastAndLaunchApplicationTwiceWithoutJoining2(ChromecastReceiver receiver) {
public async Task ConnectToChromecastAndLaunchApplicationTwiceWithoutJoining2(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
var client = await TestHelper.CreateAndConnectClient(output, receiver);
var status = await client.LaunchApplicationAsync("B3419EF5");
Expand Down Expand Up @@ -112,7 +115,7 @@ public async Task ConnectToChromecastAndLaunchApplicationOnceAndJoinIt(Chromecas
var firstLaunchTransportId = status.Application.TransportId;

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

Assert.Equal(firstLaunchTransportId, status.Application.TransportId);
}

Expand Down
14 changes: 9 additions & 5 deletions Sharpcaster.Test/LoggingTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ namespace Sharpcaster.Test
public class LoggingTester
{
ITestOutputHelper output;
public LoggingTester(ITestOutputHelper outputHelper) {
public LoggingTester(ITestOutputHelper outputHelper)
{
output = outputHelper;
}

[Fact]
public void TestLogging() {
public void TestLogging()
{
var TestHelper = new TestHelper();
List<string> logLines = [];
_ = TestHelper.GetClientWithTestOutput(output, assertableLog: logLines);
Expand All @@ -26,12 +28,14 @@ public void TestLogging() {

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
public async Task TestPlayMediaWorksWithoutLogging(ChromecastReceiver receiver) {
public async Task TestPlayMediaWorksWithoutLogging(ChromecastReceiver receiver)
{
ChromecastClient client = new ChromecastClient();
await client.ConnectChromecast(receiver);
await client.LaunchApplicationAsync("B3419EF5", false);

var media = new Media {

var media = new Media
{
ContentUrl = "https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4"
};

Expand Down
2 changes: 1 addition & 1 deletion Sharpcaster.Test/MdnsChromecastLocatorTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task SearchChromecastsTrickerEvent()
}

[Fact(Skip = "This fails if Chromecast is quick to answer")]

public async Task SearchChromecastsWithTooShortTimeout()
{
IChromecastLocator locator = new MdnsChromecastLocator();
Expand Down
3 changes: 2 additions & 1 deletion Sharpcaster.Test/MediaChannelTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ public async Task TestFailingQueue(ChromecastReceiver receiver)
try
{
var result = await client.MediaChannel.QueueLoadAsync(MyCd);
} catch (Exception ex)
}
catch (Exception ex)
{
output.WriteLine("Exception happened: " + ex.Message);
}
Expand Down
2 changes: 1 addition & 1 deletion Sharpcaster.Test/MultiZoneChannelTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Sharpcaster.Test
{
public class MultiZoneChannelTester: IClassFixture<ChromecastDevicesFixture>
public class MultiZoneChannelTester : IClassFixture<ChromecastDevicesFixture>
{
private ITestOutputHelper output;

Expand Down
2 changes: 1 addition & 1 deletion Sharpcaster.Test/MultipleClientTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task TestTwoClients(ChromecastReceiver receiver)
ContentUrl = "https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4"
};


var mediaStatus = await client1.MediaChannel.LoadAsync(media);
await client1.MediaChannel.PlayAsync();

Expand Down
20 changes: 13 additions & 7 deletions Sharpcaster.Test/ReceiverChannelTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
namespace Sharpcaster.Test
{
[Collection("SingleCollection")]
public class ReceiverChannelTester : IClassFixture<ChromecastDevicesFixture> {
public class ReceiverChannelTester : IClassFixture<ChromecastDevicesFixture>
{
private ITestOutputHelper output;

public ReceiverChannelTester(ITestOutputHelper outputHelper, ChromecastDevicesFixture fixture) {
public ReceiverChannelTester(ITestOutputHelper outputHelper, ChromecastDevicesFixture fixture)
{
output = outputHelper;
output.WriteLine("Fixture has found " + ChromecastDevicesFixture.Receivers?.Count + " receivers with " + fixture.GetSearchesCnt() + " searche(s).");
}


[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
public async Task TestMute(ChromecastReceiver receiver) {
public async Task TestMute(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
var client = await TestHelper.CreateAndConnectClient(output, receiver);

Expand All @@ -29,7 +32,8 @@ public async Task TestMute(ChromecastReceiver receiver) {

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
public async Task TestUnMute(ChromecastReceiver receiver) {
public async Task TestUnMute(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
var client = await TestHelper.CreateAndConnectClient(output, receiver);

Expand All @@ -39,10 +43,11 @@ public async Task TestUnMute(ChromecastReceiver receiver) {

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
public async Task TestVolume(ChromecastReceiver receiver) {
public async Task TestVolume(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
var client = await TestHelper.CreateAndConnectClient(output, receiver);

var status = await client.ReceiverChannel.SetVolume(0.1);
Assert.Equal(0.1, status.Volume.Level.Value, precision: 1);

Expand All @@ -56,7 +61,8 @@ public async Task TestVolume(ChromecastReceiver receiver) {

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetAll), MemberType = typeof(ChromecastReceiversFilter))]
public async Task TestStoppingApplication(ChromecastReceiver receiver) {
public async Task TestStoppingApplication(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
var client = await TestHelper.CreateAndConnectClient(output, receiver);

Expand Down
5 changes: 3 additions & 2 deletions Sharpcaster.Test/SpotifyTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ public async Task<string> GetSpotifyAccessTokenForChromecast(string originalAcce
"authority", "spclient.wg.spotify.com");
client.DefaultRequestHeaders.Add(
"authorization", "Bearer " + originalAccessToken);
var jsonContent = JsonContent.Create(new {
var jsonContent = JsonContent.Create(new
{
clientId,
deviceId
});


var result = await client.PostAsync("/device-auth/v1/refresh", jsonContent);
result.EnsureSuccessStatusCode();
Expand Down
15 changes: 10 additions & 5 deletions Sharpcaster.Test/helper/ChromecastDeviceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@ namespace Sharpcaster.Test.helper
{

// Define a TestFixture to be used by different test classes
public class ChromecastDevicesFixture : IDisposable {
public class ChromecastDevicesFixture : IDisposable
{

// This needs to be static to be used by the MemberData functions of the ChromecastReceiversFilter class allowing to annotate [Theories] with specific list of devices.
public static List<ChromecastReceiver> Receivers = [];
public static int NumberOfSearches;

static ChromecastDevicesFixture() {
static ChromecastDevicesFixture()
{
MdnsChromecastLocator locator = new();
var t = locator.FindReceiversAsync();
t.Wait();
Receivers = t.Result.ToList();
NumberOfSearches++;
}

public int GetSearchesCnt() {
public int GetSearchesCnt()
{
return NumberOfSearches;
}

public void Dispose() {
public void Dispose()
{
//Receivers.Clear();
}

Expand All @@ -35,7 +39,8 @@ public void Dispose() {

// Lets use out fixture as 'Collection Fixture' -> its only initilized once for all tests in this collection.
[CollectionDefinition("SingleCollection")]
public class ChromecastDevicesFixtureCollection : ICollectionFixture<ChromecastDevicesFixture> {
public class ChromecastDevicesFixtureCollection : ICollectionFixture<ChromecastDevicesFixture>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
Expand Down
46 changes: 30 additions & 16 deletions Sharpcaster.Test/helper/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,23 +305,31 @@ public QueueItem[] CreateTestCd()
{
QueueItem[] MyCd =
[
new QueueItem() {
Media = new Media {
new QueueItem()
{
Media = new Media
{
ContentUrl = "http://www.openmusicarchive.org/audio/Frankie%20by%20Mississippi%20John%20Hurt.mp3"
}
},
new QueueItem() {
Media = new Media {
new QueueItem()
{
Media = new Media
{
ContentUrl = "http://www.openmusicarchive.org/audio/Mississippi%20Boweavil%20Blues%20by%20The%20Masked%20Marvel.mp3"
}
},
new QueueItem() {
Media = new Media {
new QueueItem()
{
Media = new Media
{
ContentUrl = "http://www.openmusicarchive.org/audio/The%20Wild%20Wagoner%20by%20Jilson%20Setters.mp3"
}
},
new QueueItem() {
Media = new Media {
new QueueItem()
{
Media = new Media
{
ContentUrl = "http://www.openmusicarchive.org/audio/Drunkards%20Special%20by%20Coley%20Jones.mp3"
}
},
Expand All @@ -333,23 +341,29 @@ public QueueItem[] CreateFailingQueu()
{
QueueItem[] queueItems =
[

new QueueItem() {
Media = new Media {

new QueueItem()
{
Media = new Media
{
ContentUrl = "https://audionautix.com/Music/AwayInAManger.mp3"
}
},
new QueueItem() {
Media = new Media {
new QueueItem()
{
Media = new Media
{
ContentUrl = "https://audionautix.com/Music/CarolOfTheBells.mp3"
}
},
new QueueItem() {
Media = new Media {
new QueueItem()
{
Media = new Media
{
ContentUrl = "https://audionautix.com/Music/JoyToTheWorld.mp3"
}
}

];
return queueItems;
}
Expand Down
5 changes: 3 additions & 2 deletions Sharpcaster/Channels/ChromecastChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ protected ChromecastChannel(string ns, ILogger logger, bool useBaseNamespace = t
if (useBaseNamespace)
{
Namespace = $"{BASE_NAMESPACE}.{ns}";
} else
}
else
{
Namespace = ns;
}

}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions Sharpcaster/Channels/ConnectionChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public async Task ConnectAsync(string transportId)
/// <param name="message">message to process</param>
public async override Task OnMessageReceivedAsync(IMessage message)
{
if (message is CloseMessage) {
if (message is CloseMessage)
{
// In order to avoid usage deadlocks we need to spawn a new Task here!?
_ = Task.Run(async () => {
_ = Task.Run(async () =>
{
await Client.DisconnectAsync();
});
}
Expand Down
2 changes: 1 addition & 1 deletion Sharpcaster/Channels/HeartbeatChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public HeartbeatChannel(ILogger<HeartbeatChannel> logger = null) : base("tp.hear
/// <param name="message">message to process</param>
public override async Task OnMessageReceivedAsync(IMessage message)
{

_timer.Stop();
await SendAsync(new PongMessage());
_timer.Start();
Expand Down
4 changes: 2 additions & 2 deletions Sharpcaster/Channels/MultiZoneChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MultiZoneChannel : ChromecastChannel
/// Raised when the status has changed
/// </summary>
public event EventHandler<MultiZoneStatus> StatusChanged;

/// <summary>
/// Raised when device has been updated
/// </summary>
Expand Down Expand Up @@ -53,7 +53,7 @@ public override Task OnMessageReceivedAsync(IMessage message)
/// </summary>
protected virtual void OnStatusChanged()
{

}
}
}
8 changes: 5 additions & 3 deletions Sharpcaster/Channels/SpotifyChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
namespace Sharpcaster.Channels
{
public class SpotifyChannel : ChromecastChannel
{
{
public event EventHandler<SpotifyStatus> SpotifyStatusUpdated;
public SpotifyStatus SpotifyStatus{ get; set; }
public SpotifyStatus SpotifyStatus { get; set; }
public event EventHandler<AddUserResponseMessagePayload> AddUserResponseReceived;

public SpotifyChannel(ILogger<SpotifyChannel> logger = null) : base("urn:x-cast:com.spotify.chromecast.secure.v1", logger, false)
Expand Down Expand Up @@ -74,7 +74,9 @@ await SendAsync(new AddUserMessage
}, Client.GetChromecastStatus().Application.TransportId);
}

public string SpotifyDeviceId { get
public string SpotifyDeviceId
{
get
{
var friendlyName = Client.FriendlyName;
return ComputeMd5Hash(friendlyName);
Expand Down
Loading

0 comments on commit 86928f0

Please sign in to comment.