Skip to content

Commit 17a036e

Browse files
[TASKSCLOUD-248] - Added new tests, changed some other tests due to increase DocumentProperties count.
1 parent 808d562 commit 17a036e

File tree

7 files changed

+98
-15
lines changed

7 files changed

+98
-15
lines changed

Aspose.Tasks.Cloud.Sdk.Tests/Aspose.Tasks.Cloud.Sdk.Tests.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Aspose.Tasks.Cloud.Sdk.Tests</RootNamespace>
1111
<AssemblyName>Aspose.Tasks.Cloud.Sdk.Tests</AssemblyName>
12-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<TargetFrameworkProfile />
1515
</PropertyGroup>
@@ -52,6 +52,7 @@
5252
<Compile Include="Calendar\TestCalendars.cs" />
5353
<Compile Include="ExtendedAttributes\TestExtendedAttributes.cs" />
5454
<Compile Include="OutlineCodes\TestOutlineCodes.cs" />
55+
<Compile Include="ProjectOnline\TestProjectList.cs" />
5556
<Compile Include="Project\TestTaskDocumentFormat.cs" />
5657
<Compile Include="Project\TestGetPageCount.cs" />
5758
<Compile Include="Project\TestImportProject.cs" />
@@ -84,6 +85,10 @@
8485
<Project>{11cda7d7-4e13-4946-bdc7-7178115f35dd}</Project>
8586
<Name>Aspose.Tasks.Cloud.Sdk</Name>
8687
</ProjectReference>
88+
<ProjectReference Include="..\Aspose.Tasks.Cloud.Sdk\Aspose.Tasks.Cloud.Sdk.csproj">
89+
<Project>{11cda7d7-4e13-4946-bdc7-7178115f35dd}</Project>
90+
<Name>Aspose.Tasks.Cloud.Sdk</Name>
91+
</ProjectReference>
8792
</ItemGroup>
8893
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8994
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

Aspose.Tasks.Cloud.Sdk.Tests/Assignment/TestAssignments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
namespace Aspose.Tasks.Cloud.Sdk.Tests.Tasks
3838
{
39+
3940
[TestFixture]
4041
public class TestAssignments : BaseTestContext
4142
{
@@ -49,7 +50,6 @@ public void TestGetAssignments()
4950
Name = remoteName,
5051
Folder = this.DataFolder
5152
});
52-
5353
Assert.AreEqual((int)HttpStatusCode.OK, response.Code);
5454
Assert.IsNotNull(response.Assignments);
5555
Assert.AreEqual(6, response.Assignments.AssignmentItem.Count);

Aspose.Tasks.Cloud.Sdk.Tests/Base/BaseTestContext.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ protected BaseTestContext()
5959

6060
var configuration = new Configuration { ApiBaseUrl = BaseProductUri, AppKey = this.keys.AppKey, AppSid = this.keys.AppSid };
6161
this.TasksApi = new TasksApi(configuration);
62-
this.StorageApi = new StorageApi(configuration);
6362
clearingRequests = new List<DeleteRequest>();
6463
}
6564

@@ -68,7 +67,7 @@ public void Clean()
6867
{
6968
foreach (var request in clearingRequests)
7069
{
71-
var response = this.StorageApi.DeleteFile(request);
70+
var response = this.TasksApi.DeleteFile(request);
7271
Assert.That(response, Is.Not.Null.And.Property("Code").EqualTo(200));
7372
}
7473
}
@@ -86,7 +85,7 @@ protected string UploadFileToStorage(string localName)
8685
{
8786

8887
var postRequest = new PostCreateRequest(fullName, fileStream, storage: "Tasks");
89-
var response = this.StorageApi.UploadFile(postRequest);
88+
var response = this.TasksApi.UploadFile(postRequest);
9089
PrepareClearingRequest(postRequest);
9190

9291
}
@@ -122,11 +121,6 @@ protected static string BaseTestDataPath
122121

123122
protected string DataFolder => Path.Combine(BaseTestDataPath, this.GetType().Name);
124123

125-
/// <summary>
126-
/// Storage API
127-
/// </summary>
128-
protected StorageApi StorageApi { get; set; }
129-
130124
/// <summary>
131125
/// Tasks API
132126
/// </summary>

Aspose.Tasks.Cloud.Sdk.Tests/BasicApiTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222
// SOFTWARE.
2323
// </summary>
2424
// --------------------------------------------------------------------------------------------------------------------
25+
26+
using System;
27+
using System.Collections.Generic;
2528
using Aspose.Tasks.Cloud.Sdk.Model.Requests;
2629
using Aspose.Tasks.Cloud.Sdk.Tests.Base;
2730
using NUnit.Framework;
2831
using System.IO;
2932
using System.Linq;
3033
using System.Text;
34+
using System.Threading.Tasks;
35+
using NUnit.Compatibility;
3136

3237
namespace Aspose.Tasks.Cloud.Sdk.Tests
3338
{
@@ -53,7 +58,7 @@ public void TestHandleNonExistingFile()
5358
public void TestApiCoverage()
5459
{
5560
var methods = typeof(TasksApi).GetMethods()
56-
.Where(p => p.IsPublic && p.DeclaringType != typeof(object))
61+
.Where(p => p.IsPublic && p.DeclaringType != typeof(object) && !p.Name.Contains("Async"))
5762
.Select(p => p.Name)
5863
.ToList();
5964
var unitTestFolder = DirectoryHelper.GetRootSdkFolder();
@@ -70,5 +75,23 @@ public void TestApiCoverage()
7075

7176
Assert.IsTrue(strBuilder.Length == 0, strBuilder.ToString());
7277
}
78+
79+
/// <summary>
80+
/// Check if all API methods have covered by tests
81+
/// </summary>
82+
[Test]
83+
public void TestApiSyncAndAsyncMethodsEquivalence()
84+
{
85+
var allMethods = typeof(TasksApi).GetMethods().Where(m => m.DeclaringType != typeof(object));
86+
var asyncMethods = allMethods.Where(p => p.IsPublic
87+
&& p.ReturnType.IsGenericType
88+
&& p.ReturnType.GetGenericTypeDefinition() == typeof(Task<>));
89+
90+
var asyncMethodsWithWrongNamePattern = asyncMethods.Select(m => m.Name).Where(n => !n.Contains("Async"));
91+
Assert.That(asyncMethodsWithWrongNamePattern, Is.Empty);
92+
93+
var syncMethods = allMethods.Except(asyncMethods);
94+
Assert.AreEqual(syncMethods.Count(), asyncMethods.Count());
95+
}
7396
}
7497
}

Aspose.Tasks.Cloud.Sdk.Tests/DocumentProperties/TestDocumentProperties.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void TestGetDocumentProperties()
4949
});
5050

5151
Assert.AreEqual((int)HttpStatusCode.OK, response.Code);
52-
Assert.AreEqual(49, response.Properties.List.Count);
52+
Assert.AreEqual(51, response.Properties.List.Count);
5353
Assert.AreEqual("Title", response.Properties.List[0].Name);
5454
Assert.AreEqual("Home Move", response.Properties.List[0].Value);
5555
}
@@ -96,7 +96,7 @@ public void TestEditDocumentProperty()
9696
});
9797

9898
Assert.AreEqual((int)HttpStatusCode.OK, response.Code);
99-
Assert.AreEqual(49, response.Properties.List.Count);
99+
Assert.AreEqual(51, response.Properties.List.Count);
100100
Assert.AreEqual("Title", response.Properties.List[0].Name);
101101
Assert.AreEqual("New title value", response.Properties.List[0].Value);
102102
}
@@ -125,7 +125,7 @@ public void TestEditDocumentPropertyViaPost()
125125
});
126126

127127
Assert.AreEqual((int)HttpStatusCode.OK, response.Code);
128-
Assert.AreEqual(49, response.Properties.List.Count);
128+
Assert.AreEqual(51, response.Properties.List.Count);
129129
Assert.AreEqual("Title", response.Properties.List[0].Name);
130130
Assert.AreEqual("New title value", response.Properties.List[0].Value);
131131
}
@@ -154,7 +154,7 @@ public void TestAddNonExistingDocumentProperty()
154154
});
155155

156156
Assert.AreEqual((int)HttpStatusCode.OK, response.Code);
157-
Assert.AreEqual(49, response.Properties.List.Count);
157+
Assert.AreEqual(51, response.Properties.List.Count);
158158
Assert.IsNull(response.Properties.List.Where(p => p.Name == "new property").FirstOrDefault());
159159
}
160160
}

Aspose.Tasks.Cloud.Sdk.Tests/Project/TestImportProject.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@
2323
// </summary>
2424
// --------------------------------------------------------------------------------------------------------------------
2525

26+
using System;
27+
using System.Collections.Generic;
28+
using System.IO;
2629
using System.Net;
2730

2831
using Aspose.Tasks.Cloud.Sdk.Tests.Base;
2932
using Aspose.Tasks.Cloud.Sdk.Model.Requests;
3033
using NUnit.Framework;
3134
using Aspose.Tasks.Cloud.Sdk.Model;
35+
using Newtonsoft.Json;
3236

3337
namespace Aspose.Tasks.Cloud.Sdk.Tests.Project
3438
{
@@ -88,5 +92,37 @@ public void TestImportFromMsp()
8892
Assert.AreEqual((int)HttpStatusCode.OK, getProjectIdsResponse.Code);
8993
CollectionAssert.AreEquivalent(new string[] { "1" }, getProjectIdsResponse.ProjectIds);
9094
}
95+
96+
97+
[Test]
98+
[Ignore("Ignored because real credentials for project server online is required.")]
99+
public void TestImportFromProjectOnline()
100+
{
101+
var fileName = "NewProductDev.mpp";
102+
var getFileRequest = new DownloadFileRequest
103+
{
104+
Path = fileName
105+
};
106+
var importFileRequest = new PutImportProjectFromProjectOnlineRequest
107+
{
108+
Name = fileName,
109+
Guid = Guid.Parse("E6426C44-D6CB-4B9C-AF16-48910ACE0F54"),
110+
Token = "SOMESECRETTOKEN",
111+
SiteUrl = "https://your_company_name.sharepoint.com",
112+
Format = ProjectFileFormat.Xml
113+
};
114+
Stream binaryResponse = null;
115+
116+
var exception = Assert.Throws<ApiException>(() => binaryResponse = TasksApi.DownloadFile(getFileRequest));
117+
Assert.AreEqual(HttpStatusCode.NotFound, exception.HttpStatusCode);
118+
119+
var response = TasksApi.PutImportProjectFromProjectOnline(importFileRequest);
120+
Assert.AreEqual(HttpStatusCode.OK.ToString(), (string)response.Status);
121+
122+
Assert.DoesNotThrow(() => binaryResponse = TasksApi.DownloadFile(getFileRequest));
123+
Assert.That(binaryResponse, Is.Not.Null);
124+
125+
TasksApi.DeleteFile((new DeleteRequest(fileName)));
126+
}
91127
}
92128
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Net;
2+
using Aspose.Tasks.Cloud.Sdk.Model.Requests;
3+
using Aspose.Tasks.Cloud.Sdk.Tests.Base;
4+
using NUnit.Framework;
5+
6+
namespace Aspose.Tasks.Cloud.Sdk.Tests.ProjectOnline
7+
{
8+
[TestFixture]
9+
internal sealed class TestProjectList : BaseTestContext
10+
{
11+
[Test]
12+
[Ignore("Ignored because real credentials for project server online is required.")]
13+
public void TestGetProjectList()
14+
{
15+
var response = TasksApi.GetProjectList(new GetProjectListRequest
16+
{
17+
Token = "SOMESECRETTOKEN",
18+
SiteUrl = "https://your_company_name.sharepoint.com"
19+
});
20+
21+
Assert.AreEqual((int)HttpStatusCode.OK, response.Code);
22+
Assert.That(response.Projects, Is.Not.Empty);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)