示例#1
0
        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);
                }
            }
        }
        private bool TryGetHelpFromInputTerminal(InputTerminal inputTerminal, out HelpAttribute help)
        {
            var        nodeType           = Node?.GetType();
            MemberInfo terminalMemberInfo = nodeType?.GetMethod(inputTerminal.Name);

            if (terminalMemberInfo == null)
            {
                terminalMemberInfo = nodeType?.GetProperty(inputTerminal.Name);
            }
            help = terminalMemberInfo?.GetCustomAttributes(typeof(HelpAttribute), true)?.FirstOrDefault() as HelpAttribute;
            return(help is object);
        }
示例#3
0
        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]);
        }
示例#4
0
 public TwoInOneOut()
 {
     this.PinA = new InputTerminal();
     this.PinB = new InputTerminal();
 }
示例#5
0
 internal TwoInOneOut(InputTerminal PinA, InputTerminal PinB)
 {
     this.PinA = PinA;
     this.PinB = PinB;
 }
示例#6
0
 public ThreeInTwoOut()
 {
     this.PinA = new InputTerminal();
     this.PinB = new InputTerminal();
     this.PinC = new InputTerminal();
 }
示例#7
0
 internal ThreeInTwoOut(InputTerminal PinA, InputTerminal PinB, InputTerminal PinC)
 {
     this.PinA = PinA;
     this.PinB = PinB;
     this.PinC = PinB;
 }
示例#8
0
 public void SetUp()
 {
     userRepository = new Mock <IUserRepository>();
     handlerFactory = new Mock <IHandlerFactory>();
     sut            = new InputTerminal(userRepository.Object, handlerFactory.Object);
 }
示例#9
0
 public XorGate(InputTerminal PinA, InputTerminal PinB) : base(PinA, PinB) 
 {
     this.CreateInternals();
     this.WireInternals();
 }
示例#10
0
 public HalfAdder(InputTerminal PinA, InputTerminal PinB) : base(PinA, PinB)
 {
     this.CreateInternals();
 }
示例#11
0
 public AndGate(InputTerminal PinA, InputTerminal PinB) : base(PinA, PinB) { }