Skip to content

Commit ccd0b39

Browse files
Test GetProviderRoot/GetCacheRoot exceptions
1 parent 30f7330 commit ccd0b39

2 files changed

Lines changed: 47 additions & 16 deletions

File tree

tests/ImageSharp.Web.Tests/Caching/PhysicialFileSystemCacheTests.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
45
using SixLabors.ImageSharp.Web.Caching;
56
using Xunit;
67

@@ -31,21 +32,36 @@ public void FilePathMatchesReference(string key, int cacheFolderDepth, string ex
3132
[InlineData("cacheFolder", null, "/Users/WebRoot", null, "/Users/WebRoot/cacheFolder/")]
3233
[InlineData("cacheFolder", "../Temp", null, "/Users/this/a/root", "/Users/this/a/Temp/cacheFolder/")]
3334
#elif OS_WINDOWS
34-
[InlineData("cacheFolder", "C:/Temp", null, null, "C:/Temp\\cacheFolder\\")]
35-
[InlineData("cacheFolder", null, "C:/WebRoot", null, "C:/WebRoot\\cacheFolder\\")]
36-
[InlineData("cacheFolder", "../Temp", null, "C:/this/a/root", "C:\\this\\a\\Temp\\cacheFolder\\")]
35+
[InlineData("cacheFolder", "C:\\Temp", null, null, "C:\\Temp\\cacheFolder\\")]
36+
[InlineData("cacheFolder", null, "C:\\WebRoot", null, "C:\\WebRoot\\cacheFolder\\")]
37+
[InlineData("cacheFolder", "..\\Temp", null, "C:\\this\\a\\root", "C:\\this\\a\\Temp\\cacheFolder\\")]
3738
#endif
38-
public void CacheRootFromOptions(string cacheFolder, string cacheRoot, string webRootPath, string contentRootPath, string expected)
39+
public void GetCacheRoot(string cacheFolder, string cacheRootPath, string webRootPath, string contentRootPath, string expected)
3940
{
4041
var cacheOptions = new PhysicalFileSystemCacheOptions
4142
{
4243
CacheFolder = cacheFolder,
43-
CacheRootPath = cacheRoot
44+
CacheRootPath = cacheRootPath
4445
};
4546

46-
string cacheRootResult = PhysicalFileSystemCache.GetCacheRoot(cacheOptions, webRootPath, contentRootPath);
47+
string actual = PhysicalFileSystemCache.GetCacheRoot(cacheOptions, webRootPath, contentRootPath);
4748

48-
Assert.Equal(expected, cacheRootResult);
49+
Assert.Equal(expected, actual);
50+
}
51+
52+
[Theory]
53+
[InlineData("cacheFolder", null, null, "C:\\root\\")]
54+
[InlineData("cacheFolder", "", null, "C:\\root\\")]
55+
[InlineData("cacheFolder", null, "", "C:\\root\\")]
56+
public void GetCacheRootThrows(string cacheFolder, string cacheRootPath, string webRootPath, string contentRootPath)
57+
{
58+
var cacheOptions = new PhysicalFileSystemCacheOptions
59+
{
60+
CacheFolder = cacheFolder,
61+
CacheRootPath = cacheRootPath
62+
};
63+
64+
Assert.Throws<InvalidOperationException>(() => PhysicalFileSystemCache.GetCacheRoot(cacheOptions, webRootPath, contentRootPath));
4965
}
5066
}
5167
}

tests/ImageSharp.Web.Tests/Providers/PhysicalFileSystemProviderTests.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
45
using SixLabors.ImageSharp.Web.Providers;
56
using Xunit;
67

@@ -22,22 +23,36 @@ public class PhysicalFileSystemProviderTests
2223
[InlineData("../Temp", null, "/Users/this/a/root", "/Users/this/a/Temp/")]
2324
[InlineData("/Users/WebRoot", null, "/Users/this/a/root", "/Users/WebRoot/")]
2425
#elif OS_WINDOWS
25-
[InlineData(null, "wwwroot", "C:/root\\", "C:\\root\\wwwroot\\")]
26-
[InlineData(null, "C:/WebRoot", "C:/root\\", "C:/WebRoot\\")]
27-
[InlineData("providerFolder", "../Temp", "C:/this/a/root", "C:\\this\\a\\root\\providerFolder\\")]
28-
[InlineData("../Temp", null, "C:/this/a/root", "C:\\this\\a\\Temp\\")]
29-
[InlineData("C:/WebRoot", null, "C:/this/a/root", "C:/WebRoot\\")]
26+
[InlineData(null, "wwwroot", "C:\\root\\", "C:\\root\\wwwroot\\")]
27+
[InlineData(null, "C:\\WebRoot", "C:\\root\\", "C:\\WebRoot\\")]
28+
[InlineData("providerFolder", "..\\Temp", "C:\\this\\a\\root", "C:\\this\\a\\root\\providerFolder\\")]
29+
[InlineData("..\\Temp", null, "C:\\this\\a\\root", "C:\\this\\a\\Temp\\")]
30+
[InlineData("C:\\WebRoot", null, "C:\\this\\a\\root", "C:\\WebRoot\\")]
3031
#endif
31-
public void ProvidersRootFromOptions(string providerRoot, string webRootPath, string contentRootPath, string expected)
32+
public void GetProviderRoot(string providerRootPath, string webRootPath, string contentRootPath, string expected)
3233
{
3334
var providerOptions = new PhysicalFileSystemProviderOptions
3435
{
35-
ProviderRootPath = providerRoot,
36+
ProviderRootPath = providerRootPath
3637
};
3738

38-
string providerRootResult = PhysicalFileSystemProvider.GetProviderRoot(providerOptions, webRootPath, contentRootPath);
39+
string actual = PhysicalFileSystemProvider.GetProviderRoot(providerOptions, webRootPath, contentRootPath);
3940

40-
Assert.Equal(expected, providerRootResult);
41+
Assert.Equal(expected, actual);
42+
}
43+
44+
[Theory]
45+
[InlineData(null, null, "C:\\root\\")]
46+
[InlineData("", null, "C:\\root\\")]
47+
[InlineData(null, "", "C:\\root\\")]
48+
public void GetProviderRootThrows(string providerRootPath, string webRootPath, string contentRootPath)
49+
{
50+
var providerOptions = new PhysicalFileSystemProviderOptions
51+
{
52+
ProviderRootPath = providerRootPath
53+
};
54+
55+
Assert.Throws<InvalidOperationException>(() => PhysicalFileSystemProvider.GetProviderRoot(providerOptions, webRootPath, contentRootPath));
4156
}
4257
}
4358
}

0 commit comments

Comments
 (0)