public OperationNode() { kernel = new StandardKernel(); interactions = new InteractionService(); mixer = Substitute.For <IMixerViewModel, ReactiveObject>(); inputA = Substitute.For <IInConnectorViewModel, ReactiveObject>(); inputB = Substitute.For <IInConnectorViewModel, ReactiveObject>(); output = Substitute.For <IOutConnectorViewModel, ReactiveObject>(); kernel.Bind <IInteractionService>() .ToConstant(interactions); kernel.Bind <IMixerViewModel>() .ToConstant(mixer); kernel.Bind <IOutConnectorViewModel>() .ToConstant(output); kernel.Bind <IOperationNodeViewModel>() .To <OperationNodeViewModel>() .InSingletonScope() .WithConstructorArgument("inputA", inputA) .WithConstructorArgument("inputB", inputB); // system under test inputA.ConnectedTo = Arg.Do <IOutConnectorViewModel>( _ => inputA.RaisePropertyChanged(nameof(inputA.ConnectedTo))); inputB.ConnectedTo = Arg.Do <IOutConnectorViewModel>( _ => inputB.RaisePropertyChanged(nameof(inputB.ConnectedTo))); }
public static void ConnectToNode(this IOutConnectorViewModel input, INode node) { var output = Substitute.For <IInConnectorViewModel>(); output.Node.Returns(node); input.ConnectedTo = output; }
public OperationNodeViewModel(IInteractionService interactions = null, IMixerViewModel mixer = null, IInConnectorViewModel inputA = null, IInConnectorViewModel inputB = null, IOutConnectorViewModel output = null) { this.interactions = interactions ?? Locator.Current.GetService <IInteractionService>(); this.mixer = mixer ?? Locator.Current.GetService <IMixerViewModel>(); InputA = inputA ?? Locator.Current.GetService <IInConnectorViewModel>(); InputB = inputB ?? Locator.Current.GetService <IInConnectorViewModel>(); Output = output ?? Locator.Current.GetService <IOutConnectorViewModel>(); InputA.Node = this; InputB.Node = this; Output.Node = this; this.WhenActivated(disposables => { this // Handle the connections .WhenAnyValue(vm => vm.InputA.ConnectedTo, vm => vm.InputB.ConnectedTo, vm => vm.Operation, (a, b, op) => new { A = a, B = b, Op = op }) .Select(i => i.A != null && i.B != null ? Execute(i.A.Node.Color, i.B.Node.Color, i.Op) : DefaultColor) .BindTo(this, vm => vm.Color) .DisposeWith(disposables); this // Handle the color .WhenAnyValue(vm => vm.InputA.ConnectedTo.Node.Color, vm => vm.InputB.ConnectedTo.Node.Color, vm => vm.Operation, (a, b, op) => new { A = a, B = b, Op = op }) .Where(_ => InputA?.ConnectedTo?.Node != null && // when nodes are connected InputB?.ConnectedTo?.Node != null) .Select(i => Execute(i.A, i.B, i.Op)) .BindTo(this, vm => vm.Color) .DisposeWith(disposables); EditNodeCommand = ReactiveCommand.CreateFromTask(async() => { Operation = await this.interactions .GetNodeOperation .Handle(Operation); }, this.WhenAnyValue(vm => vm.mixer.IsNodeBeingAdded, vm => vm.mixer.ConnectingConnector, (a, b) => !a && b == null)) .DisposeWith(disposables); }); }
public async void SetsIsConnected(bool expected, IOutConnectorViewModel connectedTo) { // Arrange var connector = kernel.Get <IInConnectorViewModel>(); // Act connector.Activator .Activate(); connector.ConnectedTo = connectedTo; var isConnected = await connector.WhenAnyValue(vm => vm.IsConnected) .FirstAsync(); // Assert isConnected.Should().Be(expected); }
public ColorNode() { kernel = new StandardKernel(); interactions = new InteractionService(); mixer = Substitute.For <IMixerViewModel, ReactiveObject>(); output = Substitute.For <IOutConnectorViewModel>(); kernel.Bind <IInteractionService>() .ToConstant(interactions); kernel.Bind <IMixerViewModel>() .ToConstant(mixer); kernel.Bind <IOutConnectorViewModel>() .ToConstant(output); kernel.Bind <IColorNodeViewModel>() .To <ColorNodeViewModel>() .InSingletonScope(); // system under test }
public ColorNodeViewModel(IInteractionService interactions = null, IMixerViewModel mixer = null, IOutConnectorViewModel output = null) { this.interactions = interactions ?? Locator.Current.GetService <IInteractionService>(); this.mixer = mixer ?? Locator.Current.GetService <IMixerViewModel>(); this.output = output ?? Locator.Current.GetService <IOutConnectorViewModel>(); this.output.Node = this; this.WhenActivated(disposables => { EditNodeCommand = ReactiveCommand.CreateFromTask(async() => { Color = await this.interactions .GetNodeColor .Handle(Color); }, this.WhenAnyValue(vm => vm.mixer.IsNodeBeingAdded, vm => vm.mixer.ConnectingConnector, (a, b) => !a && b == null)) .DisposeWith(disposables); }); }
public void SetsOutProperties(string property, IOutConnectorViewModel initial, IOutConnectorViewModel expected) => kernel.Get <IConnectionViewModel>() .ShouldSetProperty(property, initial, expected);
public static void ConnectToNodeWithColor(this IOutConnectorViewModel input, Color color) => input.ConnectToNode(CreateNode(color));