1
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2
|
using ServerApp.DataDownload;
|
3
|
using System;
|
4
|
using System.Collections.Generic;
|
5
|
using System.IO;
|
6
|
using System.Linq;
|
7
|
using System.Text;
|
8
|
using System.Threading.Tasks;
|
9
|
|
10
|
namespace ServerAppFunctionalTests.DownloaderTests
|
11
|
{
|
12
|
[TestClass]
|
13
|
public class DataDownloaderTesting
|
14
|
{
|
15
|
static DataDownloader dd;
|
16
|
[ClassInitialize]
|
17
|
public static void SetUpClass(TestContext context)
|
18
|
{
|
19
|
dd = new DataDownloader("./testDD", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1"); ;
|
20
|
}
|
21
|
|
22
|
[TestMethod]
|
23
|
public void DirectoryCreated()
|
24
|
{
|
25
|
bool rootDirExists = Directory.Exists(dd.RootDataDirectory);
|
26
|
Assert.IsTrue(rootDirExists);
|
27
|
}
|
28
|
|
29
|
[TestMethod]
|
30
|
public void DataSubdirectoriesCreated()
|
31
|
{
|
32
|
bool jisDirExists = Directory.Exists(dd.DataSubDirectories[DataType.JIS]);
|
33
|
bool pcDirExists = Directory.Exists(dd.DataSubDirectories[DataType.STROJE]);
|
34
|
bool weatherDirExists = Directory.Exists(dd.DataSubDirectories[DataType.POCASI]);
|
35
|
// other sub dirs aren't that important
|
36
|
|
37
|
bool allTrue = jisDirExists && pcDirExists && weatherDirExists;
|
38
|
Assert.IsTrue(allTrue);
|
39
|
}
|
40
|
|
41
|
[TestMethod]
|
42
|
public void DataDownload()
|
43
|
{
|
44
|
// TODO split asserts
|
45
|
|
46
|
// I know a file with this date is stored at the website:
|
47
|
List<string> files = dd.DownloadData(DataType.JIS, DataFormat.CSV, new Date(10, 2019), new Date(10, 2019));
|
48
|
Assert.IsNotNull(files);
|
49
|
|
50
|
// we expect 2, because the 00 file will be found as well
|
51
|
Assert.AreEqual(2, files.Count);
|
52
|
}
|
53
|
|
54
|
[TestMethod]
|
55
|
public void DataRetrieveSpecific()
|
56
|
{
|
57
|
// TODO split asserts
|
58
|
|
59
|
List<string> files = dd.GetData(dd.DataSubDirectories[DataType.JIS], new Date(10, 2019), new Date(10, 2019));
|
60
|
string expectedName = "10-2019.CSV";
|
61
|
Assert.IsNotNull(files);
|
62
|
Assert.AreEqual(1, files.Count);
|
63
|
Assert.AreEqual(expectedName, Path.GetFileName(files[0]));
|
64
|
}
|
65
|
|
66
|
[TestMethod]
|
67
|
public void DataRetrieveAll()
|
68
|
{
|
69
|
List<string> files = dd.GetData(dd.DataSubDirectories[DataType.JIS], null, null);
|
70
|
Assert.IsNotNull(files);
|
71
|
Assert.AreEqual(2, files.Count);
|
72
|
}
|
73
|
|
74
|
[TestMethod]
|
75
|
public void DateCompare()
|
76
|
{
|
77
|
|
78
|
}
|
79
|
|
80
|
[TestMethod]
|
81
|
public void WeatherPredictionDownload()
|
82
|
{
|
83
|
string weatherJson = dd.DownloadWeatherPrediction();
|
84
|
Assert.IsNotNull(weatherJson);
|
85
|
}
|
86
|
|
87
|
|
88
|
//[AssemblyCleanup]
|
89
|
//public static void AssemblyCleanup()
|
90
|
//{
|
91
|
// try
|
92
|
// {
|
93
|
// Directory.Delete(dd.RootDataDirectory, true);
|
94
|
// }
|
95
|
// catch (DirectoryNotFoundException dnfe)
|
96
|
// {
|
97
|
|
98
|
// }
|
99
|
//}
|
100
|
}
|
101
|
}
|