-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWateringEventTest.cs
89 lines (76 loc) · 2.77 KB
/
WateringEventTest.cs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using NUnit.Framework;
using RainMachineNet;
using RainMachineNet.Event;
using RainMachineNet.Responses;
using RainMachineNet.Support;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace RainMachineNetTest
{
public class WateringEventTest: WateringNotificationSubscriber<WateringEvent>
{
private IRainMaker _rainMaker;
private bool _watering;
[SetUp]
public void Setup()
{
_rainMaker = new RainMaker();
}
public WateringEventTest():base("WateringEventTest")
{
_watering=true;
}
[Test]
public async Task Subscription()
{
var ret = await _rainMaker.LoginAsync(Constants.NetName, Constants.User, Constants.Password);
Assert.IsTrue(ret);
var test = new WateringEventTest();
var test2 = new WateringEventTest();
await _rainMaker.Subscribe(test);
Assert.IsTrue(_rainMaker.IsPolling);
await _rainMaker.UnSubscribe(test);
Assert.IsFalse(_rainMaker.IsPolling);
await _rainMaker.Subscribe(test);
Assert.IsTrue(_rainMaker.IsPolling);
await _rainMaker.Subscribe(test2);
Assert.IsTrue(_rainMaker.IsPolling);
await _rainMaker.UnSubscribe(test);
Assert.IsTrue(_rainMaker.IsPolling);
await _rainMaker.UnSubscribe(test2);
Assert.IsFalse(_rainMaker.IsPolling);
}
[Test]
public async Task TestPollingNotification()
{
var ret = await _rainMaker.LoginAsync(Constants.NetName, Constants.User, Constants.Password);
Assert.IsTrue(ret);
var test = new WateringEventTest();
await _rainMaker.Subscribe(test);
await _rainMaker.ProgramStart(Constants.TestProgram);
var rc=await _rainMaker.GetWateringProgram();
while (test.Waiting)
{
Thread.Sleep(500);
}
await _rainMaker.UnSubscribe(test);
await _rainMaker.ProgramStop(Constants.TestProgram);
Assert.IsInstanceOf<IResponseBase>(rc, "Unexpected object type");
Assert.IsInstanceOf<ProgramsResponse>(rc, "Unexpected object type");
}
public override void OnNext(WateringEvent ev)
{
foreach(var e in ev.Watering.zones)
{
Debugger.Log(1,"Test", $"Zone {e.uid}-{e.name} is currently {e.state}\r\n");
}
_watering=ev.Watering.zones.Any(a=>a.state==RainMachineNet.Model.Shared.WateringState.Running);
base.OnNext(ev);
}
public bool Waiting => _watering;
}
}