예제 #1
0
파일: Relayr.cs 프로젝트: davitko/CsharpWB
        // Try to connect to the broker using the given dynamic representation of a transmitter and
        // the specified clientID. If connection is successful, it will return a Transmitter isntance
        // representing the transmitter. Returns null otherwise.
        public static Transmitter ConnectToBroker(dynamic transmitterInfo, string clientId)
        {

            // Check arguments
            if (transmitterInfo == null)
            {
                throw new ArgumentException("Transmitter Info argument cannot be null");
            }

            if (clientId == null || clientId.Equals(""))
            {
                throw new ArgumentException("ClientId cannot be null or empty");
            }

            // Get required fields, try to open a connection
            string transmitterId = (string)transmitterInfo["id"];
            string transmitterSecret = (string)transmitterInfo["secret"];

            Transmitter transmitter = new Transmitter(transmitterId);
            bool success = transmitter.ConnectToBroker(clientId, transmitterSecret);

            if (!success)
            {
                return null;
            }

            return transmitter;
        }
 public void ConnectToBroker_Incorrect_TransmitterId_Return_False()
 {
     Transmitter transmitter = new Transmitter("asdasdf");
     Assert.IsFalse(transmitter.ConnectToBroker("hello", transmitterSecret));
 }
        public void ConnectToBroker_Null_ClientId_ThrowInvalidArgsException()
        {
            try
            {
                Transmitter transmitter = new Transmitter(transmitterId);
                transmitter.ConnectToBroker(null, transmitterSecret);
                Assert.Fail();
            }
            catch(ArgumentException e)
            {

            }
        }
        public async void SubscribeToSensor_Connection_Successful_ReturnDevice()
        {
            Transmitter transmitter = new Transmitter(transmitterId);
            transmitter.ConnectToBroker("hello", transmitterSecret);
            Device device = await transmitter.SubscribeToDeviceDataAsync("d1fa0703-36bb-4694-8db1-a71becc9d489");

            Assert.IsNotNull(device);
        }
 public void ConnectToBroker_ValidCredentials_Success()
 {
     Transmitter transmitter = new Transmitter(transmitterId);
     Assert.IsTrue(transmitter.ConnectToBroker("hello", transmitterSecret));
 }
        public async void SubscribeToSensor_Connection_Fails_ReturnNull()
        {
            Transmitter transmitter = new Transmitter(transmitterId);
            transmitter.ConnectToBroker("hello", transmitterSecret);
            Device device = await transmitter.SubscribeToDeviceDataAsync("asdasd33");

            //Assert.IsNull(device);
        }
        public void SubscribeToSensor_Empty_DeviceId_ThrowException()
        {
            try
            {
                Transmitter transmitter = new Transmitter(transmitterId);
                transmitter.ConnectToBroker("hello", transmitterSecret);
                transmitter.SubscribeToDeviceDataAsync("");
                Assert.Fail();
            }
            catch (ArgumentException e)
            {

            }
        }
 public void ConnectToBroker_Empty_Secret_False()
 {
     Transmitter transmitter = new Transmitter(transmitterId);
     Assert.IsFalse(transmitter.ConnectToBroker("hello", ""));
 }
 public void ConnectToBroker_Empty_ClientId_False()
 {
     Transmitter transmitter = new Transmitter(transmitterId);
     Assert.IsFalse(transmitter.ConnectToBroker("", transmitterSecret));
 }
        public void ConnectToBroker_Null_Secret_ThrowInvalidArgsException()
        {
            try
            {
                Transmitter transmitter = new Transmitter(transmitterId);
                transmitter.ConnectToBroker("hello", null);
                Assert.Fail();
            }
            catch (ArgumentException e)
            {

            }
        }