-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1459 from glopesdev/issue-1458
Require user defined conversion when multicasting to subject with non-matching type
- Loading branch information
Showing
5 changed files
with
94 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Reactive.Linq; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bonsai.Core.Tests | ||
{ | ||
public partial class CombinatorBuilderTests | ||
{ | ||
[Combinator] | ||
class TypeCombinatorMock<T> : Combinator<T, T> | ||
{ | ||
public override IObservable<T> Process(IObservable<T> source) | ||
{ | ||
return source; | ||
} | ||
} | ||
|
||
private void BuildConvertCast<TSource, TResult>(TSource value, out TResult result) | ||
{ | ||
var combinator = new TypeCombinatorMock<TResult>(); | ||
var source = CreateObservableExpression(Observable.Return(value)); | ||
var resultProvider = TestCombinatorBuilder<TResult>(combinator, source); | ||
result = Last(resultProvider).Result; | ||
} | ||
|
||
[TestMethod] | ||
public void Build_ConvertDoubleToInt_ReturnsTruncatedValue() | ||
{ | ||
var value = 5.5; | ||
BuildConvertCast(value, out int result); | ||
Assert.AreEqual((int)value, result); | ||
} | ||
|
||
[TestMethod] | ||
public void Build_ConvertObjectToImplementedInterface_ReturnsValidObject() | ||
{ | ||
BuildConvertCast(5.5, out IComparable result); | ||
Assert.IsNotNull(result); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(WorkflowBuildException))] | ||
public void Build_ConvertObjectToNotImplementedInterface_ThrowsBuildException() | ||
{ | ||
BuildConvertCast(5.5, out IDisposable result); | ||
Assert.IsNotNull(result); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(WorkflowBuildException))] | ||
public void Build_ConvertInterfaceToDifferentInterface_ThrowsBuildException() | ||
{ | ||
BuildConvertCast(5.5, out IComparable result); | ||
BuildConvertCast(result, out IDisposable disposable); | ||
Assert.AreSame((IDisposable)result, disposable); | ||
} | ||
} | ||
} |
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