public void Serialize()
        {
            var component = new PolicyRunner();
            var builder   = new StringBuilder();

            using (var writer = XmlWriter.Create(builder, new XmlWriterSettings {
                OmitXmlDeclaration = true
            }))
            {
                component.Serialize(writer);
            }
            Assert.That(
                builder.ToString(),
                Is.EqualTo(
                    string.Format(
                        "<mComponent name=\"{0}\"><ExecutionMode>Immediate</ExecutionMode><Policy /></mComponent>",
                        component.GetType().AssemblyQualifiedName)));
        }
        public void DoesNothingWhenNoPolicy()
        {
            using (var dataStream = new MemoryStream(Encoding.Unicode.GetBytes(new string('A', 512))))
            {
                MessageMock.Object.BodyPart.Data = dataStream;
                var policyMock = new Mock <IPolicy>();
                Policy.Factory = ruleSetInfo => policyMock.Object;

                var sut = new PolicyRunner {
                    ExecutionMode = PluginExecutionMode.Immediate,
                };

                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
                policyMock.Verify(pc => pc.Execute(It.IsAny <object[]>()), Times.Never());

                MessageMock.Object.BodyPart.Data.Drain();
                policyMock.Verify(pc => pc.Execute(It.IsAny <object[]>()), Times.Never());
            }
        }
        public void PolicyExecutionIsDeferred()
        {
            using (var dataStream = new MemoryStream(Encoding.Unicode.GetBytes(new string('A', 512))))
            {
                MessageMock.Object.BodyPart.Data = dataStream;
                var policyMock = new Mock <IPolicy>();
                Policy.Factory = ruleSetInfo => policyMock.Object;

                var sut = new PolicyRunner {
                    ExecutionMode = PluginExecutionMode.Deferred,
                    PolicyName    = new PolicyName("name", 1, 0)
                };

                sut.Execute(PipelineContextMock.Object, MessageMock.Object);
                policyMock.Verify(pc => pc.Execute(It.IsAny <object[]>()), Times.Never());

                MessageMock.Object.BodyPart.Data.Drain();
                policyMock.Verify(pc => pc.Execute(It.IsAny <object[]>()), Times.Once());
            }
        }