public void Should_AllowDashInUserName_When_RoutingCommands() { // Arrange var SUT = new CommandHandler(readCommand, postCommand, wallCommand); // Act SUT.HandleUserCommand("Alice-80 Wall"); //Assert var routedCall = GetExecuteCall(wallCommandObserver).FirstOrDefault(); if (routedCall == null) Assert.Inconclusive("The request was not routed to the command so this test cannot assert the appropriate routing of arguments"); var routedArguments = routedCall.GetArguments().FirstOrDefault(); Assert.IsInstanceOfType(routedArguments, typeof(string[]), "The routed arguments are of wrong type"); var convertedArguments = (string[])routedArguments; Assert.AreEqual("Alice-80", convertedArguments.FirstOrDefault(), "The User Name argument was not properly routed to the command"); }
public void Should_RoutePostRequestToAppropriateCommand() { // Arrange var SUT = new CommandHandler(readCommand, postCommand, wallCommand); // Act SUT.HandleUserCommand("Alice -> I love the weather today!"); //Assert Assert.IsFalse(GetExecuteCall(readCommandObserver).Any(), "The request was incorrectly routed to ReadCommand"); Assert.IsTrue(GetExecuteCall(postCommandObserver).Any(), "The request was not routed to PostCommand"); Assert.IsFalse(GetExecuteCall(wallCommandObserver).Any(), "The request was incorrectly routed to WallCommand"); }
public void Should_RouteEmptySignatureCommandTextToReadCommand() { // Arrange var SUT = new CommandHandler(readCommand, postCommand, wallCommand); // Act SUT.HandleUserCommand("Alice"); //Assert Assert.IsTrue(GetExecuteCall(readCommandObserver).Any(), "The request was not routed to ReadCommand"); Assert.IsFalse(GetExecuteCall(postCommandObserver).Any(), "The request was incorrectly routed to PostCommand"); Assert.IsFalse(GetExecuteCall(wallCommandObserver).Any(), "The request was incorrectly routed to WallCommand"); }
public void Should_RoutePostArgumentsToAppropriateCommand() { // Arrange var SUT = new CommandHandler(readCommand, postCommand, wallCommand); // Act SUT.HandleUserCommand("Alice -> I love the weather today!"); //Assert var routedCall = GetExecuteCall(postCommandObserver).FirstOrDefault(); if (routedCall == null) Assert.Inconclusive("The request was not routed to the command so this test cannot assert the appropriate routing of arguments"); var routedArguments = routedCall.GetArguments().FirstOrDefault(); Assert.IsInstanceOfType(routedArguments, typeof(string[]), "The routed arguments are of wrong type"); var convertedArguments = (string[])routedArguments; Assert.AreEqual(2, convertedArguments.Length, "Wrong number of arguments"); Assert.AreEqual("Alice", convertedArguments[0], "The User Name argument was not properly routed to the command"); Assert.AreEqual("I love the weather today!", convertedArguments[1], "The message argument was not properly routed to the command"); }
public void Should_ReturnErrorMessage_WhenCommandDoesNotExist() { // Arrange var SUT = new CommandHandler(readCommand, postCommand, wallCommand); // Act var actual = SUT.HandleUserCommand("Alice NotACommand"); //Assert Assert.AreEqual("Unknown command", actual); }