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

Adding more test capabilities #86

Merged
merged 10 commits into from
Feb 1, 2019
23 changes: 23 additions & 0 deletions src/StreamDeckLib.Test/ConnectionManager_UnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using Xunit;
using FluentAssertions;
using System.Threading;
using System.Diagnostics;
using System.Threading.Tasks;

namespace StreamDeckLib.Test
{
Expand All @@ -18,5 +21,25 @@ public void ThrowAnArgumentException_WhenInitializedWithEmptyArgs()
// Assert
action.Should().Throw<ArgumentException>();
}

[Fact]
public async Task ShouldRegisterEvent_WhenInitializedWithCorrectArgs() {

// Arrange
var stub = new StubProxy() {
InspectRegister = (e, uuid) => {
Assert.Equal(StubProxy.TEST_EVENT, e);
Assert.Equal(uuid, uuid);
}
};

// Act
await ConnectionManager.Initialize(StubProxy.ValidCommandLineArguments, null, stub)
.StartAsync(CancellationToken.None);

// Assert

}

}
}
87 changes: 87 additions & 0 deletions src/StreamDeckLib.Test/StubProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using StreamDeckLib.Messages;

namespace StreamDeckLib.Test
{
/// <summary>
/// A StreamDeck proxy base class
/// </summary>
public class StubProxy : IStreamDeckProxy
{

public const int TEST_PORT = 3000;
public const string TEST_UUID = "TEST_UUID";
public const string TEST_EVENT = "TEST_EVENT_TYPE";

public static readonly string[] ValidCommandLineArguments = new string[] {
"-port", TEST_PORT.ToString(), // Made up port number
"-pluginUUID", TEST_UUID,
"-registerEvent", TEST_EVENT,
"-info", @"{
""application"": {
""language"": ""en"",
""platform"": ""mac"",
""version"": ""4.0.0""
},
""devices"": [
{
""id"": ""55F16B35884A859CCE4FFA1FC8D3DE5B"",
""size"": {

""columns"": 5,
""rows"": 3

},
""type"": 0
},
{
""id"": ""B8F04425B95855CF417199BCB97CD2BB"",
""size"": {
""columns"": 3,
""rows"": 2
},
""type"": 1
}
]
}"
};

public Action<Uri,CancellationToken> InspectConnectAsync { get; set; }
public Action<string, string> InspectRegister { get; set; }

public WebSocketState State { get; set; }

public Task ConnectAsync(Uri uri, CancellationToken token)
{
InspectConnectAsync?.Invoke(uri, token);
return Task.CompletedTask;
}

public void Dispose()
{
throw new NotImplementedException();
}

public Task<string> GetMessageAsString(CancellationToken token)
{
return Task.FromResult("");
}

public Task Register(string registerEvent, string uuid)
{
InspectRegister?.Invoke(registerEvent, uuid);
return Task.CompletedTask;
}

public Task SendStreamDeckEvent(BaseStreamDeckArgs args)
{
throw new NotImplementedException();
}

}
}
Loading