forked from jagregory/docu
/
UntransformableResourceManagerTestsBase.cs
117 lines (89 loc) · 3.8 KB
/
UntransformableResourceManagerTestsBase.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
106
107
108
109
110
111
112
113
114
115
116
117
using System.IO;
using Docu.Output;
using NUnit.Framework;
namespace Docu.Tests.Output
{
public abstract class UntransformableResourceManagerTestsBase
{
protected UntransformableResourceManager manager;
protected string template_folder;
protected string output_folder;
[SetUp]
public void setup()
{
create_dummy_folder_structure();
create_resource_manager();
}
private void create_dummy_folder_structure()
{
destroy_dummy_folder_structure();
var temp_path = Path.GetTempPath();
template_folder = Path.Combine(temp_path, Path.GetRandomFileName());
output_folder = Path.Combine(temp_path, Path.GetRandomFileName());
Directory.CreateDirectory(template_folder);
Directory.CreateDirectory(output_folder);
File.WriteAllText(Path.Combine(template_folder, "a_html_page.htm"), "");
File.WriteAllText(Path.Combine(template_folder, "a_css_file.css"), "");
File.WriteAllText(Path.Combine(template_folder, "a_spark_file.spark"), "");
var hiddenFilePath = Path.Combine(template_folder, "hiddenfile.htm");
File.WriteAllText(hiddenFilePath, "");
File.SetAttributes(hiddenFilePath, File.GetAttributes(hiddenFilePath) | FileAttributes.Hidden);
var sub_directory = Path.Combine(template_folder, "sub_directory");
Directory.CreateDirectory(sub_directory);
File.WriteAllText(Path.Combine(sub_directory, "another_html_page.htm"), "");
File.WriteAllText(Path.Combine(sub_directory, "another_spark_file.spark"), "");
var empty_sub_directory = Path.Combine(template_folder, "empty_sub_directory");
Directory.CreateDirectory(empty_sub_directory);
var hiddenDirectory = Path.Combine(template_folder, "hidden_directory");
Directory.CreateDirectory(hiddenDirectory);
File.SetAttributes(hiddenDirectory, File.GetAttributes(hiddenDirectory) | FileAttributes.Hidden);
File.WriteAllText(Path.Combine(hiddenDirectory, "file_in_hidden_dir.htm"), "");
}
private void destroy_dummy_folder_structure()
{
if (Directory.Exists(template_folder))
Directory.Delete(template_folder, true);
if (Directory.Exists(output_folder))
Directory.Delete(output_folder, true);
}
private void create_resource_manager()
{
manager = new UntransformableResourceManager();
}
protected void move_files()
{
manager.MoveResources(template_folder, output_folder);
}
private string GetPath(string path, params string[] paths)
{
var full_path = path;
foreach (var p in paths)
full_path = Path.Combine(full_path, p);
return full_path;
}
protected void file_should_exist(string path, params string[] paths)
{
var full_path = GetPath(path, paths);
File.Exists(full_path)
.ShouldBeTrue();
}
protected void file_shouldnt_exist(string path, params string[] paths)
{
var full_path = GetPath(path, paths);
File.Exists(full_path)
.ShouldBeFalse();
}
protected void directory_should_exist(string path, params string[] paths)
{
var full_path = GetPath(path, paths);
Directory.Exists(full_path)
.ShouldBeTrue();
}
protected void directory_shouldnt_exist(string path, params string[] paths)
{
var full_path = GetPath(path, paths);
Directory.Exists(full_path)
.ShouldBeFalse();
}
}
}