From c7bd004da7fb53a94eba77e0b61350bdeb8d6abb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Mar 2013 12:37:51 -0500 Subject: [PATCH] [Delivers #43555147]delete object functionality --- src/corelib/Core/Domain/ObjectStore.cs | 3 +- src/corelib/Core/IObjectStoreProvider.cs | 1 + .../Rackspace/ObjectStoreProvider.cs | 17 +++++ .../Providers/Rackspace/ObjectStoreTests.cs | 69 +++++++++++++++++-- 4 files changed, 83 insertions(+), 7 deletions(-) diff --git a/src/corelib/Core/Domain/ObjectStore.cs b/src/corelib/Core/Domain/ObjectStore.cs index b0538b768..b8d313470 100644 --- a/src/corelib/Core/Domain/ObjectStore.cs +++ b/src/corelib/Core/Domain/ObjectStore.cs @@ -12,6 +12,7 @@ public enum ObjectStore ContainerExists, ContainerDeleted, ContainerNotEmpty, - ContainerNotFound + ContainerNotFound, + ObjectDeleted } } diff --git a/src/corelib/Core/IObjectStoreProvider.cs b/src/corelib/Core/IObjectStoreProvider.cs index 00c4104d3..d47bc4392 100644 --- a/src/corelib/Core/IObjectStoreProvider.cs +++ b/src/corelib/Core/IObjectStoreProvider.cs @@ -44,6 +44,7 @@ public interface IObjectStoreProvider void CreateObjectFromStream(CloudIdentity identity, string container, Stream stream, string objectName, int chunkSize = 65536, Dictionary headers = null, string region = null, Action progressUpdated = null); void GetObjectSaveToFile(string container, string saveDirectory, string objectName, string fileName = null, int chunkSize = 65536, Dictionary headers = null, string region = null, bool verifyEtag = false, CloudIdentity identity = null); void GetObject(string container, string objectName, Stream outputStream, int chunkSize = 65536, Dictionary headers = null, string region = null, bool verifyEtag = false, CloudIdentity identity = null); + ObjectStore DeleteObject(CloudIdentity identity, string container, string objectNmae, Dictionary headers = null, string region = null); #endregion diff --git a/src/corelib/Providers/Rackspace/ObjectStoreProvider.cs b/src/corelib/Providers/Rackspace/ObjectStoreProvider.cs index 606fd0834..4f673ff2f 100644 --- a/src/corelib/Providers/Rackspace/ObjectStoreProvider.cs +++ b/src/corelib/Providers/Rackspace/ObjectStoreProvider.cs @@ -431,6 +431,23 @@ public void GetObjectSaveToFile(string container, string saveDirectory, string o } } + public ObjectStore DeleteObject(CloudIdentity identity, string container, string objectName, Dictionary headers = null, string region = null) + { + _objectStoreHelper.ValidateContainerName(container); + _objectStoreHelper.ValidateObjectName(objectName); + + var urlPath = new Uri(string.Format("{0}/{1}/{2}", GetServiceEndpointCloudFiles(identity, region), container, objectName)); + + var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.DELETE, headers); + + if (response.StatusCode == 204) + return ObjectStore.ObjectDeleted; + if (response.StatusCode == 404) + return ObjectStore.ContainerNotFound; + + return ObjectStore.Unknown; + + } #endregion #region Private methods diff --git a/src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs b/src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs index 12459fbc7..4f3b44cf6 100644 --- a/src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs +++ b/src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs @@ -485,18 +485,75 @@ public void Should_Create_Object_From_File_Without_Headers() [TestMethod] public void Should_Get_Object_And_Save_To_File_Without_Headers() { - //const string containerName = "DarkKnight"; - //const string filePath = @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"; - //string fileName = Path.GetFileName(filePath); - //var headers = new Dictionary(); - //var provider = new ObjectStoreProvider(); - //provider.GetObjectSaveToFile(_testIdentity, containerName, filePath, fileName, 65536, headers); + const string containerName = "DarkKnight"; + const string filePath = @"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"; + const string saveDirectory = @"C:\Users\Public\Pictures\Sample Pictures\"; + + string fileName = Path.GetFileName(filePath); + var headers = new Dictionary(); + var provider = new ObjectStoreProvider(); + provider.GetObjectSaveToFile(containerName,saveDirectory,fileName,null,65536,null,null,false,_testIdentity); //var containerGetObjectsResponse = provider.GetObjects(_testIdentity, containerName); //Assert.AreEqual(fileName, containerGetObjectsResponse.Where(x => x.Name.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Name); } + [TestMethod] + public void Should_Get_Object_And_Save_To_File_Without_Headers_And_Verify_Etag() + { + const string containerName = "DarkKnight"; + const string filePath = @"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"; + const string saveDirectory = @"C:\Users\Public\Pictures\Sample Pictures\"; + + string fileName = Path.GetFileName(filePath); + var headers = new Dictionary(); + var provider = new ObjectStoreProvider(); + provider.GetObjectSaveToFile(containerName, saveDirectory, fileName, null, 65536, null, null, true, _testIdentity); + } + + //[TestMethod] + //public void Should_Get_Object_And_Save_To_File_Without_Headers_And_Verify_Etag_Fails() + //{ + // const string containerName = "DarkKnight"; + // const string filePath = @"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"; + // const string saveDirectory = @"C:\Users\Public\Pictures\"; + + // string fileName = Path.GetFileName(filePath); + // var headers = new Dictionary(); + // var provider = new ObjectStoreProvider(); + // provider.GetObjectSaveToFile(containerName, saveDirectory, fileName, "test", 65536, null, null, true, _testIdentity); + //} + + + [TestMethod] + public void Should_Delete_Object() + { + const string containerName = "DarkKnight"; + const string filePath = @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"; + string fileName = Path.GetFileName(filePath); + var headers = new Dictionary(); + var provider = new ObjectStoreProvider(); + var deleteResponse = provider.DeleteObject(_testIdentity, containerName, fileName, headers); + + Assert.AreEqual(ObjectStore.ObjectDeleted, deleteResponse); + } + + + [TestMethod] + [ExpectedException(typeof(ItemNotFoundException))] + public void Should_Throw_An_Exception_When_Deleting_Object() + { + // TODO: Also need to make 404 as an acceptable status. + const string containerName = "DarkKnight"; + const string filePath = @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"; + string fileName = Path.GetFileName(filePath); + var headers = new Dictionary(); + var provider = new ObjectStoreProvider(); + var deleteResponse = provider.DeleteObject(_testIdentity, containerName, fileName, headers); + + Assert.Fail("Expected exception was not thrown."); + } #endregion Object Tests }