CPNV-ES / CPNV-ES/RIA2_rekognition_python
Create test class based on the client implementation
- Dominant language
- Python
- Stars
- 1
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
```c#
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using Ria2Model.BucketManager;
namespace TestRia2Model.BucketManager
{
///
/// This test class is designed to confirm the AwsBucketManager class's behavior
///
public class TestAwsBucketManagerImpl
{
#region private attributes
private AwsBucketManagerImpl bucketManager;
private string domain;
private string bucketName;
private string bucketUrl;
private string imageName;
private string pathToTestFolder;
private string fullPathToImage;
private string prefixObjectDownloaded;
#endregion private attributes
///
/// This test method initializes the context before each test method run.
///
[SetUp]
public void Init()
{
this.pathToTestFolder = Directory.GetCurrentDirectory().Replace("bin\\Debug\\netcoreapp3.1", "testData");
this.bucketName = "testbucket";
this.domain = "aws.dev.actualit.info";
this.bucketUrl = bucketName + "." + this.domain;
this.imageName = "emiratesa380.jpg";
this.fullPathToImage = pathToTestFolder + "\\" + imageName;
this.prefixObjectDownloaded = "downloaded";
this.bucketManager = new AwsBucketManagerImpl(this.bucketUrl);
}
///
/// This test method checks the method in charge of creating a new object
/// We try to create a new bucket
///
[Test]
public async Task CreateObject_CreateNewBucket_Success()
{
//given
Assert.IsFalse(await this.bucketManager.ObjectExists(bucketUrl));
//when
await this.bucketManager.CreateObject(bucketUrl);
//then
Assert.IsTrue(await this.bucketManager.ObjectExists(bucketUrl));
}
///
/// This test method checks the method in charge of creating a new data object
/// Note : the bucket exists
///
[Test]
public async Task CreateObject_CreateObjectWithExistingBucket_Success()
{
//given
string fileName = this.imageName;
string objectUrl = this.bucketUrl + "/" + this.imageName;
await this.bucketManager.CreateObject(this.bucketUrl);
Assert.IsTrue(await this.bucketManager.ObjectExists(this.bucketUrl));
Assert.IsFalse(await this.bucketManager.ObjectExists(objectUrl));
//when
await this.bucketManager.CreateObject(objectUrl, this.pathToTestFolder + "//" + fileName);
//then
Assert.IsTrue(await this.bucketManager.ObjectExists(objectUrl));
}
///
/// This test method checks the method in charge of creating a new data object
/// Note : the bucket doesn't exist
///
[Test]
public async Task CreateObject_CreateObjectBucketNotExist_Success()
{
//given
string fileName = this.imageName;
string objectUrl = this.bucketUrl + "/" + this.imageName;
Assert.IsFalse(await this.bucketManager.ObjectExists(this.bucketUrl));
Assert.IsFalse(await this.bucketManager.ObjectExists(objectUrl));
//when
await this.bucketManager.CreateObject(objectUrl, this.pathToTestFolder + "//" + fileName);
//then
Assert.IsTrue(await this.bucketManager.ObjectExists(objectUrl));
}
///
/// This test method checks the method in charge of uploading item in an existing bucket
///
[Test]
public async Task DownloadObject_NominalCase_Success()
{
//given
string objectUrl = bucketUrl + "//" + this.imageName;
string destinationFullPath = this.pathToTestFolder + "//" + this.prefixObjectDownloaded + this.imageName;
await this.bucketManager.CreateObject(objectUrl, this.pathToTestFolder + "//" + this.imageName);
Assert.IsTrue(await this.bucketManager.ObjectExists(bucketUrl));
//when
await this.bucketManager.DownloadObject(objectUrl, destinationFullPath);
//then
Assert.IsTrue(File.Exists(destinationFullPath));
}
///
/// This test method checks the method in charge of testing the existence of an object
///
[Test]
public async Task IsObjectExists_NominalCase_Success()
{
//given
Task t = this.bucketManager.CreateObject(this.bucketUrl);
await t;
bool actualResult;
//when
actualResult = await this.bucketManager.ObjectExists(bucketUrl);
//then
Assert.IsTrue(actualResult);
}
///
/// This test method checks the method in charge of testing the existence of an object
/// When the object doesn't exist (object is the bucket)
///
[Test]
public async Task IsObjectExists_ObjectNotExistBucket_Success()
{
//given
string notExistingBucket = "notExistingBucket" + this.domain;
bool actualResult;
//when
actualResult = await this.bucketManager.ObjectExists(notExistingBucket);
//then
Assert.IsFalse(actualResult);
}
///
/// This test method checks the method in charge of testing the existence of an object
/// When the object doesn't exist (object is the file in an existing bucket)
///
[Test]
public async Task IsObjectExists_ObjectNotExistFile_Success()
{
//given
await this.bucketManager.CreateObject(this.bucketUrl);
string notExistingFile = bucketUrl + "//" + "notExistingFile.jpg";
Assert.IsTrue(await this.bucketManager.ObjectExists(bucketUrl));
bool actualResult;
//when
actualResult = await this.bucketManager.ObjectExists(notExistingFile);
//then
Assert.IsFalse(actualResult);
}
///
/// This test method checks the method in charge of removing an existing object
/// Case : empty bucket
///
[Test]
public async Task RemoveObject_EmptyBucket_Success()
{
//given
await this.bucketManager.CreateObject(this.bucketUrl);
Assert.IsTrue(await this.bucketManager.ObjectExists(bucketUrl));
//when
await this.bucketManager.RemoveObject(this.bucketUrl);
//then
Assert.IsFalse(await this.bucketManager.ObjectExists(bucketUrl));
}
///
/// This test method checks the method in charge of removing an existing object
/// Case : bucket with content
///
[Test]
public async Task RemoveObject_NotEmptyBucket_Success()
{
//given
string fileName = this.imageName;
string objectUrl = this.bucketUrl + "/" + this.imageName;
await this.bucketManager.CreateObject(this.bucketUrl);
await this.bucketManager.CreateObject(objectUrl, this.pathToTestFolder + "//" + fileName);
Assert.IsTrue(await this.bucketManager.ObjectExists(bucketUrl));
Assert.IsTrue(await this.bucketManager.ObjectExists(objectUrl));
//when
await this.bucketManager.RemoveObject(this.bucketUrl);
//then
Assert.IsFalse(await this.bucketManager.ObjectExists(bucketUrl));
}
///
/// This test method cleans up the context after each test method run.
///
[TearDown]
public async Task Cleanup()
{
string destinationFullPath = this.pathToTestFolder + "\\" + this.prefixObjectDownloaded + this.imageName;
if (File.Exists(destinationFullPath))
{
File.Delete(destinationFullPath);
}
this.bucketManager = new AwsBucketManagerImpl(this.bucketUrl);
if (await this.bucketManager.ObjectExists(bucketUrl))
{
await this.bucketManager.RemoveObject(this.bucketUrl);
}
}
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.