protected Logger()
        {
            _disablers = new Stack <object>();

            _handlers = ChainOfResponsibility.Empty <LogEntry>()
                        .Chain(new LogEntryLink <TaskLog>(Insert, Update))
                        .Chain(new LogEntryLink <StepLog>(Insert, Update))
                        .Chain(new LogEntryLink <MessageLog>(Insert));
        }
        public void Handle_ContextNotHandled_AllAskedNoneHandled()
        {
            ChainOfResponsibilityLink <int, string> first, second, third;
            ChainOfResponsibilityLink <int, string> chain = initChainOfSubstitutes(out first, out second, out third);

            Assert.That(chain.Handle(1), Is.Null);

            first.Received().CanHandle(1);
            second.Received().CanHandle(1);
            third.Received().CanHandle(1);
        }
        public void Handle_ContextNotHandled_AllAskedNoneHandled()
        {
            ChainOfResponsibilityLink <string> first, second, third;
            ChainOfResponsibilityLink <string> chain = initChainOfSubstitutes(out first, out second, out third);

            chain.Handle("str");

            first.Received().CanHandle("str");
            second.Received().CanHandle("str");
            third.Received().CanHandle("str");
        }
        public void Handle_ContextHandled_ReturnValueComesFromHandler()
        {
            string returnValue = "handled by second";

            ChainOfResponsibilityLink <int, string> first, second, third;
            ChainOfResponsibilityLink <int, string> chain = initChainOfSubstitutes(out first, out second, out third);

            second.CanHandle(1).Returns(true);
            second.Handle(1).Returns(returnValue);

            Assert.That(chain.Handle(1), Is.EqualTo(returnValue));
        }
        public void Handle_ContextHandledByLastInChain_AllAskedAndLastHandles()
        {
            ChainOfResponsibilityLink <int, string> first, second, third;
            ChainOfResponsibilityLink <int, string> chain = initChainOfSubstitutes(out first, out second, out third);

            third.CanHandle(1).Returns(true);

            chain.Handle(1);

            first.Received().CanHandle(1);
            second.Received().CanHandle(1);
        }
        public void Handle_ContextHandledBySecondInChain_FirstAskedAndThirdNot()
        {
            ChainOfResponsibilityLink <int, string> first, second, third;
            ChainOfResponsibilityLink <int, string> chain = initChainOfSubstitutes(out first, out second, out third);

            second.CanHandle(1).Returns(true);

            chain.Handle(1);

            first.Received().CanHandle(1);
            third.DidNotReceiveWithAnyArgs().CanHandle(0);
        }
        public void TryHandle_ContextHandledByLastInChain_AllAskedAndLastHandles()
        {
            ChainOfResponsibilityLink <string> first, second, third;
            ChainOfResponsibilityLink <string> chain = initChainOfSubstitutes(out first, out second, out third);

            third.CanHandle("str").Returns(true);

            Assert.That(chain.TryHandle("str"), Is.True);

            first.Received().CanHandle("str");
            second.Received().CanHandle("str");
        }
        public void TryHandle_ContextHandledBySecondInChain_FirstAskedAndThirdNot()
        {
            ChainOfResponsibilityLink <string> first, second, third;
            ChainOfResponsibilityLink <string> chain = initChainOfSubstitutes(out first, out second, out third);

            second.CanHandle("str").Returns(true);

            Assert.That(chain.TryHandle("str"), Is.True);

            first.Received().CanHandle("str");
            third.DidNotReceiveWithAnyArgs().CanHandle(null);
        }
        public void Handle_ContextHandledByFirstInChain_RestOfMembersNotEvenAsked()
        {
            ChainOfResponsibilityLink <string> first, second, third;
            ChainOfResponsibilityLink <string> chain = initChainOfSubstitutes(out first, out second, out third);

            first.CanHandle("str").Returns(true);

            chain.Handle("str");

            second.DidNotReceiveWithAnyArgs().CanHandle(null);
            third.DidNotReceiveWithAnyArgs().CanHandle(null);
        }
Beispiel #10
0
        protected Logger()
        {
            this._disablers = new Stack <object>();
            ChainOfResponsibilityLink <LogEntry> chainOfResponsibilityLink = ChainOfResponsibility.Empty <LogEntry>();
            Logger logger  = this;
            Logger logger1 = this;
            ChainOfResponsibilityLink <LogEntry> chainOfResponsibilityLink1 = chainOfResponsibilityLink.Chain(new Logger.LogEntryLink <TaskLog>(new Func <TaskLog, string>(logger.Insert), new Action <TaskLog>(logger1.Update)));
            Logger logger2 = this;
            Logger logger3 = this;
            Logger logger4 = this;

            this._handlers = chainOfResponsibilityLink1.Chain(new Logger.LogEntryLink <StepLog>(new Func <StepLog, string>(logger2.Insert), new Action <StepLog>(logger3.Update))).Chain(new Logger.LogEntryLink <MessageLog>(new Func <MessageLog, string>(logger4.Insert), null));
        }
        public void TryHandle_ContextHandledByFirstInChain_RestOfMembersNotEvenAsked()
        {
            ChainOfResponsibilityLink <int, string> first, second, third;
            ChainOfResponsibilityLink <int, string> chain = initChainOfSubstitutes(out first, out second, out third);

            first.CanHandle(1).Returns(true);

            string result;

            chain.TryHandle(1, out result);

            second.DidNotReceiveWithAnyArgs().CanHandle(0);
            third.DidNotReceiveWithAnyArgs().CanHandle(0);
        }
        private ChainOfResponsibilityLink <int, string> initChainOfSubstitutes(
            out ChainOfResponsibilityLink <int, string> first,
            out ChainOfResponsibilityLink <int, string> second,
            out ChainOfResponsibilityLink <int, string> third
            )
        {
            first  = Substitute.For <ChainOfResponsibilityLink <int, string> >();
            second = Substitute.For <ChainOfResponsibilityLink <int, string> >();
            third  = Substitute.For <ChainOfResponsibilityLink <int, string> >();

            var chain = ChainOfResponsibility
                        .Empty <int, string>()
                        .Chain(first)
                        .Chain(second)
                        .Chain(third);

            return(chain);
        }
        public MonitorWorkItem(MonitorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            DateTimeOffset utcNow = Time.UtcNow;

            if (configuration.LastRun > utcNow)
            {
                utcNow = configuration.LastRun;
            }
            this._checkRange      = new Range <DateTimeOffset>(configuration.LastRun, utcNow);
            this._entries         = new List <Tuple <Target, MonitorEntry> >();
            this._ignore          = new List <ISpecification <MonitorEntry> >();
            this._redirects       = ChainOfResponsibility.Empty <MonitorEntry, Target[]>();
            this._messageGrouping = new List <Regex>();
            this.Configuration    = configuration;
        }
        public void FluentChain_LinkingTwo_InnerChaining()
        {
            var l1 = new IToUpperIfStartsWith("1");
            var l2 = new IToUpperIfStartsWith("2");

            ChainOfResponsibilityLink <Context> chain = ChainOfResponsibility
                                                        .Empty <Context>()
                                                        .Chain(l1)
                                                        .Chain(l2);

            //Assert.That(chain, Is.SameAs(l2));

            //Assert.That(l1.Next, Is.SameAs(l2));
            //Assert.That(l2.Next, Is.Null);
            var ctx = new Context("2a");

            chain.Handle(ctx);
            Assert.That(ctx.S, Is.EqualTo("2A"));
        }
Beispiel #15
0
        public MonitorWorkItem(MonitorConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            DateTimeOffset upperBound = Time.UtcNow;

            if (configuration.LastRun > upperBound)
            {
                upperBound = configuration.LastRun;
            }

            CheckRange       = new Range <DateTimeOffset>(configuration.LastRun, upperBound);
            _entries         = new List <Tuple <Target, MonitorEntry> >();
            _ignore          = new List <ISpecification <MonitorEntry> >();
            _redirects       = ChainOfResponsibility.Empty <MonitorEntry, Target[]>();
            _messageGrouping = new List <Regex>();

            Configuration = configuration;
        }