-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7898e9e
commit 3c7e9a4
Showing
31 changed files
with
478 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using AllMyLights.Connectors.Sinks; | ||
using AllMyLights.Connectors.Sources; | ||
using AllMyLights.Models; | ||
using Microsoft.Reactive.Testing; | ||
using Moq; | ||
using NUnit.Framework; | ||
using OpenRGB.NET; | ||
using OpenRGB.NET.Models; | ||
using Unmockable; | ||
|
||
namespace AllMyLights.Test | ||
{ | ||
public class BrokerTest : ReactiveTest | ||
{ | ||
Mock<ISource> MqttSource = new Mock<ISource>(); | ||
Mock<ISource> SSESource = new Mock<ISource>(); | ||
|
||
Mock<ISink> OpenRGBSink = new Mock<ISink>(); | ||
Mock<ISink> WallpaperSink = new Mock<ISink>(); | ||
|
||
[Test] | ||
public void Should_invoke_sinks_with_colors_emitted_from_sources() | ||
{ | ||
var red = System.Drawing.Color.FromName("red"); | ||
var black = System.Drawing.Color.FromName("black"); | ||
var green = System.Drawing.Color.FromName("green"); | ||
|
||
var broker = new Broker() | ||
.RegisterSources(MqttSource.Object, SSESource.Object) | ||
.RegisterSinks(OpenRGBSink.Object, WallpaperSink.Object); | ||
|
||
var scheduler = new TestScheduler(); | ||
|
||
MqttSource.Setup(it => it.Get()).Returns(() => | ||
{ | ||
return scheduler.CreateHotObservable(OnNext(150, red)); | ||
}); | ||
|
||
SSESource.Setup(it => it.Get()).Returns(() => | ||
{ | ||
return scheduler.CreateHotObservable(OnNext(100, black), OnNext(300, green)); | ||
}); | ||
|
||
broker.Listen(); | ||
|
||
scheduler.AdvanceBy(200); | ||
|
||
OpenRGBSink.Verify((it) => it.Consume(black)); | ||
OpenRGBSink.Verify((it) => it.Consume(red)); | ||
|
||
WallpaperSink.Verify((it) => it.Consume(black)); | ||
WallpaperSink.Verify((it) => it.Consume(red)); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using AllMyLights.Connectors.Sinks; | ||
using AllMyLights.Connectors.Sources; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
|
||
namespace AllMyLights | ||
{ | ||
public class Broker | ||
{ | ||
|
||
private List<ISink> Sinks { get; } = new List<ISink>(); | ||
private List<ISource> Sources { get; } = new List<ISource>(); | ||
|
||
public Broker RegisterSources(params ISource[] sources) | ||
{ | ||
Sources.AddRange(sources); | ||
return this; | ||
} | ||
|
||
public Broker RegisterSinks(params ISink[] sinks) | ||
{ | ||
Sinks.AddRange(sinks); | ||
return this; | ||
} | ||
|
||
public void Listen() | ||
{ | ||
Observable | ||
.Merge(Sources.Select((it) => it.Get())) | ||
.Subscribe((color) => | ||
{ | ||
Sinks.ForEach((sink) => sink.Consume(color)); | ||
}); | ||
|
||
} | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.