public void Put(RelayCollection collection) { if (collection == null) { throw new ArgumentNullException(nameof(RelayCollection), "RelayCollection was nullable"); } var request = new RestRequest(_requestUrl, Method.PUT) { Timeout = 2500 }; var jsonRelayCollection = JsonConvert.SerializeObject(collection); var jsonParts = this.ConstructJsonBodyParts(jsonRelayCollection); request.AddJsonBody(jsonParts); _mxioContext.MandatoryHeaders.Select(t => new { t.Key, t.Value }).ToList().ForEach(t => request.AddHeader(t.Key, t.Value)); IRestResponse response = _mxioContext.Client.Execute(request); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception($"Put query was failder with {response.StatusCode}"); } }
public void RelayCollection_SingleItem() { // Arrange var list = new List <RelayOnChain>() { new RelayOnChain { Url = "http://test.url" } }; _client.Setup(x => x.GetAddrAsync(It.IsAny <Uri>())) .ReturnsAsync(new GetAddrResponse() { Ready = true }); // Act var collection = new RelayCollection(_client.Object, list); // Assert Assert.Single(collection); var relay = collection.First().Value; Assert.True(relay.IsLoaded); Assert.True(relay.Ready); }
public void RelayCollection_EmptyCollection() { // Act var collection = new RelayCollection(_client.Object, new List <RelayOnChain>()); // Assert Assert.Empty(collection); }
public void RelayCollection_SingleItemWithInvalidUrl() { // Arrange var list = new List <RelayOnChain>() { new RelayOnChain() }; // Act var collection = new RelayCollection(_client.Object, list); // Assert Assert.Single(collection); var relay = collection.First().Value; Assert.False(relay.IsLoaded); Assert.False(relay.Ready); }
private async Task ObservableStateAsync(object state) { await Task.Run(async() => { Ping ping = new Ping(); PingReply reply = await ping.SendPingAsync(IPAddress.Parse(_mxioContext.Client.BaseUrl.Host)); if (reply.Status != IPStatus.Success) { return; } RelayCollection relayInputs = default; //TODO:Include try { relayInputs = await this.GetAsync(); } finally { } if (_lastRelays == null) { _lastRelays = relayInputs; return; } var differentDigitalInputs = relayInputs.Where(t => _lastRelays.FirstOrDefault(k => k.Index == t.Index).Status != t.Status); if (differentDigitalInputs.Count() != 0) { OnChanged?.Invoke(this, relayInputs); } _lastRelays = relayInputs; }); }
private void SetRlsStatus(RelayCollection e) { RelayContacts = new ObservableCollection <RelayModel>(e.Select(t => new RelayModel { Relay = t })); }