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 /pollutometer-api/PollutometerWebApi.Tests/SqlOperatorTests.cs
parent9441b9d8b3035dc3142234dd13a1bcea21e72749 (diff)
Moved API to separate folder.
Diffstat (limited to 'pollutometer-api/PollutometerWebApi.Tests/SqlOperatorTests.cs')
-rw-r--r--pollutometer-api/PollutometerWebApi.Tests/SqlOperatorTests.cs68
1 files changed, 68 insertions, 0 deletions
diff --git a/pollutometer-api/PollutometerWebApi.Tests/SqlOperatorTests.cs b/pollutometer-api/PollutometerWebApi.Tests/SqlOperatorTests.cs
new file mode 100644
index 0000000..2930679
--- /dev/null
+++ b/pollutometer-api/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