public void RetrievesTheUserBasedOnTheFirstPartOfTheInput() { var handler = new Mock <IHandler>(); handlerFactory .Setup(it => it.GetHandler(It.IsAny <string>())) .Returns(handler.Object); sut.Handle("abc def ghi"); userRepository.Verify(it => it.CreateOrFind("abc")); }
public void UsingTheInputHandler() { var inputHandler = new InputTerminal(userRepository, new HandlerFactory(userRepository)); // posting Sys.Time = () => new DateTime(2000, 1, 1, 10, 0, 0); inputHandler.Handle("Alice -> I love the weather today"); Sys.Time = () => new DateTime(2000, 1, 1, 10, 3, 0); inputHandler.Handle("Bob -> Damn! We lost!"); Sys.Time = () => new DateTime(2000, 1, 1, 10, 4, 0); inputHandler.Handle("Bob -> Good game though."); // reading Sys.Time = () => new DateTime(2000, 1, 1, 10, 5, 0); var response1 = inputHandler.Handle("Alice").ToList(); Assert.AreEqual(1, response1.Count); Assert.AreEqual("I love the weather today (5 minutes ago)", response1[0]); var response2 = inputHandler.Handle("Bob").ToList(); Assert.AreEqual(2, response2.Count); Assert.AreEqual("Good game though. (1 minute ago)", response2[0]); Assert.AreEqual("Damn! We lost! (2 minutes ago)", response2[1]); // following Sys.Time = () => new DateTime(2000, 1, 1, 10, 5, 0); inputHandler.Handle("Charlie -> I'm in New York today! Anyone want to have a coffee?"); Sys.Time = () => new DateTime(2000, 1, 1, 10, 5, 2); inputHandler.Handle("Charlie follows Alice"); var response3 = inputHandler.Handle("Charlie wall").ToList(); Assert.AreEqual(2, response3.Count); Assert.AreEqual("Charlie - I'm in New York today! Anyone want to have a coffee? (2 seconds ago)", response3[0]); Assert.AreEqual("Alice - I love the weather today (5 minutes ago)", response3[1]); inputHandler.Handle("Charlie follows Bob"); var response4 = inputHandler.Handle("Charlie wall").ToList(); Assert.AreEqual(4, response4.Count); Assert.AreEqual("Charlie - I'm in New York today! Anyone want to have a coffee? (2 seconds ago)", response4[0]); Assert.AreEqual("Bob - Good game though. (1 minute ago)", response4[1]); Assert.AreEqual("Bob - Damn! We lost! (2 minutes ago)", response4[2]); Assert.AreEqual("Alice - I love the weather today (5 minutes ago)", response4[3]); }
private static void Main(string[] args) { var userRepository = new UserRepository(name => new User(name)); var commandHandler = new InputTerminal(userRepository, new HandlerFactory(userRepository)); Console.WriteLine("Social Network"); Console.WriteLine(); while (true) { Console.Write("> "); var input = Console.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { break; } var output = commandHandler.Handle(input); foreach (var line in output) { Console.WriteLine(line); } } }