public void RoundTripTest()
        {
            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();

            responseTemplate.ResponseCustomData = "This is my response custom data";
            PlayReadyLicenseTemplate licenseTemplate = new PlayReadyLicenseTemplate();

            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            licenseTemplate.LicenseType    = PlayReadyLicenseType.Persistent;
            licenseTemplate.BeginDate      = DateTime.Now.AddHours(-1);
            licenseTemplate.ExpirationDate = DateTime.Now.AddDays(30).ToUniversalTime();

            licenseTemplate.PlayRight.CompressedDigitalAudioOpl   = 300;
            licenseTemplate.PlayRight.CompressedDigitalVideoOpl   = 400;
            licenseTemplate.PlayRight.UncompressedDigitalAudioOpl = 250;
            licenseTemplate.PlayRight.UncompressedDigitalVideoOpl = 270;
            licenseTemplate.PlayRight.AnalogVideoOpl = 100;
            licenseTemplate.PlayRight.AgcAndColorStripeRestriction                       = new AgcAndColorStripeRestriction(1);
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput            = UnknownOutputPassingOption.Allowed;
            licenseTemplate.PlayRight.ExplicitAnalogTelevisionOutputRestriction          = new ExplicitAnalogTelevisionRestriction(0, true);
            licenseTemplate.PlayRight.ImageConstraintForAnalogComponentVideoRestriction  = true;
            licenseTemplate.PlayRight.ImageConstraintForAnalogComputerMonitorRestriction = true;
            licenseTemplate.PlayRight.ScmsRestriction = new ScmsRestriction(2);

            string serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);

            Assert.IsFalse(String.IsNullOrWhiteSpace(serializedTemplate));

            PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate);

            Assert.IsNotNull(responseTemplate2);
        }
        public void KnownGoodInputMinimalLicenseTest()
        {
            string serializedTemplate = "<PlayReadyLicenseResponseTemplate xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/PlayReadyTemplate/v1\"><LicenseTemplates><PlayReadyLicenseTemplate><ContentKey i:type=\"ContentEncryptionKeyFromHeader\" /><PlayRight /></PlayReadyLicenseTemplate></LicenseTemplates></PlayReadyLicenseResponseTemplate>";

            PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate);

            Assert.IsNotNull(responseTemplate2);
        }
        public void KnownGoodInputTest()
        {
            string serializedTemplate = "<PlayReadyLicenseResponseTemplate xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/PlayReadyTemplate/v1\"><LicenseTemplates><PlayReadyLicenseTemplate><AllowTestDevices>false</AllowTestDevices><BeginDate i:nil=\"true\" /><ContentKey i:type=\"ContentEncryptionKeyFromHeader\" /><ContentType>Unspecified</ContentType><ExpirationDate i:nil=\"true\" /><LicenseType>Nonpersistent</LicenseType><PlayRight><AgcAndColorStripeRestriction><ConfigurationData>1</ConfigurationData></AgcAndColorStripeRestriction><AllowPassingVideoContentToUnknownOutput>Allowed</AllowPassingVideoContentToUnknownOutput><AnalogVideoOpl>100</AnalogVideoOpl><CompressedDigitalAudioOpl>300</CompressedDigitalAudioOpl><CompressedDigitalVideoOpl>400</CompressedDigitalVideoOpl><DigitalVideoOnlyContentRestriction>false</DigitalVideoOnlyContentRestriction><ExplicitAnalogTelevisionOutputRestriction><BestEffort>true</BestEffort><ConfigurationData>0</ConfigurationData></ExplicitAnalogTelevisionOutputRestriction><ImageConstraintForAnalogComponentVideoRestriction>true</ImageConstraintForAnalogComponentVideoRestriction><ImageConstraintForAnalogComputerMonitorRestriction>true</ImageConstraintForAnalogComputerMonitorRestriction><ScmsRestriction><ConfigurationData>2</ConfigurationData></ScmsRestriction><UncompressedDigitalAudioOpl>250</UncompressedDigitalAudioOpl><UncompressedDigitalVideoOpl>270</UncompressedDigitalVideoOpl></PlayRight></PlayReadyLicenseTemplate></LicenseTemplates><ResponseCustomData>This is my response custom data</ResponseCustomData></PlayReadyLicenseResponseTemplate>";

            PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate);

            Assert.IsNotNull(responseTemplate2);
        }
        public void InputMissingLicenseTemplatesShouldThrowArgumentException()
        {
            string serializedTemplate = "<PlayReadyLicenseResponseTemplate xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/PlayReadyTemplate/v1\"><LicenseTemplates></LicenseTemplates></PlayReadyLicenseResponseTemplate>";

            try
            {
                PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate);
                Assert.Fail("Should throw an ArgumentException");
            }
            catch (ArgumentException e)
            {
                Assert.IsTrue(e.Message.Contains(ErrorMessages.AtLeastOneLicenseTemplateRequired));
            }
        }
        public void InputMissingContentKeyShouldThrowArgumentException()
        {
            string serializedTemplate = "<PlayReadyLicenseResponseTemplate xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/PlayReadyTemplate/v1\"><LicenseTemplates><PlayReadyLicenseTemplate><PlayRight /></PlayReadyLicenseTemplate></LicenseTemplates></PlayReadyLicenseResponseTemplate>";

            try
            {
                PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate);
                Assert.Fail("Should throw an ArgumentException");
            }
            catch (SerializationException e)
            {
                e.Message.Contains("ContentKey");
            }
        }
        public void DigitalVideoOnlyContentRestrictionAndAllowPassingVideoContentToUnknownOutputMutuallyExclusive()
        {
            string serializedTemplate = null;
            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
            PlayReadyLicenseTemplate         licenseTemplate  = new PlayReadyLicenseTemplate();

            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            // Part 1: Make sure we cannot set DigitalVideoOnlyContentRestriction to true if
            //         UnknownOutputPassingOption.Allowed is set
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.Allowed;
            licenseTemplate.PlayRight.DigitalVideoOnlyContentRestriction      = true;

            try
            {
                serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual(ErrorMessages.DigitalVideoOnlyMutuallyExclusiveWithPassingToUnknownOutputError, ae.Message);
            }

            // Part 2: Make sure we cannot set UnknownOutputPassingOption.AllowedWithVideoConstriction
            //         if DigitalVideoOnlyContentRestriction is true
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.AllowedWithVideoConstriction;

            try
            {
                serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual(ErrorMessages.DigitalVideoOnlyMutuallyExclusiveWithPassingToUnknownOutputError, ae.Message);
            }

            // Part 3: Make sure we can set DigitalVideoOnlyContentRestriction to true if
            //         UnknownOutputPassingOption.NotAllowed is set
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.NotAllowed;
            licenseTemplate.PlayRight.DigitalVideoOnlyContentRestriction      = true;

            serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
            Assert.IsNotNull(serializedTemplate);

            Assert.IsNotNull(MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate));
        }