public void GIVEN_a_RegisteredService_message_WHEN_listened_THEN_the_aggregate_is_saved_in_the_repository()
        {
            var dependencies = new MessageHandlerDependenciesHolder<SessionAggregate>();
            var aggregate = GenerateRandomAggregate();
            var handlersConfig = new List<MessageHandlerConfiguration>();
            handlersConfig.Add(new MessageHandlerConfigurationFake("SessionMessageHandler", new List<ESynchroSystem>() { ESynchroSystem.PortalPaciente }));
            dependencies.HostConfiguration.MessagesHandlers.Returns(handlersConfig);
            dependencies.MessageDecrypter.Decrypt<SessionAggregate>(Arg.Any<NotNullable<BaseEvent>>()).Returns(aggregate);
            var sut = new SessionMessageHandler(
                                dependencies.RepositoryFactory,
                                dependencies.MessageDecrypter,
                                dependencies.HostConfiguration,
                                dependencies.HostServiceEvents);

            var message = TestsHelpers.GenerateRandomMessage("FinisedEvaSession");
            dependencies.HostServiceEvents.AddIncommingEvent(message);
            dependencies.Repository.Received(1).Save(aggregate);
        }
        public void GIVEN_no_configuration_is_provided_WHEN_listened_a_message_THEN_it_does_nothing()
        {
            var dependencies = new MessageHandlerDependenciesHolder<SessionAggregate>();
            var aggregate = GenerateRandomAggregate();
            var handlersConfig = new List<MessageHandlerConfiguration>();
            handlersConfig.Add(new MessageHandlerConfigurationFake("SessionMessageHandler", null));
            dependencies.HostConfiguration.MessagesHandlers.Returns(handlersConfig);
            dependencies.MessageDecrypter.Decrypt<SessionAggregate>(Arg.Any<NotNullable<BaseEvent>>()).Returns(aggregate);
            var sut = new SessionMessageHandler(
                                dependencies.RepositoryFactory,
                                dependencies.MessageDecrypter,
                                dependencies.HostConfiguration,
                                dependencies.HostServiceEvents);

            var message = TestsHelpers.GenerateRandomMessage("FinisedEvaSession");
            dependencies.HostServiceEvents.AddIncommingEvent(message);
            dependencies.Repository.DidNotReceive().Save(Arg.Any<SessionAggregate>());
        }
 static SessionControlProtocol_1_1()
 {
     FAST_ALERT_TEMPLATE = new MessageTemplate("Alert", new Field[] { new Scalar("Severity", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("Code", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("Value", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, true), new Scalar("Description", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false) });
     FAST_HELLO_TEMPLATE = new MessageTemplate("Hello", new Field[] { new Scalar("SenderName", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("VendorId", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, true) });
     RESET = new RESETMessage(FAST_RESET_TEMPLATE);
     {
         FAST_RESET_TEMPLATE.AddAttribute(RESET_PROPERTY, "yes");
     }
     RESET_HANDLER       = new RESETMessageHandler();
     ALERT_HANDLER       = new ALERTSessionMessageHandler();
     ATTRIBUTE           = new MessageTemplate(new QName("Attribute", NAMESPACE), new[] { dict("Ns", true, "template"), unicode("Name"), unicode("Value") });
     ELEMENT             = new MessageTemplate(new QName("Element", NAMESPACE), new[] { dict("Ns", true, "template"), unicode("Name"), new Sequence(qualify("Attributes"), new Field[] { new StaticTemplateReference(ATTRIBUTE) }, false), new Sequence(qualify("Content"), new Field[] { DynamicTemplateReference.INSTANCE }, false) });
     TEMPLATE_NAME       = new MessageTemplate(new QName("TemplateName", NAMESPACE), new Field[] { new Scalar(qualify("Ns"), Type.UNICODE, Operator.COPY, null, false), new Scalar(qualify("Name"), Type.UNICODE, Operator.NONE, null, false) });
     NS_NAME             = new MessageTemplate(new QName("NsName", NAMESPACE), new[] { dict("Ns", false, "template"), new Scalar(qualify("Name"), Type.UNICODE, Operator.NONE, null, false) });
     NS_NAME_WITH_AUX_ID = new MessageTemplate(new QName("NsNameWithAuxId", NAMESPACE), new Field[] { new StaticTemplateReference(NS_NAME), new Scalar(qualify("AuxId"), Type.UNICODE, Operator.NONE, null, true) });
     FIELD_BASE          = new MessageTemplate(new QName("PrimFieldBase", NAMESPACE), new Field[] { new StaticTemplateReference(NS_NAME_WITH_AUX_ID), new Scalar(qualify("Optional"), Type.U32, Operator.NONE, null, false), new StaticTemplateReference(OTHER) });
     PRIM_FIELD_BASE     = new MessageTemplate(new QName("PrimFieldBase", NAMESPACE), new Field[] { new StaticTemplateReference(FIELD_BASE), new Group(qualify("Operator"), new Field[] { DynamicTemplateReference.INSTANCE }, true) });
     INT32_INSTR         = new MessageTemplate(new QName("Int32Instr", NAMESPACE), new Field[] { new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.I32, Operator.NONE, null, true) });
     UINT32_INSTR        = new MessageTemplate(new QName("UInt32Instr", NAMESPACE), new Field[] { new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.U32, Operator.NONE, null, true) });
     INT64_INSTR         = new MessageTemplate(new QName("Int64Instr", NAMESPACE), new Field[] { new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.I64, Operator.NONE, null, true) });
     UINT64_INSTR        = new MessageTemplate(new QName("UInt64Instr", NAMESPACE), new Field[] { new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.U64, Operator.NONE, null, true) });
     DECIMAL_INSTR       = new MessageTemplate(new QName("DecimalInstr", NAMESPACE), new Field[] { new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.DECIMAL, Operator.NONE, null, true) });
     UNICODE_INSTR       = new MessageTemplate(new QName("UnicodeInstr", NAMESPACE), new Field[] { new StaticTemplateReference(PRIM_FIELD_BASE_WITH_LENGTH), new Scalar(qualify("InitialValue"), Type.UNICODE, Operator.NONE, null, true) });
     ASCII_INSTR         = new MessageTemplate(new QName("AsciiInstr", NAMESPACE), new Field[] { new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.ASCII, Operator.NONE, null, true) });
     BYTE_VECTOR_INSTR   = new MessageTemplate(new QName("ByteVectorInstr", NAMESPACE), new Field[] { new StaticTemplateReference(PRIM_FIELD_BASE_WITH_LENGTH), new Scalar(qualify("InitialValue"), Type.BYTE_VECTOR, Operator.NONE, null, true) });
     TEMPLATE_DEFINITION = new MessageTemplate(new QName("TemplateDef", NAMESPACE), new[] { new StaticTemplateReference(TEMPLATE_NAME), unicodeopt("AuxId"), u32opt("TemplateId"), new StaticTemplateReference(TYPE_REF), u32("Reset"), new StaticTemplateReference(OTHER), new Sequence(qualify("Instructions"), new Field[] { DynamicTemplateReference.INSTANCE }, false) });
     GROUP_INSTR         = new MessageTemplate(new QName("GroupInstr", NAMESPACE), new Field[] { new StaticTemplateReference(FIELD_BASE), new StaticTemplateReference(TYPE_REF), new Sequence(qualify("Instructions"), new Field[] { DynamicTemplateReference.INSTANCE }, false) });
     SEQUENCE_INSTR      = new MessageTemplate(new QName("SequenceInstr", NAMESPACE), new Field[] { new StaticTemplateReference(FIELD_BASE), new StaticTemplateReference(TYPE_REF), new Group(qualify("Length"), new Field[] { new Group(qualify("Name"), new Field[] { new StaticTemplateReference(NS_NAME_WITH_AUX_ID) }, true), new Group(qualify("Operator"), new Field[] { DynamicTemplateReference.INSTANCE }, true), new Scalar(qualify("InitialValue"), Type.U32, Operator.NONE, null, true), new StaticTemplateReference(OTHER) }, true), new Sequence(qualify("Instructions"), new Field[] { DynamicTemplateReference.INSTANCE }, false) });
     TEXT = new MessageTemplate(qualify("Text"), new Field[] { new Scalar(qualify("Value"), Type.UNICODE, Operator.NONE, ScalarValue.UNDEFINED, false) });
     COMP_DECIMAL_INSTR = new MessageTemplate(qualify("CompositeDecimalInstr"), new Field[] { new StaticTemplateReference(FIELD_BASE), new Group(qualify("Exponent"), new Field[] { new Group(qualify("Operator"), new Field[] { DynamicTemplateReference.INSTANCE }, false), new Scalar(qualify("InitialValue"), Type.I32, Operator.NONE, ScalarValue.UNDEFINED, true), new StaticTemplateReference(OTHER) }, true), new Group(qualify("Mantissa"), new Field[] { new Group(qualify("Operator"), new Field[] { DynamicTemplateReference.INSTANCE }, false), new Scalar(qualify("InitialValue"), Type.I32, Operator.NONE, ScalarValue.UNDEFINED, true), new StaticTemplateReference(OTHER) }, true) });
     {
         TEMPLATE_REGISTRY.Register(FAST_HELLO_TEMPLATE_ID, FAST_HELLO_TEMPLATE);
         TEMPLATE_REGISTRY.Register(FAST_ALERT_TEMPLATE_ID, FAST_ALERT_TEMPLATE);
         TEMPLATE_REGISTRY.Register(FAST_RESET_TEMPLATE_ID, FAST_RESET_TEMPLATE);
         TEMPLATE_REGISTRY.Register(TEMPLATE_DECL_ID, TEMPLATE_DECLARATION);
         TEMPLATE_REGISTRY.Register(TEMPLATE_DEF_ID, TEMPLATE_DEFINITION);
         TEMPLATE_REGISTRY.Register(INT32_INSTR_ID, INT32_INSTR);
         TEMPLATE_REGISTRY.Register(UINT32_INSTR_ID, UINT32_INSTR);
         TEMPLATE_REGISTRY.Register(INT64_INSTR_ID, INT64_INSTR);
         TEMPLATE_REGISTRY.Register(UINT64_INSTR_ID, UINT64_INSTR);
         TEMPLATE_REGISTRY.Register(DECIMAL_INSTR_ID, DECIMAL_INSTR);
         TEMPLATE_REGISTRY.Register(COMP_DECIMAL_INSTR_ID, COMP_DECIMAL_INSTR);
         TEMPLATE_REGISTRY.Register(ASCII_INSTR_ID, ASCII_INSTR);
         TEMPLATE_REGISTRY.Register(UNICODE_INSTR_ID, UNICODE_INSTR);
         TEMPLATE_REGISTRY.Register(BYTE_VECTOR_INSTR_ID, BYTE_VECTOR_INSTR);
         TEMPLATE_REGISTRY.Register(STAT_TEMP_REF_INSTR_ID, STAT_TEMP_REF_INSTR);
         TEMPLATE_REGISTRY.Register(DYN_TEMP_REF_INSTR_ID, DYN_TEMP_REF_INSTR);
         TEMPLATE_REGISTRY.Register(SEQUENCE_INSTR_ID, SEQUENCE_INSTR);
         TEMPLATE_REGISTRY.Register(GROUP_INSTR_ID, GROUP_INSTR);
         TEMPLATE_REGISTRY.Register(CONSTANT_OP_ID, CONSTANT_OP);
         TEMPLATE_REGISTRY.Register(DEFAULT_OP_ID, DEFAULT_OP);
         TEMPLATE_REGISTRY.Register(COPY_OP_ID, COPY_OP);
         TEMPLATE_REGISTRY.Register(INCREMENT_OP_ID, INCREMENT_OP);
         TEMPLATE_REGISTRY.Register(DELTA_OP_ID, DELTA_OP);
         TEMPLATE_REGISTRY.Register(TAIL_OP_ID, TAIL_OP);
         TEMPLATE_REGISTRY.Register(FOREIGN_INSTR_ID, FOREIGN_INSTR);
         TEMPLATE_REGISTRY.Register(ELEMENT_ID, ELEMENT);
         TEMPLATE_REGISTRY.Register(TEXT_ID, TEXT);
         MessageTemplate[] templates = TEMPLATE_REGISTRY.Templates;
         for (int i = 0; i < templates.Length; i++)
         {
             Namespace = templates[i];
         }
     }
 }
 static SessionControlProtocol_1_1()
 {
     FAST_ALERT_TEMPLATE = new MessageTemplate("Alert", new Field[]{new Scalar("Severity", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("Code", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("Value", Type.U32, Operator.NONE, ScalarValue.UNDEFINED, true), new Scalar("Description", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false)});
     FAST_HELLO_TEMPLATE = new MessageTemplate("Hello", new Field[]{new Scalar("SenderName", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, false), new Scalar("VendorId", Type.ASCII, Operator.NONE, ScalarValue.UNDEFINED, true)});
     RESET = new RESETMessage(FAST_RESET_TEMPLATE);
     {
         FAST_RESET_TEMPLATE.AddAttribute(RESET_PROPERTY, "yes");
     }
     RESET_HANDLER = new RESETMessageHandler();
     ALERT_HANDLER = new ALERTSessionMessageHandler();
     ATTRIBUTE = new MessageTemplate(new QName("Attribute", NAMESPACE), new[]{dict("Ns", true, "template"), unicode("Name"), unicode("Value")});
     ELEMENT = new MessageTemplate(new QName("Element", NAMESPACE), new[]{dict("Ns", true, "template"), unicode("Name"), new Sequence(qualify("Attributes"), new Field[]{new StaticTemplateReference(ATTRIBUTE)}, false), new Sequence(qualify("Content"), new Field[]{DynamicTemplateReference.INSTANCE}, false)});
     TEMPLATE_NAME = new MessageTemplate(new QName("TemplateName", NAMESPACE), new Field[]{new Scalar(qualify("Ns"), Type.UNICODE, Operator.COPY, null, false), new Scalar(qualify("Name"), Type.UNICODE, Operator.NONE, null, false)});
     NS_NAME = new MessageTemplate(new QName("NsName", NAMESPACE), new[]{dict("Ns", false, "template"), new Scalar(qualify("Name"), Type.UNICODE, Operator.NONE, null, false)});
     NS_NAME_WITH_AUX_ID = new MessageTemplate(new QName("NsNameWithAuxId", NAMESPACE), new Field[]{new StaticTemplateReference(NS_NAME), new Scalar(qualify("AuxId"), Type.UNICODE, Operator.NONE, null, true)});
     FIELD_BASE = new MessageTemplate(new QName("PrimFieldBase", NAMESPACE), new Field[]{new StaticTemplateReference(NS_NAME_WITH_AUX_ID), new Scalar(qualify("Optional"), Type.U32, Operator.NONE, null, false), new StaticTemplateReference(OTHER)});
     PRIM_FIELD_BASE = new MessageTemplate(new QName("PrimFieldBase", NAMESPACE), new Field[]{new StaticTemplateReference(FIELD_BASE), new Group(qualify("Operator"), new Field[]{DynamicTemplateReference.INSTANCE}, true)});
     INT32_INSTR = new MessageTemplate(new QName("Int32Instr", NAMESPACE), new Field[]{new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.I32, Operator.NONE, null, true)});
     UINT32_INSTR = new MessageTemplate(new QName("UInt32Instr", NAMESPACE), new Field[]{new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.U32, Operator.NONE, null, true)});
     INT64_INSTR = new MessageTemplate(new QName("Int64Instr", NAMESPACE), new Field[]{new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.I64, Operator.NONE, null, true)});
     UINT64_INSTR = new MessageTemplate(new QName("UInt64Instr", NAMESPACE), new Field[]{new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.U64, Operator.NONE, null, true)});
     DECIMAL_INSTR = new MessageTemplate(new QName("DecimalInstr", NAMESPACE), new Field[]{new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.DECIMAL, Operator.NONE, null, true)});
     UNICODE_INSTR = new MessageTemplate(new QName("UnicodeInstr", NAMESPACE), new Field[]{new StaticTemplateReference(PRIM_FIELD_BASE_WITH_LENGTH), new Scalar(qualify("InitialValue"), Type.UNICODE, Operator.NONE, null, true)});
     ASCII_INSTR = new MessageTemplate(new QName("AsciiInstr", NAMESPACE), new Field[]{new StaticTemplateReference(PRIM_FIELD_BASE), new Scalar(qualify("InitialValue"), Type.ASCII, Operator.NONE, null, true)});
     BYTE_VECTOR_INSTR = new MessageTemplate(new QName("ByteVectorInstr", NAMESPACE), new Field[]{new StaticTemplateReference(PRIM_FIELD_BASE_WITH_LENGTH), new Scalar(qualify("InitialValue"), Type.BYTE_VECTOR, Operator.NONE, null, true)});
     TEMPLATE_DEFINITION = new MessageTemplate(new QName("TemplateDef", NAMESPACE), new[]{new StaticTemplateReference(TEMPLATE_NAME), unicodeopt("AuxId"), u32opt("TemplateId"), new StaticTemplateReference(TYPE_REF), u32("Reset"), new StaticTemplateReference(OTHER), new Sequence(qualify("Instructions"), new Field[]{DynamicTemplateReference.INSTANCE}, false)});
     GROUP_INSTR = new MessageTemplate(new QName("GroupInstr", NAMESPACE), new Field[]{new StaticTemplateReference(FIELD_BASE), new StaticTemplateReference(TYPE_REF), new Sequence(qualify("Instructions"), new Field[]{DynamicTemplateReference.INSTANCE}, false)});
     SEQUENCE_INSTR = new MessageTemplate(new QName("SequenceInstr", NAMESPACE), new Field[]{new StaticTemplateReference(FIELD_BASE), new StaticTemplateReference(TYPE_REF), new Group(qualify("Length"), new Field[]{new Group(qualify("Name"), new Field[]{new StaticTemplateReference(NS_NAME_WITH_AUX_ID)}, true), new Group(qualify("Operator"), new Field[]{DynamicTemplateReference.INSTANCE}, true), new Scalar(qualify("InitialValue"), Type.U32, Operator.NONE, null, true), new StaticTemplateReference(OTHER)}, true), new Sequence(qualify("Instructions"), new Field[]{DynamicTemplateReference.INSTANCE}, false)});
     TEXT = new MessageTemplate(qualify("Text"), new Field[]{new Scalar(qualify("Value"), Type.UNICODE, Operator.NONE, ScalarValue.UNDEFINED, false)});
     COMP_DECIMAL_INSTR = new MessageTemplate(qualify("CompositeDecimalInstr"), new Field[]{new StaticTemplateReference(FIELD_BASE), new Group(qualify("Exponent"), new Field[]{new Group(qualify("Operator"), new Field[]{DynamicTemplateReference.INSTANCE}, false), new Scalar(qualify("InitialValue"), Type.I32, Operator.NONE, ScalarValue.UNDEFINED, true), new StaticTemplateReference(OTHER)}, true), new Group(qualify("Mantissa"), new Field[]{new Group(qualify("Operator"), new Field[]{DynamicTemplateReference.INSTANCE}, false), new Scalar(qualify("InitialValue"), Type.I32, Operator.NONE, ScalarValue.UNDEFINED, true), new StaticTemplateReference(OTHER)}, true)});
     {
         TEMPLATE_REGISTRY.Register(FAST_HELLO_TEMPLATE_ID, FAST_HELLO_TEMPLATE);
         TEMPLATE_REGISTRY.Register(FAST_ALERT_TEMPLATE_ID, FAST_ALERT_TEMPLATE);
         TEMPLATE_REGISTRY.Register(FAST_RESET_TEMPLATE_ID, FAST_RESET_TEMPLATE);
         TEMPLATE_REGISTRY.Register(TEMPLATE_DECL_ID, TEMPLATE_DECLARATION);
         TEMPLATE_REGISTRY.Register(TEMPLATE_DEF_ID, TEMPLATE_DEFINITION);
         TEMPLATE_REGISTRY.Register(INT32_INSTR_ID, INT32_INSTR);
         TEMPLATE_REGISTRY.Register(UINT32_INSTR_ID, UINT32_INSTR);
         TEMPLATE_REGISTRY.Register(INT64_INSTR_ID, INT64_INSTR);
         TEMPLATE_REGISTRY.Register(UINT64_INSTR_ID, UINT64_INSTR);
         TEMPLATE_REGISTRY.Register(DECIMAL_INSTR_ID, DECIMAL_INSTR);
         TEMPLATE_REGISTRY.Register(COMP_DECIMAL_INSTR_ID, COMP_DECIMAL_INSTR);
         TEMPLATE_REGISTRY.Register(ASCII_INSTR_ID, ASCII_INSTR);
         TEMPLATE_REGISTRY.Register(UNICODE_INSTR_ID, UNICODE_INSTR);
         TEMPLATE_REGISTRY.Register(BYTE_VECTOR_INSTR_ID, BYTE_VECTOR_INSTR);
         TEMPLATE_REGISTRY.Register(STAT_TEMP_REF_INSTR_ID, STAT_TEMP_REF_INSTR);
         TEMPLATE_REGISTRY.Register(DYN_TEMP_REF_INSTR_ID, DYN_TEMP_REF_INSTR);
         TEMPLATE_REGISTRY.Register(SEQUENCE_INSTR_ID, SEQUENCE_INSTR);
         TEMPLATE_REGISTRY.Register(GROUP_INSTR_ID, GROUP_INSTR);
         TEMPLATE_REGISTRY.Register(CONSTANT_OP_ID, CONSTANT_OP);
         TEMPLATE_REGISTRY.Register(DEFAULT_OP_ID, DEFAULT_OP);
         TEMPLATE_REGISTRY.Register(COPY_OP_ID, COPY_OP);
         TEMPLATE_REGISTRY.Register(INCREMENT_OP_ID, INCREMENT_OP);
         TEMPLATE_REGISTRY.Register(DELTA_OP_ID, DELTA_OP);
         TEMPLATE_REGISTRY.Register(TAIL_OP_ID, TAIL_OP);
         TEMPLATE_REGISTRY.Register(FOREIGN_INSTR_ID, FOREIGN_INSTR);
         TEMPLATE_REGISTRY.Register(ELEMENT_ID, ELEMENT);
         TEMPLATE_REGISTRY.Register(TEXT_ID, TEXT);
         MessageTemplate[] templates = TEMPLATE_REGISTRY.Templates;
         for (int i = 0; i < templates.Length; i++)
         {
             Namespace = templates[i];
         }
     }
 }