public void SetRequestHeader(
            HealthVaultMethods method,
            int methodVersion,
            bool isAnonymous,
            Guid?recordId,
            Guid?appId,
            string infoXml,
            Request request)
        {
            request.Header = new RequestHeader
            {
                Method        = method.ToString(),
                MethodVersion = methodVersion
            };

            if (recordId != null)
            {
                request.Header.RecordId = recordId.Value.ToString();
            }

            // in case the method is anonymous - set app id, else set auth session
            if (isAnonymous)
            {
                request.Header.AppId = appId.HasValue
                    ? appId.Value.ToString()
                    : _healthVaultConfiguration.MasterApplicationId.ToString();
            }
            else
            {
                request.Header.AuthSession = _connectionInternal.GetAuthSessionHeader();
            }

            request.Header.MessageTime = SDKHelper.XmlFromNow();
            request.Header.MessageTtl  = (int)_healthVaultConfiguration.RequestTimeToLiveDuration.TotalSeconds;

            request.Header.Version =
                $"{_telemetryInformation.Category}/{_telemetryInformation.FileVersion} {_telemetryInformation.OsInformation}";

            request.Header.InfoHash = new InfoHash
            {
                HashData = _cryptographer.Hash(Encoding.UTF8.GetBytes(infoXml))
            };
        }
        public void InitializeTest()
        {
            _connection     = Substitute.For <IConnectionInternal>();
            _serviceLocator = Substitute.For <IServiceLocator>();

            _serviceLocator.GetInstance <HealthVaultConfiguration>()
            .Returns(new HealthVaultConfiguration
            {
                MasterApplicationId       = Guid.NewGuid(),
                RequestTimeToLiveDuration = new TimeSpan(hours: 0, minutes: 1, seconds: 5)
            });

            _serviceLocator.GetInstance <SdkTelemetryInformation>()
            .Returns(
                new SdkTelemetryInformation()
            {
                Category = "test", FileVersion = "test", OsInformation = "test"
            });

            ICryptographer mockCryptographer = Substitute.For <ICryptographer>();
            CryptoData     mockCryptoData    = new CryptoData()
            {
                Algorithm = "some", Value = "some"
            };

            mockCryptographer.Hmac(Arg.Any <string>(), Arg.Any <byte[]>())
            .Returns(mockCryptoData);

            mockCryptographer.Hash(Arg.Any <byte[]>())
            .Returns(mockCryptoData);

            _serviceLocator.GetInstance <ICryptographer>().Returns(mockCryptographer);

            _connection.SessionCredential.Returns(
                new SessionCredential()
            {
                SharedSecret = "someSharedSecret", Token = "someToken"
            });
        }
 public Hash Hash(ICryptographer cryptographer)
 {
     return(cryptographer.Hash(this.ToXml()));
 }
 public Hash Hash(ICryptographer cryptographer)
 {
     return cryptographer.Hash(this.ToXml());
 }