Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/corelib/Core/Domain/ObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum ObjectStore
ContainerExists,
ContainerDeleted,
ContainerNotEmpty,
ContainerNotFound
ContainerNotFound,
ObjectDeleted
}
}
1 change: 1 addition & 0 deletions src/corelib/Core/IObjectStoreProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public interface IObjectStoreProvider
void CreateObjectFromStream(CloudIdentity identity, string container, Stream stream, string objectName, int chunkSize = 65536, Dictionary<string, string> headers = null, string region = null, Action<long> progressUpdated = null);
void GetObjectSaveToFile(string container, string saveDirectory, string objectName, string fileName = null, int chunkSize = 65536, Dictionary<string, string> headers = null, string region = null, bool verifyEtag = false, CloudIdentity identity = null);
void GetObject(string container, string objectName, Stream outputStream, int chunkSize = 65536, Dictionary<string, string> headers = null, string region = null, bool verifyEtag = false, CloudIdentity identity = null);
ObjectStore DeleteObject(CloudIdentity identity, string container, string objectNmae, Dictionary<string, string> headers = null, string region = null);

#endregion

Expand Down
17 changes: 17 additions & 0 deletions src/corelib/Providers/Rackspace/ObjectStoreProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,23 @@ public void GetObjectSaveToFile(string container, string saveDirectory, string o
}
}

public ObjectStore DeleteObject(CloudIdentity identity, string container, string objectName, Dictionary<string, string> 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
Expand Down
69 changes: 63 additions & 6 deletions src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>();
//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<string, string>();
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<string, string>();
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<string, string>();
// 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<string, string>();
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<string, string>();
var provider = new ObjectStoreProvider();
var deleteResponse = provider.DeleteObject(_testIdentity, containerName, fileName, headers);

Assert.Fail("Expected exception was not thrown.");
}
#endregion Object Tests

}
Expand Down