public void BucketTaggingBasicTest() { var setRequest = new SetBucketTaggingRequest(_bucketName); var tag1 = new Tag { Key = "project", Value = "projectone" }; var tag2 = new Tag { Key = "user", Value = "jsmith" }; setRequest.AddTag(tag1); setRequest.AddTag(tag2); _ossClient.SetBucketTagging(setRequest); var result = _ossClient.GetBucketTagging(_bucketName); Assert.AreEqual(result.Tags.Count, setRequest.Tags.Count); Assert.AreEqual(result.Tags[0].Key, setRequest.Tags[0].Key); Assert.AreEqual(result.Tags[0].Value, setRequest.Tags[0].Value); Assert.AreEqual(result.Tags[1].Key, setRequest.Tags[1].Key); Assert.AreEqual(result.Tags[1].Value, setRequest.Tags[1].Value); _ossClient.DeleteBucketTagging(_bucketName); result = _ossClient.GetBucketTagging(_bucketName); Assert.AreEqual(result.Tags.Count, 0); }
public void SetBucketTaggingWithExceptionTest() { try { var request = new SetBucketTaggingRequest(_bucketName); request.AddTag(null); } catch (ArgumentException e) { Assert.IsTrue(true, e.Message); } try { var request = new SetBucketTaggingRequest(""); } catch (ArgumentException e) { Assert.IsTrue(true, e.Message); } try { var request = new SetBucketTaggingRequest(_bucketName, null); } catch (ArgumentException e) { Assert.IsTrue(true, e.Message); } try { var request = new SetBucketTaggingRequest(null, null); } catch (ArgumentException e) { Assert.IsTrue(true, e.Message); } try { var request = new SetBucketTaggingRequest(_bucketName); request.Tags = null; } catch (ArgumentException e) { Assert.IsTrue(true, e.Message); } }
/// <summary> /// 设置标签 /// </summary> /// <param name="request"></param> /// <returns></returns> public OperateResultDto SetTag(SetTagBucketParam request) { return(ToolCommon.GetResponse(() => { new SetTagBucketParamValidator().Validate(request).Check(HttpStatus.Err.Name); var zone = Core.Tools.GetZone(_aLiYunConfig, request.PersistentOps.Zone, () => ZoneEnum.HangZhou); var client = _aLiYunConfig.GetClient(zone); var bucket = Core.Tools.GetBucket(_aLiYunConfig, request.PersistentOps.Bucket); var setRequest = new SetBucketTaggingRequest(bucket); request.Tags.ForEach(tag => { setRequest.AddTag(new Tag() { Key = tag.Key, Value = tag.Value }); }); client.SetBucketTagging(setRequest); return new OperateResultDto(true, "success"); }, message => new OperateResultDto(false, message))); }