public void Default()
            {
                var injector = new MockInjector();
                var factory = injector.Create<SecurityHeaderFactory>();

                var security = new Security { Timestamp = new Timestamp { Created = "2012-11-07T01:41:35.821Z" } };

                var requestMessage = Message.CreateMessage(MessageVersion.Default, "moo");
                MessageHeader securityHeader = MessageHeader.CreateHeader("Security",
                                        "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                                        security,
                                        new CfMessagingSerializer(typeof(Security)));
                requestMessage.Headers.Add(securityHeader);
                var header = factory.CreateWithoutUserToken(requestMessage);

                header.Name.Should().Be("Security");
                header.Namespace.Should().Be("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

                string expectedXml =
                @"<Security xmlns=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
                  <Timestamp xmlns=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">
                <Created>2012-11-07T01:41:35.821Z</Created>
                  </Timestamp>
                </Security>";
                header.ToString().Should().Be(expectedXml);
            }
 MessageHeader CreateHeader(Security security)
 {
     return MessageHeader.CreateHeader(
         "Security",
         "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
         security,
         new CfMessagingSerializer(typeof(Security)));
 }
 public MessageHeader CreateWithoutUserToken(Message request)
 {
     var securityIndex = request.Headers.FindHeader("Security",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
     if (securityIndex >= 0)
     {
         var serializer = new XmlSerializer(typeof(Security));
         var requestSecurity = (Security)serializer.Deserialize(new StringReader(request.Headers[securityIndex].ToString()));
         var security = new Security
         {
             Timestamp = requestSecurity.Timestamp
         };
         return CreateHeader(security);
     }
     return null;
 }
        public MessageHeader Create()
        {
            var nonce = new byte[64];
            randomNumberGeneratorProvider.GetBytes(nonce);

            var security = new Security(
                endpointProvider.Username,
                endpointProvider.Password,
                dateTimeProvider.Now,
                nonce);

            return CreateHeader(security);
        }