aboutsummaryrefslogtreecommitdiff
blob: 293067982000b5305bcedee076db984d836abe8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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);
        }
    }
}