Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 99e5517e

Přidáno uživatelem Alex Konig před téměř 4 roky(ů)

re #8842 Start testing

Zobrazit rozdíly:

Server/ServerApp.sln
5 5
MinimumVisualStudioVersion = 10.0.40219.1
6 6
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerApp", "ServerApp\ServerApp.csproj", "{18FCFB20-B860-4147-8E7C-8A0DD84C55D4}"
7 7
EndProject
8
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TestProject\TestProject.csproj", "{8A09DB8E-64B1-4D55-991E-7F7B21996B45}"
9
EndProject
8 10
Global
9 11
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 12
		Debug|Any CPU = Debug|Any CPU
......
21 23
		{18FCFB20-B860-4147-8E7C-8A0DD84C55D4}.Release|Any CPU.Build.0 = Release|Any CPU
22 24
		{18FCFB20-B860-4147-8E7C-8A0DD84C55D4}.Release|x64.ActiveCfg = Release|x64
23 25
		{18FCFB20-B860-4147-8E7C-8A0DD84C55D4}.Release|x64.Build.0 = Release|x64
26
		{8A09DB8E-64B1-4D55-991E-7F7B21996B45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27
		{8A09DB8E-64B1-4D55-991E-7F7B21996B45}.Debug|Any CPU.Build.0 = Debug|Any CPU
28
		{8A09DB8E-64B1-4D55-991E-7F7B21996B45}.Debug|x64.ActiveCfg = Debug|Any CPU
29
		{8A09DB8E-64B1-4D55-991E-7F7B21996B45}.Debug|x64.Build.0 = Debug|Any CPU
30
		{8A09DB8E-64B1-4D55-991E-7F7B21996B45}.Release|Any CPU.ActiveCfg = Release|Any CPU
31
		{8A09DB8E-64B1-4D55-991E-7F7B21996B45}.Release|Any CPU.Build.0 = Release|Any CPU
32
		{8A09DB8E-64B1-4D55-991E-7F7B21996B45}.Release|x64.ActiveCfg = Release|Any CPU
33
		{8A09DB8E-64B1-4D55-991E-7F7B21996B45}.Release|x64.Build.0 = Release|Any CPU
24 34
	EndGlobalSection
25 35
	GlobalSection(SolutionProperties) = preSolution
26 36
		HideSolutionNode = FALSE
Server/ServerApp/Parser/OutputInfo/ActivityInfo.cs
11 11
    /// - shortest possible interval is 1h
12 12
    /// </summary>
13 13
    /// <author>A. Konig</author>
14
    class ActivityInfo
14
    public class ActivityInfo
15 15
    {
16 16
        /// <summary> Building </summary>
17 17
        public string building;
Server/ServerApp/Parser/OutputInfo/WeatherInfo.cs
11 11
    /// - shortest possible interval is 1h
12 12
    /// </summary>
13 13
    /// <author>A. Konig</author>
14
    class WeatherInfo
14
    public class WeatherInfo
15 15
    {
16 16
        /// <summary> Temperature in °C </summary>
17 17
        public double temp;
Server/ServerApp/Parser/Parsers/DataParser.cs
17 17
    /// Data parsed from 7am (included) to 18pm (included)
18 18
    /// </summary>
19 19
    /// <author>A. Konig</author>
20
    class DataParser : IDataParser
20
    public class DataParser : IDataParser
21 21
    {
22 22
        /// <summary> Data downloader </summary>
23 23
        DataDownloader downloader;
......
29 29
        /// <summary> Login data parser </summary>
30 30
        LogInParser loginParser;
31 31

  
32
        /// <summary> WeatherInfo </summary>
33
        List<WeatherInfo> weatherList;
34
        public new List<WeatherInfo> WeatherList { get => weatherList; }
35
        /// <summary> ActivityInfo repersenting overall activity </summary>
36
        List<ActivityInfo> attendanceList;
37
        public new List<ActivityInfo> AttendanceList { get => attendanceList; }
38

  
39 32
        /// <summary> ActivityInfo representing jis activity </summary>
40 33
        List<ActivityInfo> jisList;
41 34
        /// <summary> ActivityInfo representing login activity</summary>
......
89 82
            var jisFiles = downloader.GetData(pathJis, start, end);
90 83
            var loginFiles = downloader.GetData(pathLogIn, start, end);
91 84

  
92
            weatherList = weatherParser.ParseWeatherData(weatherFiles, startTime, endTime, wholeDay, interval);
85
            WeatherList = weatherParser.ParseWeatherData(weatherFiles, startTime, endTime, wholeDay, interval);
93 86
            jisList = jisParser.ParseJisData(jisFiles, startTime, endTime, wholeDay, interval);
94 87
            loginList = loginParser.ParseLogInData(loginFiles, startTime, endTime, wholeDay, interval);
95 88

  
......
102 95

  
103 96
            //WriteToConsole(AddListToOne(jisList));
104 97

  
105
            MergeAttendance();
98
            AttendanceList = MergeAttendance(jisList, loginList);
106 99

  
107 100
            //Console.WriteLine("MERGED IN ONE LIST");
108 101
            //WriteToConsole(attendanceList);
109 102

  
110
            if (weatherList.Count == 0 || attendanceList.Count == 0)
103
            if (WeatherList.Count == 0 || AttendanceList.Count == 0)
111 104
                return false;
112 105

  
113 106
            return true;
114 107
        }
115 108

  
109

  
116 110
        /// <summary>
117
        /// Merges ActivityInfo lists with jis and login activity into one
111
        /// Merges two lists into one
118 112
        /// Adds information from the same time period together, doesn't change the rest
119 113
        /// </summary>
120
        private void MergeAttendance()
114
        /// <param name="jisList">List to merge</param>
115
        /// <param name="loginList">List to merge</param>
116
        /// <returns>Merged list</returns>
117
        private List<ActivityInfo> MergeAttendance(List<ActivityInfo> jisList, List<ActivityInfo> loginList)
121 118
        {
122
            attendanceList = new List<ActivityInfo>();
119
            List<ActivityInfo> res = new List<ActivityInfo>();
120

  
121
            if (jisList == null && loginList == null)
122
                return res;
123
            else if (jisList == null)
124
                return loginList;
125
            else if (loginList == null)
126
                return jisList;
123 127

  
124 128
            int indexJis = 0, indexLogin = 0;
125 129
            while (true)
......
139 143
                    if (jisTag == loginTag)
140 144
                    {
141 145
                        jis.amount += login.amount;
142
                        attendanceList.Add(jis);
146
                        res.Add(jis);
143 147
                        indexJis++; indexLogin++;
144 148
                    }
145 149

  
146
                    if (jisTag < loginTag)
150
                    else if (jisTag < loginTag)
147 151
                    {
148 152
                        indexJis++;
149
                        attendanceList.Add(jis);
153
                        res.Add(jis);
150 154
                    }
151 155

  
152
                    if (jisTag > loginTag)
156
                    else if (jisTag > loginTag)
153 157
                    {
154 158
                        indexLogin++;
155
                        attendanceList.Add(login);
159
                        res.Add(login);
156 160
                    }
157 161

  
158 162
                }
159 163

  
160 164
                // if jis time is smaller -> add jis and move
161
                if (jis.startTime < login.startTime)
165
                else if (jis.startTime < login.startTime)
162 166
                {
163 167
                    indexJis++;
164
                    attendanceList.Add(jis);
168
                    res.Add(jis);
165 169
                }
166 170

  
167 171
                // if login time is smaller -> add login and move
168
                if (login.startTime < jis.startTime)
172
                else if (login.startTime < jis.startTime)
169 173
                {
170 174
                    indexLogin++;
171
                    attendanceList.Add(login);
175
                    res.Add(login);
172 176
                }
173 177

  
174 178
            }
175 179

  
180
            return res;
176 181
        }
177 182

  
178 183
        /// <summary>
Server/ServerApp/Parser/Parsers/IDataParser.cs
12 12
    /// Abstract class that every DataParser should inherit from
13 13
    /// </summary>
14 14
    /// <author>A. Konig</author>
15
    abstract class IDataParser
15
    public abstract class IDataParser
16 16
    {
17 17
        /// <summary> WeatherInfo </summary>
18 18
        List<WeatherInfo> weatherList;
19
        public List<WeatherInfo> WeatherList { get => weatherList; }
19
        public List<WeatherInfo> WeatherList { get => weatherList; internal set => weatherList = value; }
20 20
        /// <summary> ActivityInfo repersenting overall activity </summary>
21 21
        List<ActivityInfo> attendanceList;
22
        public List<ActivityInfo> AttendanceList { get => attendanceList; }
22
        public List<ActivityInfo> AttendanceList { get => attendanceList; internal set => attendanceList = value; }
23 23

  
24 24
        /// <summary>
25 25
        /// Parse data
Server/ServerApp/Program.cs
83 83
			jsonP.ParsePrediction();
84 84

  
85 85
			// TODO nastavit čas
86
			DataParser p = new DataParser(dd);
87
			DateTime startT = new DateTime(2019, 10, 5);
88
			DateTime endT = new DateTime(2020, 6, 30);
86
			IDataParser p = new DataParser(dd);
87
			DateTime startT = new DateTime(2018, 6, 5);
88
			DateTime endT = new DateTime(2019, 10, 30);
89 89
			p.Parse(startT, endT, wholeDay: false, interval: 3);
90 90

  
91
			Console.WriteLine(p.WeatherList.Count);
91 92

  
92 93
			// test - connection:
93 94
			//ConnectionListener cl = new ConnectionListener(int.Parse(args[0])/*8000*//*int.Parse(config.Port)*/);
Server/TestProject/Properties/AssemblyInfo.cs
1
using System.Reflection;
2
using System.Runtime.CompilerServices;
3
using System.Runtime.InteropServices;
4

  
5
[assembly: AssemblyTitle("TestProject")]
6
[assembly: AssemblyDescription("")]
7
[assembly: AssemblyConfiguration("")]
8
[assembly: AssemblyCompany("")]
9
[assembly: AssemblyProduct("TestProject")]
10
[assembly: AssemblyCopyright("Copyright ©  2021")]
11
[assembly: AssemblyTrademark("")]
12
[assembly: AssemblyCulture("")]
13

  
14
[assembly: ComVisible(false)]
15

  
16
[assembly: Guid("8a09db8e-64b1-4d55-991e-7f7b21996b45")]
17

  
18
// [assembly: AssemblyVersion("1.0.*")]
19
[assembly: AssemblyVersion("1.0.0.0")]
20
[assembly: AssemblyFileVersion("1.0.0.0")]
Server/TestProject/TestProject.csproj
1
<?xml version="1.0" encoding="utf-8"?>
2
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
  <Import Project="..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" />
4
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5
  <PropertyGroup>
6
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8
    <ProjectGuid>{8A09DB8E-64B1-4D55-991E-7F7B21996B45}</ProjectGuid>
9
    <OutputType>Library</OutputType>
10
    <AppDesignerFolder>Properties</AppDesignerFolder>
11
    <RootNamespace>TestProject</RootNamespace>
12
    <AssemblyName>TestProject</AssemblyName>
13
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
14
    <FileAlignment>512</FileAlignment>
15
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
16
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
17
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
18
    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
19
    <IsCodedUITest>False</IsCodedUITest>
20
    <TestProjectType>UnitTest</TestProjectType>
21
    <NuGetPackageImportStamp>
22
    </NuGetPackageImportStamp>
23
  </PropertyGroup>
24
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
25
    <DebugSymbols>true</DebugSymbols>
26
    <DebugType>full</DebugType>
27
    <Optimize>false</Optimize>
28
    <OutputPath>bin\Debug\</OutputPath>
29
    <DefineConstants>DEBUG;TRACE</DefineConstants>
30
    <ErrorReport>prompt</ErrorReport>
31
    <WarningLevel>4</WarningLevel>
32
    <PlatformTarget>x64</PlatformTarget>
33
  </PropertyGroup>
34
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
35
    <DebugType>pdbonly</DebugType>
36
    <Optimize>true</Optimize>
37
    <OutputPath>bin\Release\</OutputPath>
38
    <DefineConstants>TRACE</DefineConstants>
39
    <ErrorReport>prompt</ErrorReport>
40
    <WarningLevel>4</WarningLevel>
41
  </PropertyGroup>
42
  <ItemGroup>
43
    <Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
44
      <HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
45
    </Reference>
46
    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
47
      <HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
48
    </Reference>
49
    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
50
      <HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
51
    </Reference>
52
    <Reference Include="Moq, Version=4.16.0.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
53
      <HintPath>..\packages\Moq.4.16.1\lib\net45\Moq.dll</HintPath>
54
    </Reference>
55
    <Reference Include="System" />
56
    <Reference Include="System.Configuration" />
57
    <Reference Include="System.Core" />
58
    <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
59
      <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
60
    </Reference>
61
    <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
62
      <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
63
    </Reference>
64
  </ItemGroup>
65
  <ItemGroup>
66
    <Compile Include="TestingParser.cs" />
67
    <Compile Include="Properties\AssemblyInfo.cs" />
68
  </ItemGroup>
69
  <ItemGroup>
70
    <None Include="app.config" />
71
    <None Include="packages.config" />
72
  </ItemGroup>
73
  <ItemGroup>
74
    <ProjectReference Include="..\ServerApp\ServerApp.csproj">
75
      <Project>{18fcfb20-b860-4147-8e7c-8a0dd84c55d4}</Project>
76
      <Name>ServerApp</Name>
77
    </ProjectReference>
78
  </ItemGroup>
79
  <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
80
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
81
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
82
    <PropertyGroup>
83
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
84
    </PropertyGroup>
85
    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props'))" />
86
    <Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets'))" />
87
  </Target>
88
  <Import Project="..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" />
89
</Project>
Server/TestProject/TestingParser.cs
1
using Microsoft.VisualStudio.TestTools.UnitTesting;
2
using System;
3
using ServerApp.Parser.Parsers;
4
using System.Collections.Generic;
5
using ServerApp.Parser.OutputInfo;
6

  
7
namespace TestProject
8
{
9
    [TestClass]
10
    public class TestingParser
11
    {
12
        [TestMethod]
13
        public void AbstactClassTest()
14
        {
15
            IDataParser p = new DataParser(null);
16
            List<ActivityInfo> aa = p.AttendanceList;
17
            List<WeatherInfo> wa = p.WeatherList;
18

  
19
            DataParser pp = (DataParser)p;
20
            List<ActivityInfo> ap = pp.AttendanceList;
21
            List<WeatherInfo> wp = pp.WeatherList;
22

  
23
            Assert.AreEqual(aa, ap);
24
            Assert.AreEqual(wa, wp);
25
        }
26

  
27
        [TestMethod]
28
        public void MergeListsNull()
29
        {
30
            DataParser target = new DataParser(null);
31
            PrivateObject obj = new PrivateObject(target);
32

  
33
            List<ActivityInfo> jis = null;
34
            List<ActivityInfo> pc = null;
35

  
36
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
37
            Assert.AreEqual(0, retVal.Count);
38
        }
39

  
40
        [TestMethod]
41
        public void MergeListsJisNull()
42
        {
43
            DataParser target = new DataParser(null);
44
            PrivateObject obj = new PrivateObject(target);
45

  
46
            List<ActivityInfo> jis = null;
47
            List<ActivityInfo> pc = new List<ActivityInfo>();
48

  
49
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
50
            Assert.AreEqual(pc, retVal);
51
        }
52

  
53
        [TestMethod]
54
        public void MergeListsPcNull()
55
        {
56
            DataParser target = new DataParser(null);
57
            PrivateObject obj = new PrivateObject(target);
58

  
59
            List<ActivityInfo> jis = new List<ActivityInfo>();
60
            List<ActivityInfo> pc = null;
61

  
62
            List<ActivityInfo> retVal = (List<ActivityInfo>)obj.Invoke("MergeAttendance", jis, pc);
63
            Assert.AreEqual(jis, retVal);
64
        }
65
    }
66
}
Server/TestProject/app.config
1
<?xml version="1.0" encoding="utf-8"?>
2
<configuration>
3
  <runtime>
4
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5
      <dependentAssembly>
6
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
7
        <bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
8
      </dependentAssembly>
9
      <dependentAssembly>
10
        <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
11
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
12
      </dependentAssembly>
13
    </assemblyBinding>
14
  </runtime>
15
</configuration>
Server/TestProject/packages.config
1
<?xml version="1.0" encoding="utf-8"?>
2
<packages>
3
  <package id="Castle.Core" version="4.4.0" targetFramework="net472" />
4
  <package id="Moq" version="4.16.1" targetFramework="net472" />
5
  <package id="MSTest.TestAdapter" version="2.1.2" targetFramework="net472" />
6
  <package id="MSTest.TestFramework" version="2.1.2" targetFramework="net472" />
7
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net472" />
8
  <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
9
</packages>

Také k dispozici: Unified diff