-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathFileTests.cs
89 lines (75 loc) · 2.98 KB
/
FileTests.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
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Parse.Abstractions.Infrastructure;
using Parse.Abstractions.Internal;
using Parse.Abstractions.Platform.Files;
using Parse.Abstractions.Platform.Users;
using Parse.Infrastructure;
using Parse.Platform.Files;
namespace Parse.Tests;
[TestClass]
public class FileTests
{
[TestMethod]
public async Task TestFileSaveAsync()
{
// Arrange: Set up mock controllers and client
var mockController = new Mock<IParseFileController>();
mockController
.Setup(obj => obj.SaveAsync(
It.IsAny<FileState>(),
It.IsAny<Stream>(),
It.IsAny<string>(),
It.IsAny<IProgress<IDataTransferLevel>>(),
It.IsAny<CancellationToken>()))
.ReturnsAsync(new FileState
{
Name = "newBekti.png",
Location = new Uri("https://www.parse.com/newBekti.png"),
MediaType = "image/png"
});
var mockCurrentUserController = new Mock<IParseCurrentUserController>();
var client = new ParseClient(
new ServerConnectionData { Test = true },
new MutableServiceHub
{
FileController = mockController.Object,
CurrentUserController = mockCurrentUserController.Object
});
var file = new ParseFile("bekti.jpeg", new MemoryStream(), "image/jpeg");
// Act: Save the file using the Parse client
Assert.AreEqual("bekti.jpeg", file.Name);
Assert.AreEqual("image/jpeg", file.MimeType);
Assert.IsTrue(file.IsDirty);
await file.SaveAsync(client);
// Assert: Verify file properties and state after saving
Assert.AreEqual("newBekti.png", file.Name);
Assert.AreEqual("image/png", file.MimeType);
Assert.AreEqual("https://www.parse.com/newBekti.png", file.Url.AbsoluteUri);
Assert.IsFalse(file.IsDirty);
// Verify the SaveAsync method was called on the mock controller
mockController.Verify(obj => obj.SaveAsync(
It.IsAny<FileState>(),
It.IsAny<Stream>(),
It.IsAny<string>(),
It.IsAny<IProgress<IDataTransferLevel>>(),
It.IsAny<CancellationToken>()), Times.Once);
}
[TestMethod]
public void TestSecureUrl()
{
Uri unsecureUri = new Uri("http://files.parsetfss.com/yolo.txt");
Uri secureUri = new Uri("https://files.parsetfss.com/yolo.txt");
Uri randomUri = new Uri("http://random.server.local/file.foo");
ParseFile file = ParseFileExtensions.Create("Foo", unsecureUri);
Assert.AreEqual(secureUri, file.Url);
file = ParseFileExtensions.Create("Bar", secureUri);
Assert.AreEqual(secureUri, file.Url);
file = ParseFileExtensions.Create("Baz", randomUri);
Assert.AreEqual(randomUri, file.Url);
}
}