public async Task ErrorReceived() { Message message = null; var autoresetevent = new AutoResetEvent(false); var json = await File.ReadAllTextAsync(@"Data\Error.json"); var document = JsonDocument.Parse(json); await _client.Connect(new MessageObserver(m => { message = m as Message; autoresetevent.Set(); })); _nikoResponseObservable.MessageReceived(new NikoMessage { MessageType = NikoMessageType.Err, Method = Constants.Messages.LocationsList, Params = document.RootElement }); autoresetevent.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); message.Should().NotBeNull(); message.MessageType.Should().Be(Constants.Messages.LocationsList); message.IsError.Should().BeTrue(); message.Data.Should().BeNull(); message.Error.Should().NotBeNull(); message.Error.ErrCode.Should().Be("UNKNOWN_METHOD"); message.Error.ErrMessage.Should().Be("Method 'unknown' not supported for topic 'hobby/control/location/cmd'"); }
public async Task DevicesAdded_Success() { Message message = null; var autoresetevent = new AutoResetEvent(false); var json = await File.ReadAllTextAsync(@"Data\DeviceAdded.json"); var document = JsonDocument.Parse(json); await _client.Connect(new MessageObserver(m => { message = m as Message; autoresetevent.Set(); })); _nikoResponseObservable.MessageReceived(new NikoMessage { MessageType = NikoMessageType.Evt, Method = Constants.Messages.DevicesAdded, Params = document.RootElement }); autoresetevent.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); message.Should().NotBeNull(); message.MessageType.Should().Be(Constants.Messages.DevicesAdded); message.IsError.Should().BeFalse(); message.Data.Should().AllBeAssignableTo <IDevice>(); message.Data.Count.Should().Be(2); var devices = message.Data.Cast <IDevice>().ToList(); devices[0].Id.Should().Be("b6a06a67-ce6f-42e2-933b-c67227996f46"); }
public async Task DeviceList_Success() { Message message = null; var autoresetevent = new AutoResetEvent(false); var json = await File.ReadAllTextAsync(@"Data\DeviceList.json"); var document = JsonDocument.Parse(json); await _client.Connect(new MessageObserver(m => { message = m as Message; autoresetevent.Set(); })); _nikoResponseObservable.MessageReceived(new NikoMessage { MessageType = NikoMessageType.Rsp, Method = Constants.Messages.DevicesList, Params = document.RootElement }); autoresetevent.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); message.Should().NotBeNull(); message.MessageType.Should().Be(Constants.Messages.DevicesList); message.IsError.Should().BeFalse(); message.Data.Should().AllBeAssignableTo <IDevice>(); message.Data.Count.Should().Be(1); var device = (IDevice)message.Data[0]; device.Identifier.Should().Be("a4fafca1-bde4-4ad7-94f9-292c60c26bf7"); device.Parameters.Count.Should().Be(3); device.Properties.Count.Should().Be(3); device.Properties.First().Definition.ValueType.Should().Be(PropertyType.Range); device.Properties.First().Definition.Range.Should().NotBeNull(); device.Properties.First().Definition.Range.End.Should().Be(100); }