Microsoft.WindowsAzure.MediaServices.Client.Tests.MediaServicesCredentialsTest.MediaServicesCredentialsTestReuseInvalidTokenBytes C# (CSharp) Method

MediaServicesCredentialsTestReuseInvalidTokenBytes() private method

        public void MediaServicesCredentialsTestReuseInvalidTokenBytes()
        {
            // Get the current time plus two hours and then remove the milliseconds component
            // since the encoded expiry is represented in seconds
            DateTime timeToEncode = DateTime.UtcNow.AddSeconds(5999);
            timeToEncode = timeToEncode.Subtract(TimeSpan.FromMilliseconds(timeToEncode.Millisecond));

            var context1 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext();
            MakeRestCallAndVerifyToken(context1);
            MediaServicesCredentials credentials = context1.Credentials;

            StringBuilder builder = new StringBuilder();
            builder.Append("{\"token_type\":\"http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0\",\"access_token\":\"http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=mediacreator&urn%3aSubscriptionId=3c5e503f-adcb-4aa5-a549-f34931566d6c&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=");
            builder.Append(EncodeExpiry(timeToEncode));
            builder.Append("&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=8RMeaHPfHHWAqlDSAvg0YDOpYhzjBGAsKZMMNeAwLsE%3d\",\"expires_in\":\"5999\",\"scope\":\"urn:WindowsAzureMediaServices\"}");
            string badAcsResponse = builder.ToString();
            byte[] acsResponse = new UTF8Encoding().GetBytes(badAcsResponse);
            credentials.SetAcsToken(acsResponse);

            Assert.AreEqual(timeToEncode.ToString(), credentials.TokenExpiration.ToString());

            try
            {
                var context2 = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(credentials);
                MakeRestCallAndVerifyToken(context2);
            }
            catch (DataServiceQueryException x)
            {
                var code = x.Response.StatusCode;
                Assert.AreEqual((int)HttpStatusCode.Unauthorized, code);
                throw;
            }
        }