public async void MediaServicesLocatorDeleteTest() { string locName = "locator-123"; var amsV3SdkWrapper = Mock.Of <IMediaServicesV3SdkWrapper>(); var storageService = Mock.Of <IStorageService>(); var amsContentKeyPolService = Mock.Of <IMediaServicesV3ContentKeyPolicyService>(); var amsStreamingPolService = Mock.Of <IMediaServicesV3CustomStreamingPolicyService>(); var settingsProvider = Mock.Of <ISettingsProvider>(); // Arrange Mocks Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorDeleteAsync(locName, It.IsAny <CancellationToken>())); // Arrange Mocks Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorDeleteAsync(null, It.IsAny <CancellationToken>())) .ThrowsAsync(new Exception()); // Act var amsV3PubServices = new MediaServicesV3PublicationService(amsContentKeyPolService, amsStreamingPolService, amsV3SdkWrapper, storageService, settingsProvider, Log); // Assert var exception = await Record.ExceptionAsync(async() => await amsV3PubServices.LocatorDeleteAsync(locName, MediaServicesV3PublicationTestData.GoodOperationContext).ConfigureAwait(false)).ConfigureAwait(false); Xunit.Assert.Null(exception); // no exception if string are not null // exception is locator is null await Xunit.Assert.ThrowsAsync <GridwichPublicationLocatorDeletionException>(async() => await amsV3PubServices.LocatorDeleteAsync(null, MediaServicesV3PublicationTestData.GoodOperationContext).ConfigureAwait(false)).ConfigureAwait(false); }
public async void MediaServicesLocatorStreamingEndpointListFailureTest() { var locatorCreateDTO = MediaServicesV3PublicationTestData.RequestMediaServicesLocatorCreateDTO_Is_Expected; // Arrange var amsV3SdkWrapper = Mock.Of <IMediaServicesV3SdkWrapper>(); var storageService = Mock.Of <IStorageService>(); var amsContentKeyPolService = Mock.Of <IMediaServicesV3ContentKeyPolicyService>(); var amsStreamingPolService = Mock.Of <IMediaServicesV3CustomStreamingPolicyService>(); var settingsProvider = Mock.Of <ISettingsProvider>(); string assetName = "myassetname"; var amsAccount = new MediaService(storageAccounts: new List <StorageAccount>() { new StorageAccount() { Id = MediaServicesV3PublicationTestData.DefaultStorageId } }); var streamingEndpoint = new StreamingEndpoint(name: "default", hostName: "test.azure.net", scaleUnits: 0); var mockPageSe = new MockPageCollection <StreamingEndpoint>(new List <StreamingEndpoint>() { streamingEndpoint }.ToList()); // Arrange Mocks Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue(EnvironmentTypeConstants.EnvironmentTypeSettingName)) .Returns(EnvironmentTypeConstants.EnvironmentTypeDevelopment); Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <Asset>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new Asset(name: assetName)); Mock.Get(amsV3SdkWrapper) .Setup(x => x.MediaservicesGetAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(amsAccount); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingEndpointsListAsync(It.IsAny <CancellationToken>())) .ThrowsAsync(new Exception()); Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetFiltersCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <AssetFilter>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new AssetFilter()); // Act var amsV3PubServices = new MediaServicesV3PublicationService(amsContentKeyPolService, amsStreamingPolService, amsV3SdkWrapper, storageService, settingsProvider, Log); // Assert _ = await Xunit.Assert.ThrowsAsync <GridwichPublicationStreamingEndpointsListException>(async() => await amsV3PubServices.LocatorCreateAsync( locatorCreateDTO.ContainerUri, locatorCreateDTO.StreamingPolicyName, locatorCreateDTO.ContentKeyPolicyName, locatorCreateDTO.TimeBasedFilter, locatorCreateDTO.OperationContext, locatorCreateDTO.GenerateAudioFilters).ConfigureAwait(false)).ConfigureAwait(false); }
public async void MediaServicesV3ServiceCreateLocatorTestWithPolicyUpdate(RequestMediaServicesLocatorCreateDTO locatorCreateDTO, string updatePolicy, ContentKeyPolicy contentKeyPolicy) { var amsV3SdkWrapper = Mock.Of <IMediaServicesV3SdkWrapper>(); var storageService = Mock.Of <IStorageService>(); var settingsProvider = Mock.Of <ISettingsProvider>(); // Arrange string assetName = "myassetname"; var amsAccount = new MediaService(storageAccounts: new List <StorageAccount>() { new StorageAccount() { Id = MediaServicesV3PublicationTestData.DefaultStorageId } }); // Arrange Mocks Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <Asset>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new Asset(name: assetName)); Mock.Get(amsV3SdkWrapper) .Setup(x => x.MediaservicesGetAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(amsAccount); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingEndpointsListAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(MockPageSe); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorListPathsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())) .ReturnsAsync(Paths); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>() { new StreamingLocatorContentKey(Guid.NewGuid(), StreamingLocatorContentKeyType.CommonEncryptionCenc), new StreamingLocatorContentKey(Guid.NewGuid(), StreamingLocatorContentKeyType.CommonEncryptionCbcs) })); Mock.Get(amsV3SdkWrapper) .Setup(x => x.ContentKeyPolicyGetAsync(locatorCreateDTO.ContentKeyPolicyName, It.IsAny <CancellationToken>())) .ReturnsAsync(contentKeyPolicy); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingPolicyGetAsync(MediaServicesV3PublicationTestData.GoodDRMStreamingPolicy, It.IsAny <CancellationToken>())) .ReturnsAsync(new StreamingPolicy()); Mock.Get(amsV3SdkWrapper) .Setup(x => x.ContentKeyPolicyCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <IEnumerable <ContentKeyPolicyOption> >(), It.IsAny <string>(), It.IsAny <CancellationToken>())); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmOpenIdConnectDiscoveryDocument")) .Returns(MediaServicesV3PublicationTestData.AmsDrmOpenIdConnectDiscoveryDocument); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayPfxPassword")) .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayPfxPassword); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayAskHex")) .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayAskHex); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayCertificateB64")) .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayCertAsSecretStringStatic); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmEnableContentKeyPolicyUpdate")) .Returns(updatePolicy); IMediaServicesV3ContentKeyPolicyService amsContentKeyPolService2 = new MediaServicesV3ContentKeyPolicyService(settingsProvider, LogKey); IMediaServicesV3CustomStreamingPolicyService amsStreamingPolService2 = new MediaServicesV3CustomStreamingPolicyService(); // Act var amsV3PubServices = new MediaServicesV3PublicationService(amsContentKeyPolService2, amsStreamingPolService2, amsV3SdkWrapper, storageService, settingsProvider, Log); // Assert var result = await amsV3PubServices.LocatorCreateAsync( locatorCreateDTO.ContainerUri, locatorCreateDTO.StreamingPolicyName, locatorCreateDTO.ContentKeyPolicyName, locatorCreateDTO.TimeBasedFilter, locatorCreateDTO.OperationContext, locatorCreateDTO.GenerateAudioFilters).ConfigureAwait(false); result.ShouldBeOfType <ServiceOperationResultMediaServicesV3LocatorCreate>(); result.LocatorName.ShouldBeOfType <string>(); }
public async void MediaServicesV3ServiceCreateLocatorFailureTests(RequestMediaServicesLocatorCreateDTO locatorCreateDTO, bool expectedValue, Type typeException) { // Arrange var amsV3SdkWrapper = Mock.Of <IMediaServicesV3SdkWrapper>(); var storageService = Mock.Of <IStorageService>(); var amsContentKeyPolService = Mock.Of <IMediaServicesV3ContentKeyPolicyService>(); var settingsProvider = Mock.Of <ISettingsProvider>(); string assetName = "myassetname"; var amsAccount = new MediaService(storageAccounts: new List <StorageAccount>() { new StorageAccount() { Id = MediaServicesV3PublicationTestData.DefaultStorageId } }); // Arrange Mocks Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue(EnvironmentTypeConstants.EnvironmentTypeSettingName)) .Returns(EnvironmentTypeConstants.EnvironmentTypeDevelopment); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmEnableContentKeyPolicyUpdate")) .Returns("true"); Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <Asset>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new Asset(name: assetName)); Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetFiltersCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>(), TimingIsWrong(), It.IsAny <CancellationToken>())) .ThrowsAsync(new Exception()); Mock.Get(amsV3SdkWrapper) .Setup(x => x.MediaservicesGetAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(amsAccount); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingEndpointsListAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(MockPageSe); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorListPathsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())) .ReturnsAsync(Paths); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>())); if (locatorCreateDTO.ContentKeyPolicyName == MediaServicesV3PublicationTestData.GoodDataDtoDRM.ContentKeyPolicyName) { ContentKeyPolicy pol = null; Mock.Get(amsV3SdkWrapper) .Setup(x => x.ContentKeyPolicyGetAsync(MediaServicesV3PublicationTestData.GoodDataDtoDRM.ContentKeyPolicyName, It.IsAny <CancellationToken>())) .ReturnsAsync(pol); Mock.Get(amsV3SdkWrapper) .Setup(x => x.ContentKeyPolicyCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <List <ContentKeyPolicyOption> >(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .ThrowsAsync(new Exception()); } Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetFiltersCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <AssetFilter>(), It.IsAny <CancellationToken>())) .ThrowsAsync(new Exception()); Mock.Get(amsContentKeyPolService) .Setup(x => x.GetContentKeyPolicyFromMemory(It.IsAny <string>())) .Returns(new MediaServicesV3CustomContentKeyPolicyMultiDrmKey( MediaServicesV3PublicationTestData.AmsDrmOpenIdConnectDiscoveryDocument, MediaServicesV3PublicationTestData.AmsDrmFairPlayPfxPassword, MediaServicesV3PublicationTestData.AmsDrmFairPlayAskHex, MediaServicesV3PublicationTestData.AmsDrmFairPlayPfx)); IMediaServicesV3CustomStreamingPolicyService amsStreamingPolService2 = new MediaServicesV3CustomStreamingPolicyService(); // Act var amsV3PubServices = new MediaServicesV3PublicationService(amsContentKeyPolService, amsStreamingPolService2, amsV3SdkWrapper, storageService, settingsProvider, Log); // Assert if (expectedValue) { } else { _ = await Xunit.Assert.ThrowsAsync(typeException, async() => await amsV3PubServices.LocatorCreateAsync( locatorCreateDTO.ContainerUri, locatorCreateDTO.StreamingPolicyName, locatorCreateDTO.ContentKeyPolicyName, locatorCreateDTO.TimeBasedFilter, locatorCreateDTO.OperationContext, locatorCreateDTO.GenerateAudioFilters).ConfigureAwait(false)).ConfigureAwait(false); } }
public async void MediaServicesV3ServiceCreateLocatorTest(RequestMediaServicesLocatorCreateDTO locatorCreateDTO, bool expectedValue, Type typeException, string environmentType) { // Arrange var storageService = Mock.Of <IStorageService>(); var amsV3SdkWrapper = Mock.Of <IMediaServicesV3SdkWrapper>(); var settingsProvider = Mock.Of <ISettingsProvider>(); string assetName = "myassetname"; var amsAccount = new MediaService(storageAccounts: new List <StorageAccount>() { new StorageAccount() { Id = MediaServicesV3PublicationTestData.DefaultStorageId } }); // Arrange Mocks Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <Asset>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new Asset(name: assetName)); Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetFiltersCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>(), TimingIsWrong(), It.IsAny <CancellationToken>())) .ThrowsAsync(new Exception()); Mock.Get(amsV3SdkWrapper) .Setup(x => x.MediaservicesGetAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(amsAccount); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingEndpointsListAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(MockPageSe); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorListPathsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())) .ReturnsAsync(Paths); Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>())); if (locatorCreateDTO.ContentKeyPolicyName == MediaServicesV3PublicationTestData.GoodContentKeyPolicyDrm) { // let's add a CENC and CBCS keys Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>() { new StreamingLocatorContentKey(Guid.NewGuid(), StreamingLocatorContentKeyType.CommonEncryptionCenc), new StreamingLocatorContentKey(Guid.NewGuid(), StreamingLocatorContentKeyType.CommonEncryptionCbcs) })); } else { Mock.Get(amsV3SdkWrapper) .Setup(x => x.StreamingLocatorCreateAsync(It.IsAny <string>(), It.IsAny <StreamingLocator>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new StreamingLocator(assetName: "asset45", streamingPolicyName: locatorCreateDTO.StreamingPolicyName, defaultContentKeyPolicyName: locatorCreateDTO.ContentKeyPolicyName, contentKeys: new List <StreamingLocatorContentKey>())); } Mock.Get(amsV3SdkWrapper) .Setup(x => x.AssetFiltersCreateOrUpdateAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <AssetFilter>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new AssetFilter()); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue(EnvironmentTypeConstants.EnvironmentTypeSettingName)) .Returns(environmentType); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmOpenIdConnectDiscoveryDocument")) .Returns(MediaServicesV3PublicationTestData.AmsDrmOpenIdConnectDiscoveryDocument); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayPfxPassword")) .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayPfxPassword); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayAskHex")) .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayAskHex); Mock.Get(settingsProvider) .Setup(x => x.GetAppSettingsValue("AmsDrmFairPlayCertificateB64")) .Returns(MediaServicesV3PublicationTestData.AmsDrmFairPlayCertAsSecretStringStatic); Mock.Get(storageService) .Setup(x => x.ListBlobsAsync(It.IsAny <Uri>(), It.IsAny <StorageClientProviderContext>())) .ReturnsAsync(MediaServicesV3PublicationTestData.GoodBlobItemListWithIsmFile); Mock.Get(storageService) .Setup(x => x.DownloadHttpRangeAsync(It.IsAny <Uri>(), It.IsAny <StorageClientProviderContext>(), default)) .ReturnsAsync(MediaServicesV3PublicationTestData.GoodIsmFileBlobDownloadInfo); IMediaServicesV3ContentKeyPolicyService amsContentKeyPolService2 = new MediaServicesV3ContentKeyPolicyService(settingsProvider, LogKey); IMediaServicesV3CustomStreamingPolicyService amsStreamingPolService2 = new MediaServicesV3CustomStreamingPolicyService(); // Act var amsV3PubServices = new MediaServicesV3PublicationService(amsContentKeyPolService2, amsStreamingPolService2, amsV3SdkWrapper, storageService, settingsProvider, Log); // Assert if (expectedValue == false) { _ = await Xunit.Assert.ThrowsAsync(typeException, async() => await amsV3PubServices.LocatorCreateAsync( locatorCreateDTO.ContainerUri, locatorCreateDTO.StreamingPolicyName, locatorCreateDTO.ContentKeyPolicyName, locatorCreateDTO.TimeBasedFilter, locatorCreateDTO.OperationContext, locatorCreateDTO.GenerateAudioFilters).ConfigureAwait(false)).ConfigureAwait(false); } else { var result = await amsV3PubServices.LocatorCreateAsync( locatorCreateDTO.ContainerUri, locatorCreateDTO.StreamingPolicyName, locatorCreateDTO.ContentKeyPolicyName, locatorCreateDTO.TimeBasedFilter, locatorCreateDTO.OperationContext, locatorCreateDTO.GenerateAudioFilters).ConfigureAwait(false); result.ShouldBeOfType <ServiceOperationResultMediaServicesV3LocatorCreate>(); result.LocatorName.ShouldBeOfType <string>(); } }