Exemple #1
0
        public void SetHandlerSuccessor_WhenSetSuccessorIsCalled()
        {
            var concreteHandlerTwo   = new ConcreteHandlerTwo();
            var concreteHandlerThree = new ConcreteHandlerThree();

            concreteHandlerTwo.SetSuccessor(concreteHandlerThree);

            concreteHandlerTwo.Successor.Should().Be(concreteHandlerThree);
        }
Exemple #2
0
        public void ReturnThreeForRequestsOfTypeThree_WhenHandleRequestIsCalled()
        {
            var requestType = 3;
            var expectedConcreteHandlerNumber = 3;
            var concreteHandlerOne            = new ConcreteHandlerOne();
            var concreteHandlerTwo            = new ConcreteHandlerTwo();
            var concreteHandlerThree          = new ConcreteHandlerThree();

            concreteHandlerOne.SetSuccessor(concreteHandlerTwo);
            concreteHandlerTwo.SetSuccessor(concreteHandlerThree);

            var handledBy = concreteHandlerOne.Handle(requestType);

            handledBy.Should().Be(expectedConcreteHandlerNumber);
        }
Exemple #3
0
        public List <int> ProcessRequests(List <int> requestTypes)
        {
            var handlers             = new List <int>();
            var concreteHandlerOne   = new ConcreteHandlerOne();
            var concreteHandlerTwo   = new ConcreteHandlerTwo();
            var concreteHandlerThree = new ConcreteHandlerThree();

            concreteHandlerOne.SetSuccessor(concreteHandlerTwo);
            concreteHandlerTwo.SetSuccessor(concreteHandlerThree);

            foreach (var requestType in requestTypes)
            {
                handlers.Add(concreteHandlerOne.Handle(requestType));
            }

            return(handlers);
        }
Exemple #4
0
    static void Main(string[] args)
    {
        // Setup Chain of Responsibility
        Handler h1 = new ConcreteHandlerOne();
        Handler h2 = new ConcreteHandlerTwo();
        Handler h3 = new ConcreteHandlerThree();

        h1.setSuccessor(h2);
        h2.setSuccessor(h3);

        // Send requests to the chain
        h1.handleRequest(new Request("Negative Value", -1));
        h1.handleRequest(new Request("Zero Value", 0));
        h1.handleRequest(new Request("Positive Value", 1));
        h1.handleRequest(new Request("Positive Value", 2));
        h1.handleRequest(new Request("Negative Value", -5));

        Console.ReadKey();
    }
    static void Main(string[] args)
    {
        // Setup Chain of Responsibility
        Handler h1 = new ConcreteHandlerOne();
        Handler h2 = new ConcreteHandlerTwo();
        Handler h3 = new ConcreteHandlerThree();

        h1.setSuccessor(h2);
        h2.setSuccessor(h3);

        // Send requests to the chain
        h1.handleRequest(new Request("Negative Value", -1));
        h1.handleRequest(new Request("Zero Value", 0));
        h1.handleRequest(new Request("Positive Value", 1));
        h1.handleRequest(new Request("Positive Value", 2));
        h1.handleRequest(new Request("Negative Value", -5));

        Console.ReadKey();
    }