/// <summary> /// Deserializes a json object into an Activator object. /// </summary> /// <param name="jsonActivator"></param> /// <returns>An Activator object</returns> public Activator DeserializeActivator(JToken jsonActivator) { // get the activatorId, rank and name string id = jsonActivator.Value <string>("activatorId"); int rank = jsonActivator.Value <int>("rank"); string name = jsonActivator.Value <string>("name"); // get the state type string type = jsonActivator.Value <string>("type"); ActivatorState state = null; switch (type.ToLower()) { case "bool": state = new ActivatorState(jsonActivator.Value <bool>("state"), "bool"); break; case "float": state = new ActivatorState(jsonActivator.Value <float>("state"), "float"); break; } // create the Activator Activator activator = new Activator(id, name, rank, state); return(activator); }
public void SetUpActivators() { networkHandler = new NetworkHandler(dummyAddress); serverInteractor = new HestiaServerInteractor(networkHandler); device = new Device("1234", "nice_device", "light", new List <Activator>(), serverInteractor); boolId = "123"; boolName = "dummyBoolName"; boolRank = 0; boolRawState = false; boolStateType = "bool"; boolActivatorState = new ActivatorState(boolRawState, boolStateType); boolActivator = new Activator(boolId, boolName, boolRank, boolActivatorState) { Device = device }; floatId = "123456"; floatName = "dummyFloatName"; floatRank = 1; floatRawState = 0.5f; floatStateType = "float"; floatActivatorState = new ActivatorState(floatRawState, floatStateType); floatActivator = new Activator(floatId, floatName, floatRank, floatActivatorState) { Device = device }; Assert.IsNotNull(boolActivator); Assert.IsNotNull(floatActivator); }
public void SetFloatStateFailure() { Mock <NetworkHandler> mockNetworkHandler = new Mock <NetworkHandler>(dummyAddress); mockNetworkHandler.Setup(x => x.Post(It.IsAny <JObject>(), It.IsAny <string>())).Throws(new ServerInteractionException()); floatActivator.Device.ServerInteractor.NetworkHandler = mockNetworkHandler.Object; ActivatorState newFloatState = new ActivatorState(1.5, "float"); floatActivator.State = newFloatState; }
public void SetUpActivatorStates() { boolRawState = true; boolType = "bool"; boolState = new ActivatorState(boolRawState, boolType); floatRawState = 0.5f; floatType = "float"; floatState = new ActivatorState(floatRawState, floatType); Assert.IsNotNull(boolState); Assert.IsNotNull(floatState); }
public void SetAndGetActivatorsTest() { Assert.IsTrue(device.Activators.Count == 1); Assert.AreEqual(activators, device.Activators); ActivatorState newActivatorState = new ActivatorState(0.8, "float"); string newActivatorId = "1000"; string newActivatorName = "slider"; int newActivatorRank = 15; Activator newActivator = new Activator(newActivatorId, newActivatorName, newActivatorRank, newActivatorState); List <Activator> newActivators = new List <Activator> { newActivator }; device.Activators = newActivators; Assert.IsTrue(device.Activators.Count == 1); Assert.AreEqual(newActivators, device.Activators); }
public void SetUpDevice() { ActivatorState activatorState = new ActivatorState(false, "bool"); string activatorId = "1234"; string activatorName = "bob"; int activatorRank = 0; activator = new Activator(activatorId, activatorName, activatorRank, activatorState); activators = new List <Activator> { activator }; networkHandler = new NetworkHandler(dummyAddress); serverInteractor = new HestiaServerInteractor(networkHandler); device = new Device(deviceId, deviceName, type, activators, serverInteractor); activator.Device = device; Assert.IsNotNull(device); }
public void SetAndGetBoolStateTestSuccess() { Assert.AreEqual(boolActivatorState, boolActivator.State); Mock <NetworkHandler> mockNetworkHandler = new Mock <NetworkHandler>(dummyAddress); mockNetworkHandler.Setup(x => x.Post(It.IsAny <JObject>(), It.IsAny <string>())).Returns(new JObject()); boolActivator.Device.ServerInteractor.NetworkHandler = mockNetworkHandler.Object; ActivatorState newBoolState = new ActivatorState(true, "bool"); Assert.AreNotEqual(boolActivatorState, newBoolState); try { boolActivator.State = newBoolState; } catch (ServerInteractionException ex) { Assert.Fail(ex.Message, ex); } Assert.AreEqual(newBoolState, boolActivator.State); }