aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2018-03-16 21:40:28 +0100
committermarcinzelent <zelent.marcin@gmail.com>2018-03-16 21:40:28 +0100
commit08e7a82cc7b237e550c0236bebd4f41c3c3f4acf (patch)
tree30e2320d62f2bf3981120ad76f2de92efec1e8f5 /PollutometerWebApi.Tests
parent9441b9d8b3035dc3142234dd13a1bcea21e72749 (diff)
Moved API to separate folder.
Diffstat (limited to 'PollutometerWebApi.Tests')
-rw-r--r--PollutometerWebApi.Tests/AqiCalculatorTests.cs51
-rw-r--r--PollutometerWebApi.Tests/EmailSenderTests.cs21
-rw-r--r--PollutometerWebApi.Tests/PollutometerWebApi.Tests.csproj125
-rw-r--r--PollutometerWebApi.Tests/Properties/AssemblyInfo.cs36
-rw-r--r--PollutometerWebApi.Tests/ReadingsControllerTests.cs116
-rw-r--r--PollutometerWebApi.Tests/SqlOperatorTests.cs68
-rw-r--r--PollutometerWebApi.Tests/app.config11
-rw-r--r--PollutometerWebApi.Tests/packages.config10
8 files changed, 0 insertions, 438 deletions
diff --git a/PollutometerWebApi.Tests/AqiCalculatorTests.cs b/PollutometerWebApi.Tests/AqiCalculatorTests.cs
deleted file mode 100644
index e84b687..0000000
--- a/PollutometerWebApi.Tests/AqiCalculatorTests.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using PollutometerWebApi.Models;
-
-namespace PollutometerWebApi.Tests
-{
- [TestClass()]
- public class AqiCalculatorTests
- {
- [TestMethod()]
- public void CalculateAqiPerfectTest()
- {
- var reading = new Reading
- {
- Co = 2.2,
- No = 0.1,
- So = 0.8
- };
-
- var result = AqiCalculator.CalculateAqi(reading);
- Assert.AreEqual(398.0100502512563, result.Value);
- }
-
- [TestMethod()]
- public void CalculateAqiBigNumbersTest()
- {
- var reading = new Reading
- {
- Co = 100.2,
- No = 100.1,
- So = 100.8
- };
-
- var result = AqiCalculator.CalculateAqi(reading);
- Assert.AreEqual(0, result.Value);
- }
-
- [TestMethod()]
- public void CalculateAqiZerosTest()
- {
- var reading = new Reading
- {
- Co = 0,
- No = 0,
- So = 0
- };
-
- var result = AqiCalculator.CalculateAqi(reading);
- Assert.AreEqual(0, result.Value);
- }
- }
-} \ No newline at end of file
diff --git a/PollutometerWebApi.Tests/EmailSenderTests.cs b/PollutometerWebApi.Tests/EmailSenderTests.cs
deleted file mode 100644
index 427ec92..0000000
--- a/PollutometerWebApi.Tests/EmailSenderTests.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using PollutometerWebApi.Models;
-
-namespace PollutometerWebApi.Tests
-{
- [TestClass()]
- public class EmailSenderTests
- {
- [TestMethod()]
- public void SendEmailTest()
- {
- var aqi = new Aqi
- {
- GasName = "SO",
- Value = 69,
- Level = "Moderate"
- };
- EmailSender.SendEmail(aqi);
- }
- }
-} \ No newline at end of file
diff --git a/PollutometerWebApi.Tests/PollutometerWebApi.Tests.csproj b/PollutometerWebApi.Tests/PollutometerWebApi.Tests.csproj
deleted file mode 100644
index 6ff37aa..0000000
--- a/PollutometerWebApi.Tests/PollutometerWebApi.Tests.csproj
+++ /dev/null
@@ -1,125 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" />
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProjectGuid>{94A21C38-920E-42EF-8D48-B133D635EAFA}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>PollutometerWebApi.Tests</RootNamespace>
- <AssemblyName>PollutometerWebApi.Tests</AssemblyName>
- <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
- <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
- <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
- <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
- <IsCodedUITest>False</IsCodedUITest>
- <TestProjectType>UnitTest</TestProjectType>
- <TargetFrameworkProfile />
- <NuGetPackageImportStamp>
- </NuGetPackageImportStamp>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
- </Reference>
- <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
- </Reference>
- <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
- <HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
- <Private>True</Private>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Net.Http" />
- <Reference Include="System.Net.Http.Formatting, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.0\lib\net45\System.Net.Http.Formatting.dll</HintPath>
- </Reference>
- <Reference Include="System.Transactions" />
- <Reference Include="System.Web.Http, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.0\lib\net45\System.Web.Http.dll</HintPath>
- </Reference>
- <Reference Include="System.Web.Http.WebHost, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
- <HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.0\lib\net45\System.Web.Http.WebHost.dll</HintPath>
- </Reference>
- </ItemGroup>
- <Choose>
- <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
- <ItemGroup>
- <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
- </ItemGroup>
- </When>
- <Otherwise />
- </Choose>
- <ItemGroup>
- <Compile Include="AqiCalculatorTests.cs" />
- <Compile Include="EmailSenderTests.cs" />
- <Compile Include="ReadingsControllerTests.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="SqlOperatorTests.cs" />
- </ItemGroup>
- <ItemGroup>
- <None Include="app.config" />
- <None Include="packages.config" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\PollutometerWebApi\PollutometerWebApi.csproj">
- <Project>{22C32F4C-0DEB-40EA-9D56-48942CBB2A07}</Project>
- <Name>PollutometerWebApi</Name>
- </ProjectReference>
- </ItemGroup>
- <Choose>
- <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
- <ItemGroup>
- <Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <Private>False</Private>
- </Reference>
- <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <Private>False</Private>
- </Reference>
- <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <Private>False</Private>
- </Reference>
- <Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
- <Private>False</Private>
- </Reference>
- </ItemGroup>
- </When>
- </Choose>
- <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
- <PropertyGroup>
- <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>
- </PropertyGroup>
- <Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props'))" />
- <Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets'))" />
- </Target>
- <Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project> \ No newline at end of file
diff --git a/PollutometerWebApi.Tests/Properties/AssemblyInfo.cs b/PollutometerWebApi.Tests/Properties/AssemblyInfo.cs
deleted file mode 100644
index d6c3cc7..0000000
--- a/PollutometerWebApi.Tests/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("PollutometerWebApi.Tests")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("PollutometerWebApi.Tests")]
-[assembly: AssemblyCopyright("Copyright © 2017")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("94a21c38-920e-42ef-8d48-b133d635eafa")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/PollutometerWebApi.Tests/ReadingsControllerTests.cs b/PollutometerWebApi.Tests/ReadingsControllerTests.cs
deleted file mode 100644
index 647649d..0000000
--- a/PollutometerWebApi.Tests/ReadingsControllerTests.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using PollutometerWebApi.Models;
-using System;
-using System.Collections.Generic;
-using System.Web.Http.Results;
-
-namespace PollutometerWebApi.Controllers.Tests
-{
- [TestClass()]
- public class ReadingsControllerTests
- {
- ReadingsController controller = new ReadingsController();
-
- [TestMethod()]
- public void GetAllReadingsTest()
- {
- var actionResult = controller.GetAllReadings();
- var content = ((OkNegotiatedContentResult<List<Reading>>)actionResult).Content;
- Assert.IsTrue(content.Count >= 1);
- }
-
-
- [TestMethod()]
- public void GetReadingTest()
- {
- var actionResult = controller.GetReading(0);
- Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult<Reading>));
- }
-
- [TestMethod()]
- public void GetLatestReadingTest()
- {
- var actionResult = controller.GetLatestReading();
- var content = ((OkNegotiatedContentResult<Reading>)actionResult).Content;
- Assert.IsNotNull(content);
- }
-
- [TestMethod()]
- public void GetReadingsFromLastWeekTest()
- {
- var actionResult = controller.GetReadingsFromLastWeek();
- var content = ((OkNegotiatedContentResult<List<Reading>>)actionResult).Content;
- foreach(var reading in content)
- {
- var now = DateTimeOffset.Now.ToUnixTimeSeconds();
- Assert.IsTrue(reading.TimeStamp < now && reading.TimeStamp > now - 7*24*3600);
- }
- }
-
- [TestMethod()]
- public void PostReadingPassTest()
- {
- var newReading = new Reading
- {
- TimeStamp = (int)DateTimeOffset.Now.ToUnixTimeSeconds(),
- Co = 1.0,
- No = 1.0,
- So = 1.0
- };
- var actionResult = controller.PostReading(newReading);
- var reading = controller.GetLatestReading();
- var content = ((OkNegotiatedContentResult<Reading>)reading).Content;
- Assert.AreEqual(newReading.TimeStamp, content.TimeStamp);
- }
-
- [TestMethod()]
- public void PostReadingFailTest()
- {
- var actionResult = controller.PostReading(null);
- Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult));
- }
-
- [TestMethod()]
- public void PutReadingPassTest()
- {
- var latest = controller.GetLatestReading();
- var content = ((OkNegotiatedContentResult<Reading>)latest).Content;
- var actionResult = controller.PutReading(content.Id,
- new Reading
- {
- TimeStamp = (int)DateTimeOffset.Now.ToUnixTimeSeconds(),
- Co = 2.0,
- No = 2.0,
- So = 2.0
- }
- );
- Assert.AreEqual(typeof(OkResult), actionResult.GetType());
- }
-
- [TestMethod()]
- public void PutReadingFailTest()
- {
- var latest = controller.GetLatestReading();
- var content = ((OkNegotiatedContentResult<Reading>)latest).Content;
- var actionResult = controller.PutReading(content.Id, null);
- Assert.AreEqual(typeof(BadRequestResult), actionResult.GetType());
- }
-
- [TestMethod()]
- public void DeleteReadingPassTest()
- {
- var latest = controller.GetLatestReading();
- var content = ((OkNegotiatedContentResult<Reading>)latest).Content;
- var actionResult = controller.DeleteReading(content.Id);
- var reading = controller.GetReading(content.Id);
- Assert.IsInstanceOfType(reading, typeof(NotFoundResult));
- }
-
- [TestMethod()]
- public void DeleteReadingFailTest()
- {
- var actionResult = controller.DeleteReading(1337);
- Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
- }
- }
-} \ No newline at end of file
diff --git a/PollutometerWebApi.Tests/SqlOperatorTests.cs b/PollutometerWebApi.Tests/SqlOperatorTests.cs
deleted file mode 100644
index 2930679..0000000
--- a/PollutometerWebApi.Tests/SqlOperatorTests.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using PollutometerWebApi.Models;
-using System;
-
-namespace PollutometerWebApi.Tests
-{
- [TestClass()]
- public class SqlOperatorTests
- {
- [TestMethod()]
- public void GetReadingsTest()
- {
- var readings = SqlOperator.GetReadings("SELECT * FROM Readings");
- Assert.IsTrue(readings.Count >= 1);
- }
-
- [TestMethod()]
- public void PostReadingTest()
- {
- var newReading = new Reading
- {
- TimeStamp = (int)DateTimeOffset.Now.ToUnixTimeSeconds(),
- Co = 0.0,
- No = 0.0,
- So = 0.0
- };
- SqlOperator.PostReading(newReading);
- var command = "SELECT * FROM Readings " +
- "WHERE TimeStamp IN(SELECT MAX(TimeStamp) FROM Readings)";
- var latestReading = SqlOperator.GetReadings(command)[0];
- var command2 = $"SELECT * FROM Readings WHERE Id={latestReading.Id}";
- var reading = SqlOperator.GetReadings(command2)[0];
- Assert.AreEqual(newReading.TimeStamp, reading.TimeStamp);
- }
-
- [TestMethod()]
- public void PutReadingTest()
- {
- var newReading = new Reading
- {
- TimeStamp = (int)DateTimeOffset.Now.ToUnixTimeSeconds(),
- Co = 0.5,
- No = 0.5,
- So = 0.5
-
- };
- var command = "SELECT * FROM Readings " +
- "WHERE TimeStamp IN(SELECT MAX(TimeStamp) FROM Readings)";
- var latestReading = SqlOperator.GetReadings(command)[0];
- SqlOperator.PutReading(latestReading.Id, newReading);
- var command2 = $"SELECT * FROM Readings WHERE Id={latestReading.Id}";
- var reading = SqlOperator.GetReadings(command2)[0];
- Assert.AreEqual(newReading.TimeStamp, reading.TimeStamp);
- }
-
- [TestMethod()]
- public void DeleteReadingTest()
- {
- var command = "SELECT * FROM Readings " +
- "WHERE TimeStamp IN(SELECT MAX(TimeStamp) FROM Readings)";
- var latestReading = SqlOperator.GetReadings(command)[0];
- SqlOperator.DeleteReading(latestReading.Id);
- var command2 = $"SELECT * FROM Readings WHERE Id={latestReading.Id}";
- var readings = SqlOperator.GetReadings(command2);
- Assert.IsTrue(readings.Count == 0);
- }
- }
-} \ No newline at end of file
diff --git a/PollutometerWebApi.Tests/app.config b/PollutometerWebApi.Tests/app.config
deleted file mode 100644
index 4429813..0000000
--- a/PollutometerWebApi.Tests/app.config
+++ /dev/null
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <runtime>
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
- <dependentAssembly>
- <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
- <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
- </dependentAssembly>
- </assemblyBinding>
- </runtime>
-</configuration> \ No newline at end of file
diff --git a/PollutometerWebApi.Tests/packages.config b/PollutometerWebApi.Tests/packages.config
deleted file mode 100644
index 7472064..0000000
--- a/PollutometerWebApi.Tests/packages.config
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
- <package id="Microsoft.AspNet.WebApi" version="5.2.0" targetFramework="net462" />
- <package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="net462" />
- <package id="Microsoft.AspNet.WebApi.Core" version="5.2.0" targetFramework="net462" />
- <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.0" targetFramework="net462" />
- <package id="MSTest.TestAdapter" version="1.1.18" targetFramework="net462" />
- <package id="MSTest.TestFramework" version="1.1.18" targetFramework="net462" />
- <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net462" />
-</packages> \ No newline at end of file