-
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.
Separate transformation from transport logic
- Loading branch information
1 parent
388e426
commit 35dd806
Showing
45 changed files
with
999 additions
and
229 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
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 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,9 @@ | ||
using Microsoft.Reactive.Testing; | ||
|
||
namespace AllMyLights.Test | ||
{ | ||
public class ObservableExtensionsTest : ReactiveTest | ||
{ | ||
|
||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
AllMyLights.Test/Transformations/ColorTransformationTest.cs
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,97 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Reactive; | ||
using System.Reactive.Linq; | ||
using AllMyLights.Common; | ||
using AllMyLights.Models.Transformations; | ||
using AllMyLights.Transformations; | ||
using Microsoft.Reactive.Testing; | ||
using NUnit.Framework; | ||
|
||
namespace AllMyLights.Test | ||
{ | ||
public class ColorTransformationTest : ReactiveTest | ||
{ | ||
|
||
[Test] | ||
public void Should_transform_color() | ||
{ | ||
var black = "#000000"; | ||
Ref<Color> expectedColor = new Ref<Color>(Color.FromArgb(255, 0, 0, 0)); | ||
var source = Observable.Return(black); | ||
|
||
var transformation = new ColorTransformation(new ColorTransformationOptions()); | ||
|
||
var scheduler = new TestScheduler(); | ||
|
||
|
||
var actual = scheduler.Start( | ||
() => transformation.GetOperator()(source), | ||
created: 0, | ||
subscribed: 10, | ||
disposed: 100 | ||
); | ||
|
||
var expected = new Recorded<Notification<Ref<Color>>>[] { | ||
OnNext(10, expectedColor), | ||
OnCompleted<Ref<Color>>(10) | ||
}; | ||
|
||
ReactiveAssert.AreElementsEqual(expected, actual.Messages); | ||
} | ||
|
||
[Test] | ||
public void Should_transform_color_using_given_channel_layout() | ||
{ | ||
var black = "#FF0000"; | ||
var expectedColor = new Ref<Color>(Color.FromArgb(255, 0, 255, 0)); | ||
var source = Observable.Return(black); | ||
|
||
var transformation = new ColorTransformation(new ColorTransformationOptions() | ||
{ | ||
ChannelLayout = "GRB" | ||
}); | ||
|
||
var scheduler = new TestScheduler(); | ||
|
||
|
||
var actual = scheduler.Start( | ||
() => transformation.GetOperator()(source), | ||
created: 0, | ||
subscribed: 10, | ||
disposed: 100 | ||
); | ||
|
||
var expected = new Recorded<Notification<Ref<Color>>>[] { | ||
OnNext(10, expectedColor), | ||
OnCompleted<Ref<Color>>(10) | ||
}; | ||
|
||
ReactiveAssert.AreElementsEqual(expected, actual.Messages); | ||
} | ||
|
||
[Test] | ||
public void Should_throw_argument_exception_for_invalid_input() | ||
{ | ||
var source = Observable.Return(new object()); | ||
|
||
var transformation = new ColorTransformation(new ColorTransformationOptions()); | ||
|
||
var scheduler = new TestScheduler(); | ||
|
||
|
||
var actual = scheduler.Start( | ||
() => transformation.GetOperator()(source), | ||
created: 0, | ||
subscribed: 10, | ||
disposed: 100 | ||
); | ||
|
||
|
||
Recorded<Notification<Ref<Color>>> first = actual.Messages.First(); | ||
Equals(NotificationKind.OnError, first.Value.Kind); | ||
Equals(typeof(ArgumentException), first.Value.Exception.GetType()); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
AllMyLights.Test/Transformations/JsonPathTransformationTest.cs
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,67 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reactive; | ||
using System.Reactive.Linq; | ||
using AllMyLights.Models.Transformations; | ||
using AllMyLights.Transformations; | ||
using Microsoft.Reactive.Testing; | ||
using NUnit.Framework; | ||
|
||
namespace AllMyLights.Test | ||
{ | ||
public class JsonPathTransformationTest : ReactiveTest | ||
{ | ||
|
||
[Test] | ||
public void Should_extract_deeply_nested_value() | ||
{ | ||
var json = "{\"data\":{\"livingRoom\":{\"color\": \"red\"}}}"; | ||
var source = Observable.Return(json); | ||
|
||
var options = new JsonPathTransformationOptions() { Expression = "$.data.livingRoom.color" }; | ||
var transformation = new JsonPathTransformation<string>(options); | ||
|
||
var scheduler = new TestScheduler(); | ||
|
||
|
||
var actual = scheduler.Start( | ||
() => transformation.GetOperator()(source), | ||
created: 0, | ||
subscribed: 10, | ||
disposed: 100 | ||
); | ||
|
||
var expected = new Recorded<Notification<string>>[] { | ||
OnNext(10, "red"), | ||
OnCompleted<string>(10) | ||
}; | ||
|
||
ReactiveAssert.AreElementsEqual(expected, actual.Messages); | ||
} | ||
|
||
[Test] | ||
public void Should_throw_argument_exception_for_invalid_input() | ||
{ | ||
var source = Observable.Return(new object()); | ||
|
||
var options = new JsonPathTransformationOptions() { Expression = "$.data.livingRoom.color" }; | ||
var transformation = new JsonPathTransformation<string>(options); | ||
|
||
var scheduler = new TestScheduler(); | ||
|
||
|
||
var actual = scheduler.Start( | ||
() => transformation.GetOperator()(source), | ||
created: 0, | ||
subscribed: 0, | ||
disposed: 100 | ||
); | ||
|
||
|
||
|
||
Recorded<Notification<string>> first = actual.Messages.First(); | ||
Equals(NotificationKind.OnError, first.Value.Kind); | ||
Equals(typeof(ArgumentException), first.Value.Exception.GetType()); | ||
} | ||
} | ||
} |
Oops, something went wrong.