Skip to content

Commit 5bfb543

Browse files
anshuldavid13amanda-tarafa
authored andcommitted
Incorporating review comments
1 parent cb24da3 commit 5bfb543

12 files changed

Lines changed: 353 additions & 19 deletions

‎storage/api/Storage.Samples.Tests/CreateBucketTest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ public void CreateBucket()
3838
var metadata = getBucketMetadataSample.GetBucketMetadata(bucketName);
3939
Assert.NotNull(metadata);
4040
}
41-
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2020 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using Xunit;
17+
18+
[Collection(nameof(StorageFixture))]
19+
public class CreatePubSubNotificationTest
20+
{
21+
private readonly StorageFixture _fixture;
22+
23+
public CreatePubSubNotificationTest(StorageFixture fixture)
24+
{
25+
_fixture = fixture;
26+
}
27+
28+
[Fact]
29+
public void CreatePubSubNotification()
30+
{
31+
32+
CreatePubSubNotificationSample createPubSubNotificationSample = new CreatePubSubNotificationSample();
33+
var confirmNotification = createPubSubNotificationSample.CreatePubSubNotification(_fixture.BucketNameGeneric, "my-topic");
34+
35+
Assert.NotNull(confirmNotification);
36+
37+
}
38+
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2020 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Google;
16+
using System;
17+
using Xunit;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Text;
21+
22+
[Collection(nameof(StorageFixture))]
23+
public class DeletePubSubNotificationTest
24+
{
25+
private readonly StorageFixture _fixture;
26+
27+
public DeletePubSubNotificationTest(StorageFixture fixture)
28+
{
29+
_fixture = fixture;
30+
}
31+
32+
[Fact]
33+
public void DeletePubSubNotification()
34+
{
35+
CreatePubSubNotificationSample createPubSubNotificationSample = new CreatePubSubNotificationSample();
36+
GetPubSubNotificationSample getPubSubNotificationSample = new GetPubSubNotificationSample();
37+
DeletePubSubNotificationSample deletePubSubNotificationSample = new DeletePubSubNotificationSample();
38+
39+
var notification = createPubSubNotificationSample.CreatePubSubNotification(_fixture.BucketNameGeneric, "my-topic");
40+
deletePubSubNotificationSample.DeletePubSubNotification(_fixture.BucketNameGeneric, notification.Id);
41+
42+
var exception = Assert.Throws<GoogleApiException>(() => getPubSubNotificationSample.GetPubSubNotification(_fixture.BucketNameGeneric, notification.Id));
43+
Assert.Equal(System.Net.HttpStatusCode.NotFound, exception.HttpStatusCode);
44+
45+
}
46+
}
47+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2020 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Text;
18+
using Xunit;
19+
20+
[Collection(nameof(StorageFixture))]
21+
public class GetPubSubNotificationTest
22+
{
23+
private readonly StorageFixture _fixture;
24+
25+
public GetPubSubNotificationTest(StorageFixture fixture)
26+
{
27+
_fixture = fixture;
28+
}
29+
30+
[Fact]
31+
public void GetPubSubNotification()
32+
{
33+
GetPubSubNotificationSample getPubSubNotificationSample = new GetPubSubNotificationSample();
34+
CreatePubSubNotificationSample createPubSubNotificationSample = new CreatePubSubNotificationSample();
35+
36+
var notification = createPubSubNotificationSample.CreatePubSubNotification(_fixture.BucketNameGeneric, "my-topic");
37+
var recievedNotification = getPubSubNotificationSample.GetPubSubNotification(_fixture.BucketNameGeneric, notification.Id);
38+
39+
Assert.NotNull(recievedNotification);
40+
}
41+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2020 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
16+
using Xunit;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Text;
20+
21+
[Collection(nameof(StorageFixture))]
22+
public class ListPubSubNotificationTest
23+
{
24+
private readonly StorageFixture _fixture;
25+
26+
public ListPubSubNotificationTest(StorageFixture fixture)
27+
{
28+
_fixture = fixture;
29+
}
30+
31+
[Fact]
32+
public void ListPubSubNotification()
33+
{
34+
CreatePubSubNotificationSample createPubSubNotificationSample = new CreatePubSubNotificationSample();
35+
ListPubSubNotificationSample listPubSubNotificationSample = new ListPubSubNotificationSample();
36+
37+
var bucketName = Guid.NewGuid().ToString();
38+
_fixture.CreateBucket(bucketName);
39+
40+
createPubSubNotificationSample.CreatePubSubNotification(bucketName, "my-topic");
41+
var listOfPubSubNotifications = listPubSubNotificationSample.ListPubSubNotification(bucketName);
42+
43+
Assert.Contains(listOfPubSubNotifications, x => x.Topic == "my-topic");
44+
}
45+
46+
}

‎storage/api/Storage.Samples.Tests/MakeBucketPublicTest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void MakeBucketPublic()
3636
MakeBucketPublicSample makeBucketPublicSample = new MakeBucketPublicSample();
3737
var bucket = makeBucketPublicSample.MakeBucketPublic(_fixture.BucketNameGeneric);
3838

39-
var bind = storage.GetBucketIamPolicy(bucket).Bindings.Select(y => (y.Role == "roles/storage.legacyBucketReader") && y.Members.Contains("allUsers")).Any();
39+
var bind = storage.GetBucketIamPolicy(bucket).Bindings.Select(y => (y.Role == "roles/storage.objectViewer") && y.Members.Contains("allUsers")).Any();
4040
Assert.True(bind);
4141
}
4242
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2021 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START storage_create_bucket_notifications]
16+
17+
using System;
18+
using Google.Cloud.Storage.V1;
19+
using Google.Apis.Storage.v1.Data;
20+
21+
22+
public class CreatePubSubNotificationSample
23+
{
24+
public Notification CreatePubSubNotification(
25+
string bucketName = "your-unique-bucket-name",
26+
string topic = "my-topic")
27+
{
28+
var storage = StorageClient.Create();
29+
Notification notification = new Notification();
30+
notification.Topic = topic;
31+
var confirmNotification = storage.CreateNotification(bucketName,notification);
32+
33+
Console.WriteLine("Notification subscription created with ID: " + confirmNotification.Id + " for bucket name "+ bucketName);
34+
35+
return confirmNotification;
36+
37+
}
38+
}
39+
40+
// [END storage_create_bucket_notifications]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2021 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START storage_delete_bucket_notification]
16+
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Text;
21+
using Google.Cloud.Storage.V1;
22+
using Google.Apis.Storage.v1.Data;
23+
24+
25+
public class DeletePubSubNotificationSample
26+
{
27+
public void DeletePubSubNotification(
28+
string bucketName = "your-unique-bucket-name",
29+
string notificationId = "notification-Id")
30+
{
31+
var storage = StorageClient.Create();
32+
storage.DeleteNotification(bucketName, notificationId);
33+
34+
Console.WriteLine("Successfully deleted notification with ID " + notificationId +" for bucket "+ bucketName);
35+
}
36+
}
37+
38+
39+
// [END storage_delete_bucket_notification]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2021 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START storage_print_pubsub_bucket_notification]
16+
17+
18+
using System;
19+
using Google.Cloud.Storage.V1;
20+
using Google.Apis.Storage.v1.Data;
21+
22+
public class GetPubSubNotificationSample
23+
{
24+
public Notification GetPubSubNotification(
25+
string bucketName = "your-unique-bucket-name",
26+
string notificationId = "notification-Id")
27+
{
28+
var storage = StorageClient.Create();
29+
var notification = storage.GetNotification(bucketName, notificationId);
30+
31+
Console.WriteLine("ID: "+ notification.Id );
32+
Console.WriteLine("Topic: " + notification.Topic);
33+
Console.WriteLine("EventTypes: " + notification.EventTypes);
34+
Console.WriteLine("CustomAttributes: " + notification.CustomAttributes);
35+
Console.WriteLine("PayloadFormat: " + notification.PayloadFormat);
36+
Console.WriteLine("ObjectNamePrefix: " + notification.ObjectNamePrefix);
37+
Console.WriteLine("ETag: " + notification.ETag);
38+
Console.WriteLine("SelfLink: " + notification.SelfLink);
39+
Console.WriteLine("Kind: " + notification.Kind);
40+
41+
return notification;
42+
}
43+
}
44+
45+
46+
// [END storage_print_pubsub_bucket_notification]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2021 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// [START storage-list-bucket-notifications]
16+
17+
18+
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Text;
22+
using Google.Cloud.Storage.V1;
23+
using Google.Apis.Storage.v1.Data;
24+
25+
26+
public class ListPubSubNotificationSample
27+
{
28+
public IReadOnlyList<Notification> ListPubSubNotification(
29+
string bucketName = "your-unique-bucket-name")
30+
{
31+
var storage = StorageClient.Create();
32+
var notifications = storage.ListNotifications(bucketName);
33+
34+
foreach (var notification in notifications)
35+
Console.WriteLine(notification.Id);
36+
37+
return notifications;
38+
}
39+
}
40+
41+
42+
// [END storage-list-bucket-notifications]

0 commit comments

Comments
 (0)