public void Should_Make_Container_CDN_Disabled() { var provider = new CloudFilesProvider(); var cdnEnabledResponse = provider.DisableCDNOnContainer(containerName, identity: _testIdentity); var cdnContainerHeaderResponse = provider.GetContainerCDNHeader(containerName, identity: _testIdentity); Assert.IsFalse(cdnContainerHeaderResponse.CDNEnabled); }
public void Should_Make_Container_CDN_Enabled_With_Log_Retention() { var provider = new CloudFilesProvider(); var cdnEnabledResponse = provider.EnableCDNOnContainer(containerName, true, identity: _testIdentity); var cdnContainerHeaderResponse = provider.GetContainerCDNHeader(containerName, identity: _testIdentity); Assert.AreEqual(259200, cdnContainerHeaderResponse.Ttl); Assert.IsTrue(cdnContainerHeaderResponse.LogRetention); Assert.IsTrue(cdnContainerHeaderResponse.CDNEnabled); Assert.IsTrue(!string.IsNullOrWhiteSpace(cdnContainerHeaderResponse.CDNIosUri)); Assert.IsTrue(containerName.Equals(cdnContainerHeaderResponse.Name, StringComparison.InvariantCultureIgnoreCase)); }
public void Should_Make_Container_CDN_Enabled_With_TTL() { var provider = new CloudFilesProvider(); var cdnEnabledResponse = provider.EnableCDNOnContainer(containerName, 1000, identity: _testIdentity); var cdnContainerHeaderResponse = provider.GetContainerCDNHeader(containerName, identity: _testIdentity); Assert.AreEqual(1000, cdnContainerHeaderResponse.Ttl); Assert.IsTrue(cdnContainerHeaderResponse.CDNEnabled); }
public void Should_Not_Get_CDN_Headers_For_Container() { var provider = new CloudFilesProvider(); var objectHeadersResponse = provider.GetContainerCDNHeader(containerName, identity: _testIdentity); Assert.Fail("Expected exception was not thrown."); }
public void Should_Get_CDN_Headers_For_Container() { var provider = new CloudFilesProvider(); var objectHeadersResponse = provider.GetContainerCDNHeader(containerName, identity: _testIdentity); Assert.IsNotNull(objectHeadersResponse); }
public void TestCDNOnContainer() { IObjectStorageProvider provider = new CloudFilesProvider(Bootstrapper.Settings.TestIdentity); string containerName = TestContainerPrefix + Path.GetRandomFileName(); string objectName = Path.GetRandomFileName(); string fileContents = "File contents!"; ObjectStore result = provider.CreateContainer(containerName); Assert.AreEqual(ObjectStore.ContainerCreated, result); Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(fileContents)); provider.CreateObject(containerName, stream, objectName); Dictionary<string, string> cdnHeaders = provider.EnableCDNOnContainer(containerName, false); Assert.IsNotNull(cdnHeaders); Console.WriteLine("CDN Headers from EnableCDNOnContainer"); foreach (var pair in cdnHeaders) Console.WriteLine(" {0}: {1}", pair.Key, pair.Value); ContainerCDN containerHeader = provider.GetContainerCDNHeader(containerName); Assert.IsNotNull(containerHeader); Console.WriteLine(JsonConvert.SerializeObject(containerHeader, Formatting.Indented)); Assert.IsTrue(containerHeader.CDNEnabled); Assert.IsFalse(containerHeader.LogRetention); Assert.IsTrue( containerHeader.CDNUri != null || containerHeader.CDNIosUri != null || containerHeader.CDNSslUri != null || containerHeader.CDNStreamingUri != null); // Call the other overloads of EnableCDNOnContainer cdnHeaders = provider.EnableCDNOnContainer(containerName, containerHeader.Ttl); ContainerCDN updatedHeader = provider.GetContainerCDNHeader(containerName); Console.WriteLine(JsonConvert.SerializeObject(updatedHeader, Formatting.Indented)); Assert.IsNotNull(updatedHeader); Assert.IsTrue(updatedHeader.CDNEnabled); Assert.IsFalse(updatedHeader.LogRetention); Assert.IsTrue( updatedHeader.CDNUri != null || updatedHeader.CDNIosUri != null || updatedHeader.CDNSslUri != null || updatedHeader.CDNStreamingUri != null); Assert.AreEqual(containerHeader.Ttl, updatedHeader.Ttl); cdnHeaders = provider.EnableCDNOnContainer(containerName, containerHeader.Ttl, true); updatedHeader = provider.GetContainerCDNHeader(containerName); Console.WriteLine(JsonConvert.SerializeObject(updatedHeader, Formatting.Indented)); Assert.IsNotNull(updatedHeader); Assert.IsTrue(updatedHeader.CDNEnabled); Assert.IsTrue(updatedHeader.LogRetention); Assert.IsTrue( updatedHeader.CDNUri != null || updatedHeader.CDNIosUri != null || updatedHeader.CDNSslUri != null || updatedHeader.CDNStreamingUri != null); Assert.AreEqual(containerHeader.Ttl, updatedHeader.Ttl); // update the container CDN properties Dictionary<string, string> headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { { CloudFilesProvider.CdnTTL, (updatedHeader.Ttl + 1).ToString() }, { CloudFilesProvider.CdnLogRetention, false.ToString() }, //{ CloudFilesProvider.CdnEnabled, true.ToString() }, }; provider.UpdateContainerCdnHeaders(containerName, headers); updatedHeader = provider.GetContainerCDNHeader(containerName); Console.WriteLine(JsonConvert.SerializeObject(updatedHeader, Formatting.Indented)); Assert.IsNotNull(updatedHeader); Assert.IsTrue(updatedHeader.CDNEnabled); Assert.IsFalse(updatedHeader.LogRetention); Assert.IsTrue( updatedHeader.CDNUri != null || updatedHeader.CDNIosUri != null || updatedHeader.CDNSslUri != null || updatedHeader.CDNStreamingUri != null); Assert.AreEqual(containerHeader.Ttl + 1, updatedHeader.Ttl); // attempt to access the container over the CDN if (containerHeader.CDNUri != null || containerHeader.CDNSslUri != null) { string baseUri = containerHeader.CDNUri ?? containerHeader.CDNSslUri; Uri uri = new Uri(containerHeader.CDNUri + '/' + objectName); WebRequest request = HttpWebRequest.Create(uri); using (WebResponse response = request.GetResponse()) { Stream cdnStream = response.GetResponseStream(); StreamReader reader = new StreamReader(cdnStream, Encoding.UTF8); string text = reader.ReadToEnd(); Assert.AreEqual(fileContents, text); } } else { Assert.Inconclusive("This integration test relies on cdn_uri or cdn_ssl_uri."); } IEnumerable<ContainerCDN> containers = ListAllCDNContainers(provider); Console.WriteLine("Containers"); foreach (ContainerCDN container in containers) { Console.WriteLine(" {1}{0}", container.Name, container.CDNEnabled ? "*" : ""); } cdnHeaders = provider.DisableCDNOnContainer(containerName); Assert.IsNotNull(cdnHeaders); Console.WriteLine("CDN Headers from DisableCDNOnContainer"); foreach (var pair in cdnHeaders) Console.WriteLine(" {0}: {1}", pair.Key, pair.Value); updatedHeader = provider.GetContainerCDNHeader(containerName); Console.WriteLine(JsonConvert.SerializeObject(updatedHeader, Formatting.Indented)); Assert.IsNotNull(updatedHeader); Assert.IsFalse(updatedHeader.CDNEnabled); Assert.IsFalse(updatedHeader.LogRetention); Assert.IsTrue( updatedHeader.CDNUri != null || updatedHeader.CDNIosUri != null || updatedHeader.CDNSslUri != null || updatedHeader.CDNStreamingUri != null); Assert.AreEqual(containerHeader.Ttl + 1, updatedHeader.Ttl); provider.DeleteContainer(containerName, deleteObjects: true); }