public ViewModel() { // コマンドの初期化 PlusCommand = new PlusCommand(); MinusCommand = new MinusCommand(); MultiCommand = new MultiCommand(); DivCommand = new DivCommand(); // コマンド実行後の結果をResultに反映 PlusCommand.PropertyChanged += (sender, e) => { Result = ((PlusCommand)sender).Result.ToString(); RaisePropertyChanged(e.PropertyName); }; MinusCommand.PropertyChanged += (sender, e) => { Result = ((MinusCommand)sender).Result.ToString(); RaisePropertyChanged(e.PropertyName); }; MultiCommand.PropertyChanged += (sender, e) => { Result = ((MultiCommand)sender).Result.ToString(); RaisePropertyChanged(e.PropertyName); }; DivCommand.PropertyChanged += (sender, e) => { Result = ((DivCommand)sender).Result; RaisePropertyChanged(e.PropertyName); }; }
public SYMathCalculator(ISYReciever reciever) { _addCommand = new AddCommand(reciever); _subtractCommand = new SubtractCommand(reciever); _multiplyCommand = new MultiplyCommand(reciever); _divCommand = new DivCommand(reciever); _powCommand = new PowCommand(reciever); }
public void TestExecute1() { var obj = new DivCommand(); // We expect an exception because we are missing any arguments. // obj.Execute(new List <string> { }); }
public void TestAccept2() { var obj = new DivCommand(); // We expect the method to return true. // Assert.IsFalse(obj.Accept("command", new List <string> { })); }
public void TestExecute4() { var obj = new DivCommand(); // We expect an exception because we need exactly two arguments. // obj.Execute(new List <string> { "1", "2", "3" }); }
public void TestExecute2() { var obj = new DivCommand(); // We expect an exception because we are not allowed to divide by zero. // obj.Execute(new List <string> { "1", "0" }); }
public async Task DivByZeroCommandTest() { var services = CreateServices(); var command = new DivCommand() { Divisible = 4, Divisor = 0 }; await Assert.ThrowsAsync <DivideByZeroException>(async() => { await services.Commander().Call(command); }); }
public async Task DivCommandTest() { var services = CreateServices(); var command = new DivCommand() { Divisible = 4, Divisor = 2 }; var result = await services.Commander().Call(command); result.Should().Be(2); }
protected virtual Task <double> Divide(DivCommand command, CancellationToken cancellationToken = default) { var context = CommandContext.GetCurrent <double>(); var handler = context.ExecutionState.Handlers[^ 1];
public virtual void Div(double operand) { var cmd = new DivCommand(math, operand); Calculate(cmd); }