forked from madskristensen/WebCompiler
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathConfigHandlerTest.cs
More file actions
122 lines (91 loc) · 4.86 KB
/
ConfigHandlerTest.cs
File metadata and controls
122 lines (91 loc) · 4.86 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Linq;
using WebCompiler;
namespace WebCompilerTest.Config
{
[TestClass]
public class ConfigHandlerTest
{
private ConfigHandler _handler;
private const string originalConfigFile = "../../artifacts/config/originalcoffeeconfig.json";
private const string processingConfigFile = "../../artifacts/config/coffeeconfig.json";
private const string configFileWithExtensions = "../../artifacts/configwithextensions.json";
[TestInitialize]
public void Setup()
{
_handler = new ConfigHandler();
File.Copy(originalConfigFile, processingConfigFile, true);
}
[TestCleanup]
public void Cleanup()
{
if (File.Exists(processingConfigFile))
File.Delete(processingConfigFile);
}
[TestMethod, TestCategory("Config")]
public void AddConfig()
{
var newConfig = new WebCompiler.Config();
const string newInputFileName = "newInputFile";
newConfig.InputFile = newInputFileName;
_handler.AddConfig(processingConfigFile, newConfig);
var configs = ConfigHandler.GetConfigs(processingConfigFile);
Assert.AreEqual(2, configs.Count());
Assert.AreEqual(newInputFileName, configs.ElementAt(1).InputFile);
}
[TestMethod, TestCategory("Config")]
public void NonExistingConfigFileShouldReturnEmptyList()
{
var expectedResult = Enumerable.Empty<WebCompiler.Config>();
var result = ConfigHandler.GetConfigs("../NonExistingFile.config");
Assert.AreEqual(expectedResult, result);
}
[TestMethod, TestCategory("Config")]
public void GetConfig_WhenExpandExtensionsIsNotProvided_ReturnsConfigsIncludingFilesMatchingExtensions()
{
var configs = ConfigHandler.GetConfigs(configFileWithExtensions);
var configFileFolder = new FileInfo(configFileWithExtensions).DirectoryName;
var test1FilePath = new FileInfo("../../artifacts/scss/test1.razor.scss");
var test2FilePath = new FileInfo("../../artifacts/scss/test2.razor.scss");
var expectedTest1InputFile = test1FilePath.FullName.Replace(configFileFolder, "").Substring(1);
var expectedTest2InputFile = test2FilePath.FullName.Replace(configFileFolder, "").Substring(1);
var test1Config = configs.SingleOrDefault(x => x.IsFromExtensionPattern && x.InputFile == expectedTest1InputFile);
var test2Config = configs.SingleOrDefault(x => x.IsFromExtensionPattern && x.InputFile == expectedTest2InputFile);
Assert.IsNotNull(test1Config);
Assert.IsNotNull(test2Config);
Assert.IsTrue(test1Config.IsFromExtensionPattern);
Assert.IsTrue(test2Config.IsFromExtensionPattern);
Assert.AreEqual(test1Config.OutputFile ,expectedTest1InputFile.Replace(".scss",".css"));
Assert.AreEqual(test2Config.OutputFile , expectedTest2InputFile.Replace(".scss",".css"));
Assert.IsFalse((bool)test1Config.Minify["enabled"]);
Assert.IsFalse((bool)test1Config.Minify["enabled"]);
Assert.AreEqual(3, configs.Count());
Assert.AreEqual(0, configs.Where(x => x.IsExtensionPattern).Count());
}
[TestMethod, TestCategory("Config")]
public void GetConfig_WhenExpandExtensionsIsFalse_ReturnsConfigsWithoutFilesMatchingExtensions()
{
var configs = ConfigHandler.GetConfigs(configFileWithExtensions, expandExtensions: false);
Assert.AreEqual(2, configs.Count());
Assert.AreEqual(1, configs.Where(x => x.IsExtensionPattern).Count());
}
[TestMethod, TestCategory("Config")]
public void GetConfig_WhenExpandExtensionsIsFalseAndSourceFileProvided_ReturnsConfigsWithoutFilesMatchingExtensions()
{
var configs = ConfigHandler.GetConfigs(configFileWithExtensions, sourceFile: "newfile.razor.scss", expandExtensions: false);
Assert.AreEqual(2, configs.Count());
Assert.AreEqual(1, configs.Where(x => x.IsExtensionPattern).Count());
}
[TestMethod, TestCategory("Config")]
public void GetConfig_WhenSourceFileWithValidExtensionIsProvidedAndCacheAlreadyFilled_ReturnsConfigsIncludingFile()
{
var newFile = "newFile.razor.scss";
// trigger loading existing files to dictionary cache
var configs = ConfigHandler.GetConfigs(configFileWithExtensions);
configs = ConfigHandler.GetConfigs(configFileWithExtensions, newFile);
Assert.AreEqual(4, configs.Count());
Assert.AreEqual(1, configs.Where(x => x.InputFile.Contains(newFile)).Count());
}
}
}