Skip to content

Commit a3da84c

Browse files
committed
Updated sources
1 parent 8e5cd2d commit a3da84c

5 files changed

Lines changed: 248 additions & 5 deletions

File tree

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright company="Aspose Pty Ltd">
3+
// Copyright (c) 2003-2022 Aspose Pty Ltd
4+
// </copyright>
5+
// <summary>
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
// </summary>
24+
// --------------------------------------------------------------------------------------------------------------------
25+
26+
using GroupDocs.Conversion.Cloud.Sdk.Api;
27+
using GroupDocs.Conversion.Cloud.Sdk.Client;
28+
using GroupDocs.Conversion.Cloud.Sdk.Model.Requests;
29+
30+
namespace GroupDocs.Conversion.Cloud.Sdk.Test.Api
31+
{
32+
using GroupDocs.Conversion.Cloud.Sdk.Test.Api.Internal;
33+
using Newtonsoft.Json;
34+
using NUnit.Framework;
35+
using System.IO;
36+
using System.Reflection;
37+
using System.Text;
38+
using System;
39+
using GroupDocs.Conversion.Cloud.Sdk.Model;
40+
41+
public class ThirdPartyStorageTests
42+
{
43+
private readonly string _appSid = Config.AppSid;
44+
private readonly string _appKey = Config.AppKey;
45+
private readonly string _apiBaseUrl = Config.ApiBaseUrl;
46+
47+
protected ConvertApi ConvertApi;
48+
protected InfoApi InfoApi;
49+
protected FileApi FileApi;
50+
protected FolderApi FolderApi;
51+
protected StorageApi StorageApi;
52+
53+
[OneTimeSetUp]
54+
public void BeforeAllTests()
55+
{
56+
var config = new Configuration(_appSid, _appKey)
57+
{
58+
ApiBaseUrl = _apiBaseUrl
59+
};
60+
61+
ConvertApi = new ConvertApi(config);
62+
InfoApi = new InfoApi(config);
63+
FileApi = new FileApi(config);
64+
FolderApi = new FolderApi(config);
65+
StorageApi = new StorageApi(config);
66+
}
67+
68+
/// <summary>
69+
/// Test Conversion using Third Party Storage
70+
/// </summary>
71+
[Test]
72+
public void TestConversionAtThirdPartyStorage()
73+
{
74+
var testFile = TestFiles.FourPagesDocx;
75+
var storageName = "week";
76+
var targetFormat = "pdf";
77+
78+
var deleteRequest = new DeleteFileRequest { path = testFile.FullName, storageName = storageName };
79+
var existsRequest = new ObjectExistsRequest { path = testFile.FullName, storageName = storageName };
80+
var uploadRequest = new UploadFileRequest(testFile.FullName, GetTestFileStream(testFile), storageName);
81+
82+
FileApi.DeleteFile(deleteRequest);
83+
var response = StorageApi.ObjectExists(existsRequest);
84+
Assert.IsFalse(response.Exists);
85+
FileApi.UploadFile(uploadRequest);
86+
response = StorageApi.ObjectExists(existsRequest);
87+
Assert.IsTrue(response.Exists);
88+
89+
var settings = new ConvertSettings
90+
{
91+
FilePath = testFile.FullName,
92+
StorageName = storageName,
93+
Format = targetFormat,
94+
OutputPath = "converted.pdf"
95+
};
96+
97+
var result = ConvertApi.ConvertDocument(new ConvertDocumentRequest(settings));
98+
99+
Assert.NotNull(result);
100+
Assert.Greater(result.Count, 0);
101+
var convertedExtension = Path.GetExtension(result[0].Name);
102+
Assert.NotNull(convertedExtension);
103+
Assert.AreEqual(targetFormat, convertedExtension.Substring(1));
104+
105+
var request = new DownloadFileRequest { path = result[0].Path, storageName = storageName };
106+
107+
var dResponse = FileApi.DownloadFile(request);
108+
Assert.Greater(dResponse.Length, 0);
109+
}
110+
111+
112+
113+
////////////////////////////////////////////////////////////////////////////////////////////////////////
114+
private byte[] GetTestFileBytes(TestFile file)
115+
{
116+
var filePath = Path.Combine(GetTestDataPath(), file.Folder, file.FileName);
117+
if (!File.Exists(filePath))
118+
{
119+
throw new FileNotFoundException("File not found: " + filePath);
120+
}
121+
122+
return File.ReadAllBytes(filePath);
123+
}
124+
125+
protected Stream GetTestFileStream(TestFile file)
126+
{
127+
var bytes = GetTestFileBytes(file);
128+
129+
return new MemoryStream(bytes);
130+
}
131+
132+
// ReSharper disable once UnusedMember.Global
133+
protected Stream SerializeObject(object obj)
134+
{
135+
var options = new JsonSerializerSettings
136+
{
137+
NullValueHandling = NullValueHandling.Ignore
138+
};
139+
var json = JsonConvert.SerializeObject(obj, options);
140+
141+
var bytes = Encoding.UTF8.GetBytes(json);
142+
143+
return new MemoryStream(bytes);
144+
}
145+
146+
private static string GetTestDataPath()
147+
{
148+
var uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
149+
var workingDir = Path.GetDirectoryName(uri.LocalPath) ?? Directory.GetCurrentDirectory();
150+
151+
var baseDir = Path.Combine(workingDir, "Resources", "TestData");
152+
153+
return Path.GetFullPath(baseDir);
154+
}
155+
}
156+
}

src/GroupDocs.Conversion.Cloud.Sdk.Test/GroupDocs.Conversion.Cloud.Sdk.Test.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net46</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
55
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
66
<Company>GroupDocs</Company>
77
<Authors>GroupDocs Product Team</Authors>
@@ -10,7 +10,8 @@
1010
<ItemGroup>
1111
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
1212
<PackageReference Include="NUnit" Version="3.13.2" />
13-
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
13+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
1415
</ItemGroup>
1516
<ItemGroup>
1617
<ProjectReference Include="..\GroupDocs.Conversion.Cloud.Sdk\GroupDocs.Conversion.Cloud.Sdk.csproj" />

src/GroupDocs.Conversion.Cloud.Sdk/GroupDocs.Conversion.Cloud.Sdk.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;net20</TargetFrameworks>
5-
<AssemblyVersion>22.3.0.0</AssemblyVersion>
6-
<FileVersion>22.3.0.0</FileVersion>
7-
<Version>22.3.0</Version>
5+
<AssemblyVersion>22.10.0.0</AssemblyVersion>
6+
<FileVersion>22.10.0.0</FileVersion>
7+
<Version>22.10.0</Version>
88
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
99
<Company>GroupDocs</Company>
1010
<Authors>GroupDocs Product Team</Authors>

src/GroupDocs.Conversion.Cloud.Sdk/GroupDocs.Conversion.Cloud.Sdk.xml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright company="Aspose Pty Ltd" file="PersonalStorageLoadOptions.cs">
3+
// Copyright (c) 2003-2022 Aspose Pty Ltd
4+
// </copyright>
5+
// <summary>
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
// </summary>
24+
// --------------------------------------------------------------------------------------------------------------------
25+
26+
namespace GroupDocs.Conversion.Cloud.Sdk.Model
27+
{
28+
using System;
29+
using System.Collections;
30+
using System.Collections.Generic;
31+
using System.Runtime.Serialization;
32+
using System.Text;
33+
using Newtonsoft.Json;
34+
using Newtonsoft.Json.Converters;
35+
36+
/// <summary>
37+
/// Options for loading personal storage documents.
38+
/// </summary>
39+
public class PersonalStorageLoadOptions : LoadOptions
40+
{
41+
/// <summary>
42+
/// Folder which to be processed Default is Inbox
43+
/// </summary>
44+
public string Folder { get; set; }
45+
46+
/// <summary>
47+
/// Controls how many levels in depth to perform conversion
48+
/// </summary>
49+
public int? Depth { get; set; }
50+
51+
/// <summary>
52+
/// Get the string presentation of the object
53+
/// </summary>
54+
/// <returns>String presentation of the object</returns>
55+
public override string ToString()
56+
{
57+
var sb = new StringBuilder();
58+
sb.Append("class PersonalStorageLoadOptions {\n");
59+
sb.Append(" Folder: ").Append(this.Folder).Append("\n");
60+
sb.Append(" Depth: ").Append(this.Depth).Append("\n");
61+
sb.Append("}\n");
62+
return sb.ToString();
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)