Skip to content

Commit 9be5507

Browse files
authored
Merge pull request googleworkspace#96 from RajeshGogo/driveV2snippet
test: create testcase for Drive v2 file snippets
2 parents ddc9892 + 05a06eb commit 9be5507

8 files changed

+151
-8
lines changed

drive/snippets/drive_v2/DriveV2Snippets/UploadBasic.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static string DriveUploadBasic(string filePath)
5353
};
5454
FilesResource.InsertMediaUpload request;
5555
// Create a new file on drive
56-
using (var stream = new FileStream("files/photo.jpg",
56+
using (var stream = new FileStream(filePath,
5757
FileMode.Open))
5858
{
5959
// Create a new file, with metadata and stream.

drive/snippets/drive_v2/DriveV2Snippets/UploadToFolder.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public class UploadToFolder
3030
/// Upload a file to the specified folder.
3131
/// </summary>
3232
/// <param name="folderId"></param>
33+
/// <param name="filePath"></param>
3334
/// <returns>Inserted file metadata if successful, null otherwise</returns>
34-
35-
public File DriveUploadToFolder(string folderId)
35+
public static File DriveUploadToFolder(string folderId, string filePath)
3636
{
3737
try
3838
{
@@ -61,7 +61,7 @@ public File DriveUploadToFolder(string folderId)
6161
};
6262
FilesResource.InsertMediaUpload request;
6363
// Create a new file on drive.
64-
using (var stream = new FileStream("files/photo.jpg", FileMode.Open))
64+
using (var stream = new FileStream(filePath, FileMode.Open))
6565
{
6666
// Create a new file, with metadata and stream
6767
request = service.Files.Insert(

drive/snippets/drive_v2/DriveV2Snippets/UploadWithConversion.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ namespace DriveV2Snippets
2525
// Class to demonstrate Drive's upload with conversion use-case.
2626
public class UploadWithConversion
2727
{
28-
2928
/// <summary>
3029
/// Upload file with conversion.
3130
/// </summary>
31+
/// <param name="filePath"></param>
3232
/// <returns>Inserted file id if successful, null otherwise.</returns>
33-
public static string DriveUploadWithConversion()
33+
public static string DriveUploadWithConversion(string filePath)
3434
{
3535
try
3636
{
@@ -53,7 +53,7 @@ public static string DriveUploadWithConversion()
5353
MimeType = "application/vnd.google-apps.spreadsheet"
5454
};
5555
FilesResource.InsertMediaUpload request;
56-
using (var stream = new FileStream("files/report.csv",
56+
using (var stream = new FileStream(filePath,
5757
FileMode.Open))
5858
{
5959
// Create a new file, with metadata and stream.

drive/snippets/drive_v2/DriveV2SnippetsTest/DriveV2SnippetsTest.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Google.Apis.Drive.v2" Version="1.57.0.2663" />
13+
<PackageReference Include="Google.Apis.Drive.v2" Version="1.57.0.2684" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
1515
<PackageReference Include="NUnit" Version="3.13.2" />
1616
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2022 Google LLC
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+
// https://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 DriveV2Snippets;
16+
using NUnit.Framework;
17+
18+
namespace DriveV2SnippetsTest
19+
{
20+
// Unit testcase for drive v2 share file snippet
21+
[TestFixture]
22+
public class ShareFileTest : BaseTest
23+
{
24+
//TODO(developer) - Provide absolute path of the file
25+
private string filePath = "files/photo.jpg";
26+
27+
[Test]
28+
public void TestShareFile()
29+
{
30+
String fileId = CreateTestBlob(filePath);
31+
var ids = ShareFile.DriveShareFile(fileId,
32+
"user@test.appsdevtesting.com",
33+
"test.appsdevtesting.com");
34+
Assert.AreNotEqual(0, ids.Count);
35+
DeleteFileOnCleanup(fileId);
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2022 Google LLC
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+
// https://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 DriveV2Snippets;
16+
using NUnit.Framework;
17+
18+
namespace DriveV2SnippetsTest
19+
{
20+
// Unit testcase for drive v2 upload basic snippet
21+
[TestFixture]
22+
public class UploadBasicTest : BaseTest
23+
{
24+
//TODO(developer) - Provide absolute path of the file
25+
private string filePath = "files/photo.jpg";
26+
27+
[Test]
28+
public void TestUploadBasic()
29+
{
30+
var id = UploadBasic.DriveUploadBasic(filePath);
31+
Assert.IsNotNull(id);
32+
DeleteFileOnCleanup(id);
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2022 Google LLC
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+
// https://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 DriveV2Snippets;
16+
using NUnit.Framework;
17+
18+
namespace DriveV2SnippetsTest
19+
{
20+
// Unit testcase for drive v2 upload file to folder snippet
21+
[TestFixture]
22+
public class UploadToFolderTest : BaseTest
23+
{
24+
//TODO(developer) - Provide absolute path of the file
25+
private string filePath = "files/photo.jpg";
26+
27+
[Test]
28+
public void TestUploadToFolder()
29+
{
30+
var folderId = CreateFolder.DriveCreateFolder();
31+
var id = UploadToFolder.DriveUploadToFolder(folderId,filePath);
32+
DeleteFileOnCleanup(folderId);
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2022 Google LLC
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+
// https://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 DriveV2Snippets;
16+
using NUnit.Framework;
17+
18+
namespace DriveV2SnippetsTest{
19+
20+
// Unit testcase for drive v2 upload with conversion snippet
21+
[TestFixture]
22+
public class UploadWithConversionTest : BaseTest
23+
{
24+
//TODO(developer) - Provide absolute path of the file
25+
private string filePath = "files/report.csv";
26+
27+
[Test]
28+
public void TestUploadWithConversifon()
29+
{
30+
var id = UploadWithConversion.DriveUploadWithConversion(filePath);
31+
Assert.IsNotNull(id);
32+
DeleteFileOnCleanup(id);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)