public void ShouldThrowIfBadCommandExecuted() { var command = new BadCommand(); Func <Task> execute = async() => await command.Execute(); execute.Should().ThrowExactly <CommandExecutionException>(); }
public async Task <IActionResult> Post( [FromServices] IConfiguration configuration, [FromBody] Update update, [FromServices] Bot bot, [FromServices] IExpenseRepository expenseRepository, [FromServices] IUserAccountRepository userAccountRepository, [FromServices] ICategoryRepository categoryRepository) { if (update == null) { return(Ok()); } var commands = bot.Commands; var message = update.Message; if (message == null) { return(Ok()); } var config = configuration.Get <Settings>(); var client = await bot.Get(config); //TODO: обновление даты (new IinternalCommand ?) foreach (var command in commands) { if (command.Contains(config, message)) { await command.Execute(message, client, expenseRepository, userAccountRepository, categoryRepository); return(Ok()); } } var parseCommandDict = MessageParser .ComposeParseCommandDict(message, userAccountRepository, categoryRepository, expenseRepository); //TODO: Exeption handlers try { var parsedCommand = MessageParser .ReadCommand(parseCommandDict, message); await parsedCommand.Execute(message, client); } catch (CommandExeption e) { var badCommand = new BadCommand(e); await badCommand.Execute(message, client); } return(Ok()); }
public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException() { BadCommand target = new BadCommand(); IMethodInterceptor mock = A.Fake <IMethodInterceptor>(); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock }); A.CallTo(() => mock.Invoke(null)).WithAnyArguments().Throws <NotImplementedException>(); // we want this exception to bubble up... Assert.Throws <NotImplementedException>(() => join.Proceed()); }
private bool _TryParseDistance(string[] argsText, out AbstractCommand cmd) { // здесь может некорректный формат команды cmd = new BadCommand(this.currCmdText); if (argsText.Length != 4) return false; // на каждую точку по две координаты Point[] points = new Point[argsText.Length / 2]; for (int i = 0; i < points.Length; ++i) if (!_TryParsePoint(argsText[2 * i], argsText[2 * i + 1], ref points[i])) return false; cmd = new DistanceCommand(points[0], points[1]); return true; }
public void InitialState_TestingBadCommand_SuccessResultReplied() { var aggregateId = TestAggregateId.New; var commandId = SourceId.New; var command = new BadCommand(aggregateId).WithSourceId(commandId); var fixture = new AggregateFixture <TestAggregateId, TestAggregate, ITestAggregateState, TestAggregateState>(this); fixture.For(aggregateId) .GivenNothing() .When(command) .ThenExpectResult(r => !r.IsSuccess); }
private bool _TryParseTriangle(CommandKind cmdKind, string[] argsText, out AbstractCommand cmd) { // здесь может некорректный формат команды cmd = new BadCommand(this.currCmdText); // команда работы с треугольником принимает лидо длины строн (3 аргумента), // либо координаты вершин (6 аргументов) if (argsText.Length != 3 && argsText.Length != 6) return false; TriangleCommand trnglCmd = null; // создаём конкретную команду switch (cmdKind) { case CommandKind.TRIANGLE_AREA: trnglCmd = new TriangleAreaCommand(); break; case CommandKind.TRIANGLE_PERIM: trnglCmd = new TrianglePerimCommand(); break; case CommandKind.TRIANGLE_IS_RIGHT: trnglCmd = new TriangleIsRightCommand(); break; case CommandKind.TRIANGLE_IS_EQUIL: trnglCmd = new TriangleIsRightCommand(); break; default: Debug.Assert(false, "_TryParseTriangle must be called only for triangle commands"); break; } // инициализируем данными треугольника if (argsText.Length == 3) { double[] sides; if (!_TryParseTriangleSides(argsText, out sides)) return false; trnglCmd.Init(sides); } else { Debug.Assert(argsText.Length == 6, "This case only for 6 args-coordinates"); Point[] vertices; if (!_TryParseTriangleVertices(argsText, out vertices)) return false; trnglCmd.Init(vertices); } cmd = trnglCmd; return true; }
public void UnwrapsTargetInvocationException_NoInterceptors() { BadCommand target = new BadCommand(); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { }); try { join.Proceed(); } catch (NotImplementedException) { // this is good, we want this exception to bubble up... } catch (TargetInvocationException) { Assert.Fail("Must have unwrapped this."); } }
public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException() { BadCommand target = new BadCommand(); IMethodInterceptor mock = (IMethodInterceptor)mocks.CreateMock(typeof(IMethodInterceptor)); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock }); Expect.Call(mock.Invoke(null)).IgnoreArguments().Throw(new NotImplementedException()); mocks.ReplayAll(); try { join.Proceed(); } catch (NotImplementedException) { // this is good, we want this exception to bubble up... } catch (TargetInvocationException) { Assert.Fail("Must have unwrapped this."); } mocks.VerifyAll(); }
public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException() { BadCommand target = new BadCommand(); IMethodInterceptor mock = (IMethodInterceptor) mocks.CreateMock(typeof(IMethodInterceptor)); AbstractMethodInvocation join = CreateMethodInvocation( null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock }); Expect.Call(mock.Invoke(null)).IgnoreArguments().Throw(new NotImplementedException()); mocks.ReplayAll(); try { join.Proceed(); } catch (NotImplementedException) { // this is good, we want this exception to bubble up... } catch (TargetInvocationException) { Assert.Fail("Must have unwrapped this."); } mocks.VerifyAll(); }
public Task <Result> Do(BadCommand command) { throw new Exception("Bad Command"); }
public Task <IExecutionResult> Execute(BadCommand command) { return(Task.FromResult((IExecutionResult) new FailedTestExecutionResult(command.Metadata.SourceId, new List <String> { "Test cause" }))); }
public override T VisitBadCommand(BadCommand node) { throw new NotImplementedException(); }