예제 #1
0
 public void ExecuteTest(SimpleCommandWithIntegerResult command, Exception thrownException)
 {
     "Given a command whose handler throws an exception"
     .x(() => command = new SimpleCommandWithIntegerResult(new Exception("something went wrong")));
     "When I dispatch the command"
     .x(async() =>
     {
         try
         {
             await Dispatcher.DispatchAsync(command);
         }
         catch (Exception ex)
         {
             thrownException = ex;
         }
     });
     "Then the exception is propagated back to the caller"
     .x(() =>
     {
         Assert.NotNull(thrownException);
         Assert.IsType <CommandExecutionException>(thrownException);
         CommandExecutionException commandExecutionException = (CommandExecutionException)thrownException;
         Assert.NotNull(commandExecutionException.InnerException);
         Assert.Equal("something went wrong", commandExecutionException.InnerException.Message);
     });
 }
 public void ExecuteTest(SimpleCommandWithIntegerResult command, int result)
 {
     "Given a command with an integer result"
     .x(() => command = new SimpleCommandWithIntegerResult());
     "When I dispatch the command"
     .x(async() => result = await Dispatcher.DispatchAsync(command));
     "Then the associated command handler is executed and the correct result returned"
     .x(() =>
     {
         Assert.Equal(99, result);
     });
 }
 public void ExecuteTest(SimpleCommandWithIntegerResult command)
 {
     "Given a command that returns a result"
     .x(() => command = new SimpleCommandWithIntegerResult());
     "When I dispatch the command using a custom dispatcher"
     .x(async() => await Dispatcher.DispatchAsync(command));
     "Then the custom dispatcher is used"
     .x(() =>
     {
         Assert.Equal(1, CustomDispatcher.Log.Count);
         Assert.Contains("Command of type SimpleCommandWithIntegerResult dispatched", CustomDispatcher.Log);
     });
 }
        public void ExecuteTest(SimpleCommandWithIntegerResult command, Exception ex)
        {
            "Given a command with no registered handler"
                .x(() => command = new SimpleCommandWithIntegerResult());
            "When I dispatch the command"
                .x(async () =>
                {
                    try
                    {
                        await Dispatcher.DispatchAsync(command);
                    }
                    catch (Exception e)
                    {
                        ex = e;
                    }

                });
            "Then a meaningful exception is raised"
                .x(() =>
                {
                    Assert.NotNull(ex);
                    Assert.IsType<MissingCommandHandlerRegistrationException>(ex);
                });
        }