-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathLockManagementServiceTests.cs
55 lines (53 loc) · 2.55 KB
/
LockManagementServiceTests.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
using System;
using System.IO;
using System.Threading.Tasks;
using Kiota.Builder.Lock;
using Xunit;
namespace Kiota.Builder.Tests.Lock;
public class LockManagementServiceTests
{
[Fact]
public async Task DefensiveProgramming()
{
var lockManagementService = new LockManagementService();
Assert.Throws<ArgumentNullException>(() => lockManagementService.GetDirectoriesContainingLockFile(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => lockManagementService.GetLockFromDirectoryAsync(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => lockManagementService.GetLockFromStreamAsync(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => lockManagementService.WriteLockFileAsync(null, new KiotaLock()));
await Assert.ThrowsAsync<ArgumentNullException>(() => lockManagementService.WriteLockFileAsync("path", null));
}
[Fact]
public async Task Identity()
{
var lockManagementService = new LockManagementService();
var descriptionPath = Path.Combine(Path.GetTempPath(), "description.yml");
var lockFile = new KiotaLock
{
ClientClassName = "foo",
ClientNamespaceName = "bar",
DescriptionLocation = descriptionPath,
};
var path = Path.GetTempPath();
await lockManagementService.WriteLockFileAsync(path, lockFile);
lockFile.DescriptionLocation = Path.GetFullPath(descriptionPath); // expected since we write the relative path but read to the full path
var result = await lockManagementService.GetLockFromDirectoryAsync(path);
Assert.Equal(lockFile, result, new KiotaLockComparer());
}
[Fact]
public async Task UsesRelativePaths()
{
var tmpPath = Path.Combine(Path.GetTempPath(), "tests", "kiota");
var lockManagementService = new LockManagementService();
var descriptionPath = Path.Combine(tmpPath, "information", "description.yml");
var descriptionDirectory = Path.GetDirectoryName(descriptionPath);
Directory.CreateDirectory(descriptionDirectory);
var lockFile = new KiotaLock
{
DescriptionLocation = descriptionPath,
};
var outputDirectory = Path.Combine(tmpPath, "output");
Directory.CreateDirectory(outputDirectory);
await lockManagementService.WriteLockFileAsync(outputDirectory, lockFile);
Assert.Equal($"..{Path.DirectorySeparatorChar}information{Path.DirectorySeparatorChar}description.yml", lockFile.DescriptionLocation, StringComparer.OrdinalIgnoreCase);
}
}