Skip to content

Commit

Permalink
提升单测覆盖率
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnnqin committed Mar 29, 2023
1 parent ca76468 commit b61efdc
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 1 deletion.
2 changes: 1 addition & 1 deletion QCloudCSharpSDK/COSXMLTests/ObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ public void TestUploadTaskCancelledAndRetry()

var asyncTask = transferManager.UploadAsync(uploadTask);

Thread.Sleep(2000);
Thread.Sleep(500);
uploadTask.Cancel();
Thread.Sleep(500);

Expand Down
227 changes: 227 additions & 0 deletions QCloudCSharpSDK/COSXMLTests/ServiceConfigTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using COSXML.Log;
using COSXML.Auth;
using COSXML.Model.Service;
using COSXML;
using COSXML.Model.Object;
Expand Down Expand Up @@ -107,5 +108,231 @@ public void TestCustomHost()

Assert.AreEqual("service.cos.myqcloud.com", serviceRequest.GetHost());
}

[Test()]
public void TestInvalidParams()
{
CosXmlServer cosXml;
try {
cosXml = new CosXmlServer(null, null);
Assert.Fail();
} catch (Exception)
{

}


}

[Test()]
public void ServiceSchedueTest()
{
CosXmlConfig config = new CosXmlConfig.Builder()
.SetConnectionLimit(512)
.Build();

string secretId = Environment.GetEnvironmentVariable("SECRET_ID");
string secretKey = Environment.GetEnvironmentVariable("SECRET_KEY");

QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, 600);
CosXmlServer cosXml = new CosXmlServer(config, qCloudCredentialProvider);

GetServiceRequest serviceRequest = new GetServiceRequest();
try {
cosXml.GetService(serviceRequest, null, null);
} catch (Exception)
{

}

PutBucketRequest putBucketRequest = new PutBucketRequest("dotnet-ut-obj-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.PutBucket(putBucketRequest, null, null);
} catch (Exception)
{

}

DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest("not-exist-bucket-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.DeleteBucket(deleteBucketRequest, null, null);
} catch (Exception)
{

}

HeadBucketRequest headBucketRequest = new HeadBucketRequest("dotnet-ut-obj-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.HeadBucket(headBucketRequest, null, null);
} catch (Exception)
{

}

PutBucketACLRequest pubBucketAclRequest = new PutBucketACLRequest("not-exist-bucket-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.PutBucketACL(pubBucketAclRequest, null, null);
} catch (Exception)
{

}

GetBucketACLRequest getBucketAclRequest = new GetBucketACLRequest("not-exist-bucket-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.GetBucketACL(getBucketAclRequest, null, null);
} catch (Exception)
{

}

PutBucketCORSRequest putBucketCORSRequest = new PutBucketCORSRequest("not-exist-bucket-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.PutBucketCORS(putBucketCORSRequest, null, null);
} catch (Exception)
{

}

GetBucketCORSRequest getBucketCORSRequest = new GetBucketCORSRequest("not-exist-bucket-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.GetBucketCORS(getBucketCORSRequest, null, null);
} catch (Exception)
{

}

DeleteBucketCORSRequest deleteBucketCORSRequest = new DeleteBucketCORSRequest("bucket");
try {
cosXml.DeleteBucketCORS(deleteBucketCORSRequest, null, null);
} catch (Exception)
{

}

PutBucketLifecycleRequest putBucketLifecycleRequest = new PutBucketLifecycleRequest("bucket");
try {
cosXml.PutBucketLifecycle(putBucketLifecycleRequest, null, null);
} catch (Exception)
{

}

GetBucketLifecycleRequest getBucketLifecycleRequest = new GetBucketLifecycleRequest("bucket");
try {
cosXml.GetBucketLifecycle(getBucketLifecycleRequest, null, null);
} catch (Exception)
{

}

DeleteBucketLifecycleRequest deleteBucketLifecycleRequest = new DeleteBucketLifecycleRequest("bucket");
try {
cosXml.DeleteBucketLifecycle(deleteBucketLifecycleRequest, null, null);
} catch (Exception)
{

}

PutBucketReplicationRequest putBucketReplicationRequest = new PutBucketReplicationRequest("bucket");
try {
cosXml.PutBucketReplication(putBucketReplicationRequest, null, null);
} catch (Exception)
{

}

GetBucketReplicationRequest getBucketReplicationRequest = new GetBucketReplicationRequest("dotnet-ut-obj-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.GetBucketReplication(getBucketReplicationRequest, null, null);
} catch (Exception)
{

}
try {
cosXml.GetBucketReplication(getBucketReplicationRequest);
} catch (Exception)
{

}

DeleteBucketReplicationRequest deleteBucketReplicationRequest = new DeleteBucketReplicationRequest("not-exist-bucket-" + Environment.GetEnvironmentVariable("APPID"));
try {
cosXml.DeleteBucketReplication(deleteBucketReplicationRequest);
} catch (Exception)
{

}
try {
cosXml.DeleteBucketReplication(deleteBucketReplicationRequest, null, null);
} catch (Exception)
{

}

PutBucketVersioningRequest putBucketVersioningRequest = new PutBucketVersioningRequest("bucket");
try {
cosXml.PutBucketVersioning(putBucketVersioningRequest, null, null);
} catch (Exception)
{

}

GetBucketVersioningRequest getBucketVersioningRequest = new GetBucketVersioningRequest("bucket");
try {
cosXml.GetBucketVersioning(getBucketVersioningRequest, null, null);
} catch (Exception)
{

}

ListBucketVersionsRequest listBucketVersionsRequest = new ListBucketVersionsRequest("bucket");
try {
cosXml.ListBucketVersions(listBucketVersionsRequest, null, null);
} catch (Exception)
{

}

PutBucketRefererRequest putBucketRefererRequest = new PutBucketRefererRequest("bucket");
try {
cosXml.PutBucketReferer(putBucketRefererRequest, null, null);
} catch (Exception)
{

}

GetBucketRefererRequest getBucketRefererRequest = new GetBucketRefererRequest("bucket");
try {
cosXml.GetBucketReferer(getBucketRefererRequest, null, null);
} catch (Exception)
{

}

DeleteBucketPolicyRequest deleteBucketPolicyRequest = new DeleteBucketPolicyRequest("bucket");
try {
cosXml.DeleteBucketPolicy(deleteBucketPolicyRequest, null, null);
} catch (Exception)
{

}
try {
cosXml.DeleteBucketPolicy(deleteBucketPolicyRequest);
} catch (Exception)
{

}

AppendObjectRequest appendObjectRequest = new AppendObjectRequest("bucket", "key");
try {
cosXml.AppendObject(appendObjectRequest, null, null);
} catch (Exception)
{

}

Assert.Pass();

}
}
}

0 comments on commit b61efdc

Please sign in to comment.