Ejemplo n.º 1
0
        public void GetDevicesTestSuccess()
        {
            Mock <NetworkHandler> mockNetworkHandlerLocal  = new Mock <NetworkHandler>(address);
            Mock <NetworkHandler> mockNetworkHandlerRemote = new Mock <NetworkHandler>(address);

            JArray  deviceJsonArray  = new JArray();
            JObject deviceJsonObject = new JObject
            {
                ["deviceId"]   = "dummyId",
                ["name"]       = "dummyName",
                ["type"]       = "dummyType",
                ["activators"] = new JArray()
            };

            deviceJsonArray.Add(deviceJsonObject);

            mockNetworkHandlerLocal.CallBase = true;
            mockNetworkHandlerLocal.Setup(x => x.Get(It.IsAny <string>())).Returns(deviceJsonArray);
            dummyServerInteractorLocal.NetworkHandler = mockNetworkHandlerLocal.Object;

            mockNetworkHandlerRemote.CallBase = true;
            mockNetworkHandlerRemote.Setup(x => x.Post(It.IsAny <JObject>(), It.IsAny <string>())).Returns(deviceJsonArray);
            dummyServerInteractorRemote.NetworkHandler = mockNetworkHandlerRemote.Object;

            List <Device> devicesLocal = null;

            try
            {
                devicesLocal = dummyServerInteractorLocal.GetDevices();
            } catch (ServerInteractionException ex)
            {
                Assert.Fail(ex.Message, ex);
            }

            List <Device> devicesRemote = null;

            try
            {
                devicesRemote = dummyServerInteractorRemote.GetDevices();
            }
            catch (ServerInteractionException ex)
            {
                Assert.Fail(ex.Message, ex);
            }

            Assert.IsNotNull(devicesLocal);
            Assert.AreEqual(devicesLocal[0].DeviceId, "dummyId");
            Assert.AreEqual(devicesLocal[0].Name, "dummyName");
            Assert.AreEqual(devicesLocal[0].Type, "dummyType");
            Assert.IsNotNull(devicesLocal[0].Activators);
            Assert.AreEqual(devicesLocal[0].ServerInteractor.NetworkHandler.Address, dummyNetworkHandler.Address);

            Assert.IsNotNull(devicesRemote);
            Assert.AreEqual(devicesRemote[0].DeviceId, "dummyId");
            Assert.AreEqual(devicesRemote[0].Name, "dummyName");
            Assert.AreEqual(devicesRemote[0].Type, "dummyType");
            Assert.IsNotNull(devicesRemote[0].Activators);
            Assert.AreEqual(devicesRemote[0].ServerInteractor.NetworkHandler.Address, dummyNetworkHandler.Address);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if a hestia server exists.
        /// </summary>
        /// <param name="address"></param>
        /// <returns>True or false</returns>
        public static bool Check(string address)
        {
            HestiaServerInteractor interactor = new HestiaServerInteractor(new NetworkHandler(address));

            try
            {
                interactor.GetDevices();
                return(true);
            }
            catch (ServerInteractionException ex)
            {
                Console.WriteLine("No such server exists");
                Console.WriteLine(ex);
                return(false);
            }
        }