-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathCloudTests.cs
105 lines (88 loc) · 3.16 KB
/
CloudTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Parse.Abstractions.Infrastructure;
using Parse.Abstractions.Infrastructure.Data;
using Parse.Abstractions.Infrastructure.Execution;
using Parse.Abstractions.Platform.Cloud;
using Parse.Abstractions.Platform.Users;
using Parse.Infrastructure;
using Parse.Infrastructure.Execution;
using Parse.Platform.Cloud;
namespace Parse.Tests;
[TestClass]
public class CloudTests
{
private Mock<IParseCommandRunner> _commandRunnerMock;
private Mock<IParseDataDecoder> _decoderMock;
private MutableServiceHub _hub;
private ParseClient _client;
[TestInitialize]
public void Initialize()
{
_commandRunnerMock = new Mock<IParseCommandRunner>();
_decoderMock = new Mock<IParseDataDecoder>();
}
[TestCleanup]
public void Cleanup()
{
_commandRunnerMock = null;
_decoderMock = null;
_hub = null;
_client = null;
}
private void SetupMocksForMissingResult()
{
_commandRunnerMock
.Setup(runner => runner.RunCommandAsync(
It.IsAny<ParseCommand>(),
It.IsAny<IProgress<IDataTransferLevel>>(),
It.IsAny<IProgress<IDataTransferLevel>>(),
It.IsAny<CancellationToken>()
))
.ReturnsAsync(new Tuple<HttpStatusCode, IDictionary<string, object>>(
HttpStatusCode.OK,
new Dictionary<string, object>
{
["unexpectedKey"] = "unexpectedValue" // Missing "result" key
}));
_decoderMock
.Setup(decoder => decoder.Decode(It.IsAny<object>(), It.IsAny<IServiceHub>()))
.Returns(new Dictionary<string, object> { ["unexpectedKey"] = "unexpectedValue" });
}
[TestMethod]
public async Task TestCloudFunctionsMissingResultAsync()
{
// Arrange
SetupMocksForMissingResult();
_hub = new MutableServiceHub
{
CommandRunner = _commandRunnerMock.Object,
CloudCodeController = new ParseCloudCodeController(_commandRunnerMock.Object, _decoderMock.Object)
};
_client = new ParseClient(new ServerConnectionData { Test = true }, _hub);
// Act & Assert
await Assert.ThrowsExceptionAsync<ParseFailureException>(async () =>
await _client.CallCloudCodeFunctionAsync<IDictionary<string, object>>("someFunction", null, CancellationToken.None));
}
[TestMethod]
public async Task TestParseCloudCodeControllerMissingResult()
{
//Arrange
SetupMocksForMissingResult();
var controller = new ParseCloudCodeController(_commandRunnerMock.Object, _decoderMock.Object);
// Act & Assert
await Assert.ThrowsExceptionAsync<ParseFailureException>(async () =>
await controller.CallFunctionAsync<IDictionary<string, object>>(
"testFunction",
null,
null,
null,
CancellationToken.None));
}
}