aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--PollutometerWebApi.Tests/AqiCalculatorTests.cs51
-rw-r--r--PollutometerWebApi.Tests/EmailSenderTests.cs21
-rw-r--r--PollutometerWebApi.Tests/PollutometerWebApi.Tests.csproj99
-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/Test.cs15
-rw-r--r--PollutometerWebApi.Tests/app.config11
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/Microsoft.Web.Infrastructure.dllbin45416 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.dllbin4096 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.pdbbin536 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.dllbin16896 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.pdbbin4216 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Net.Http.Formatting.dllbin185032 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Net.Http.Formatting.xml2094
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.Http.WebHost.dllbin82120 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.Http.WebHost.xml135
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.Http.dllbin471248 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.Http.xml6664
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.Mvc.dllbin566472 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.Mvc.xml11485
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.Razor.dllbin272072 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.Razor.xml5742
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.WebPages.Deployment.dllbin41672 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.WebPages.Deployment.xml60
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.WebPages.Razor.dllbin39624 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.WebPages.Razor.xml292
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.WebPages.dllbin211656 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/System.Web.WebPages.xml2706
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/nunit.framework.dllbin151552 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/bin/Debug/nunit.framework.xml10984
-rw-r--r--PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.csproj.CopyComplete0
-rw-r--r--PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.csproj.CoreCompileInputs.cache1
-rw-r--r--PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.csproj.FileListAbsolute.txt27
-rw-r--r--PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.csprojResolveAssemblyReference.cachebin109342 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.dllbin4096 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/obj/Debug/PollutometerWebApi.Tests.pdbbin536 -> 0 bytes
-rw-r--r--PollutometerWebApi.Tests/packages.config8
-rw-r--r--PollutometerWebApi.sln21
-rw-r--r--PollutometerWebApi/App_Start/WebApiConfig.cs46
-rw-r--r--PollutometerWebApi/AqiCalculator.cs188
-rw-r--r--PollutometerWebApi/Controllers/ReadingsController.cs127
-rw-r--r--PollutometerWebApi/PollutometerWebApi.csproj47
-rw-r--r--PollutometerWebApi/SqlOperator.cs5
-rw-r--r--PollutometerWebApi/Views/Web.config2
-rw-r--r--packages/Microsoft.AspNet.WebApi.5.2.3/Microsoft.AspNet.WebApi.5.2.3.nupkgbin3193 -> 0 bytes
-rw-r--r--packages/Microsoft.AspNet.WebApi.Client.5.2.3/Microsoft.AspNet.WebApi.Client.5.2.3.nupkgbin188921 -> 0 bytes
-rw-r--r--packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/net45/System.Net.Http.Formatting.dllbin185544 -> 0 bytes
-rw-r--r--packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/net45/System.Net.Http.Formatting.xml2094
-rw-r--r--packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/portable-wp8+netcore45+net45+wp81+wpa81/System.Net.Http.Formatting.dllbin151240 -> 0 bytes
-rw-r--r--packages/Microsoft.AspNet.WebApi.Client.5.2.3/lib/portable-wp8+netcore45+net45+wp81+wpa81/System.Net.Http.Formatting.xml4025
-rw-r--r--packages/Microsoft.AspNet.WebApi.Core.5.2.3/Content/web.config.transform11
-rw-r--r--packages/Microsoft.AspNet.WebApi.Core.5.2.3/Microsoft.AspNet.WebApi.Core.5.2.3.nupkgbin239426 -> 0 bytes
-rw-r--r--packages/Microsoft.AspNet.WebApi.Core.5.2.3/lib/net45/System.Web.Http.dllbin471240 -> 0 bytes
-rw-r--r--packages/Microsoft.AspNet.WebApi.Core.5.2.3/lib/net45/System.Web.Http.xml6664
-rw-r--r--packages/Microsoft.AspNet.WebApi.WebHost.5.2.3/Microsoft.AspNet.WebApi.WebHost.5.2.3.nupkgbin43077 -> 0 bytes
-rw-r--r--packages/Microsoft.AspNet.WebApi.WebHost.5.2.3/lib/net45/System.Web.Http.WebHost.dllbin82120 -> 0 bytes
-rw-r--r--packages/Microsoft.AspNet.WebApi.WebHost.5.2.3/lib/net45/System.Web.Http.WebHost.xml135
58 files changed, 634 insertions, 53346 deletions
diff --git a/PollutometerWebApi.Tests/AqiCalculatorTests.cs b/PollutometerWebApi.Tests/AqiCalculatorTests.cs
new file mode 100644
index 0000000..e84b687
--- /dev/null
+++ b/PollutometerWebApi.Tests/AqiCalculatorTests.cs
@@ -0,0 +1,51 @@
+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
new file mode 100644
index 0000000..427ec92
--- /dev/null
+++ b/PollutometerWebApi.Tests/EmailSenderTests.cs
@@ -0,0 +1,21 @@
+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
index c27a06c..6ff37aa 100644
--- a/PollutometerWebApi.Tests/PollutometerWebApi.Tests.csproj
+++ b/PollutometerWebApi.Tests/PollutometerWebApi.Tests.csproj
@@ -1,39 +1,84 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<?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>{D19CA1E0-796F-480A-996D-3DFABFC6203F}</ProjectGuid>
+ <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;</DefineConstants>
+ <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>
+ <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="nunit.framework">
- <HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
+ <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="Test.cs" />
+ <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>
@@ -42,5 +87,39 @@
<Name>PollutometerWebApi</Name>
</ProjectReference>
</ItemGroup>
- <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <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
new file mode 100644
index 0000000..d6c3cc7
--- /dev/null
+++ b/PollutometerWebApi.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+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
new file mode 100644
index 0000000..647649d
--- /dev/null
+++ b/PollutometerWebApi.Tests/ReadingsControllerTests.cs
@@ -0,0 +1,116 @@
+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
new file mode 100644
index 0000000..2930679
--- /dev/null
+++ b/PollutometerWebApi.Tests/SqlOperatorTests.cs
@@ -0,0 +1,68 @@
+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/Test.cs b/PollutometerWebApi.Tests/Test.cs
deleted file mode 100644
index abec015..0000000
--- a/PollutometerWebApi.Tests/Test.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using NUnit.Framework;
-using System;
-namespace PollutometerWebApi.Tests
-{
- [TestFixture()]
- public class Test
- {
- [Test()]
- public void TestCase()
- {
- var result = AqiCalculator.CalculateAqi(new Models.Reading() {Co = 30.4, No = 1.0, So = 0.4});
- EmailSender.SendEmail(result);
- }
- }
-}
diff --git a/PollutometerWebApi.Tests/app.config b/PollutometerWebApi.Tests/app.config
new file mode 100644
index 0000000..4429813
--- /dev/null
+++ b/PollutometerWebApi.Tests/app.config
@@ -0,0 +1,11 @@
+<?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/bin/Debug/Microsoft.Web.Infrastructure.dll b/PollutometerWebApi.Tests/bin/Debug/Microsoft.Web.Infrastructure.dll
deleted file mode 100644
index 85f1138..0000000
--- a/PollutometerWebApi.Tests/bin/Debug/Microsoft.Web.Infrastructure.dll
+++ /dev/null
Binary files differ
diff --git a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.dll b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.dll
deleted file mode 100644
index 29a96a6..0000000
--- a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.dll
+++ /dev/null
Binary files differ
diff --git a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.pdb b/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.pdb
deleted file mode 100644
index d4059a7..0000000
--- a/PollutometerWebApi.Tests/bin/Debug/PollutometerWebApi.Tests.pdb
+++ /dev/null
Binary files dif