Пример #1
0
        public void SetHandlerSuccessor_WhenSetSuccessorIsCalled()
        {
            var concreteHandlerOne = new ConcreteHandlerOne();
            var concreteHandlerTwo = new ConcreteHandlerTwo();

            concreteHandlerOne.SetSuccessor(concreteHandlerTwo);

            concreteHandlerOne.Successor.Should().Be(concreteHandlerTwo);
        }
Пример #2
0
        public void ReturnMinusOneIfSuccessorIsNotSet_WhenHandleRequestIsCalled()
        {
            var requestType = 3;
            var expectedConcreteHandlerNumber = -1;
            var concreteHandlerTwo            = new ConcreteHandlerTwo();

            var handledBy = concreteHandlerTwo.Handle(requestType);

            handledBy.Should().Be(expectedConcreteHandlerNumber);
        }
Пример #3
0
        private static void ChainOfResponsibilityExample()
        {
            var handlerOne = new ConcreteHandlerOne();
            var handlerTwo = new ConcreteHandlerTwo();

            handlerOne.SetSuccessor(handlerTwo);
            handlerTwo.SetSuccessor(handlerOne);

            handlerOne.HandleRequest("PrintDate");
            handlerOne.HandleRequest("PrintGreeting");
        }
Пример #4
0
        public void ReturnTwoForRequestsOfTypeTwo_WhenHandleRequestIsCalled()
        {
            var requestType = 2;
            var expectedConcreteHandlerNumber = 2;
            var concreteHandlerOne            = new ConcreteHandlerOne();
            var concreteHandlerTwo            = new ConcreteHandlerTwo();

            concreteHandlerOne.SetSuccessor(concreteHandlerTwo);

            var handledBy = concreteHandlerOne.Handle(requestType);

            handledBy.Should().Be(expectedConcreteHandlerNumber);
        }
Пример #5
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);
        }
Пример #6
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();
    }