Exemplo n.º 1
0
        public void ResponseCreation_Unlock_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(UNLOCK_REQUEST);
            SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header);

            Assert.Null(response.Context);
            response.Context = new Context();
            Property p = new Property(Namespaces.ALEXA_LOCKCONTROLLER, PropertyNames.LOCK_STATE,
                                      LockModes.UNLOCKED, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);
            ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK);
            Property p2 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value,
                                       DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);

            response.Context.Properties.Add(p);
            response.Context.Properties.Add(p2);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(Payload), response.GetPayloadType());
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("Lock", response);
        }
Exemplo n.º 2
0
        public void ResponseCreation_SetpointError_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_T_TEMPERATURE_TRIPLEMODE_REQUEST);
            SmartHomeResponse response = SmartHomeResponse.CreateErrorResponse(request.Directive.Header, ErrorTypes.REQUESTED_SETPOINTS_TOO_CLOSE);

            Assert.Null(response.Context);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header, Namespaces.ALEXA_THERMOSTATCONTROLLER, HeaderNames.ERROR_RESPONSE);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(RequestedSetpointsTooCloseErrorPayload), response.GetPayloadType());
            RequestedSetpointsTooCloseErrorPayload p = response.Event.Payload as RequestedSetpointsTooCloseErrorPayload;

            Assert.Equal(ErrorTypes.REQUESTED_SETPOINTS_TOO_CLOSE, p.Type);
            Assert.Null(p.Message);
            Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(response));
            p.Message = "The requested temperature results in setpoints too close";
            Assert.Null(p.MinimumTemperatureDelta);
            Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(response));
            p.MinimumTemperatureDelta = new Setpoint(2.0, Scale.CELSIUS);
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("Setpoints too clos", response);
        }
Exemplo n.º 3
0
        public void ResponseCreation_TemperatureOOR_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_T_TEMPERATURE_TRIPLEMODE_REQUEST);
            SmartHomeResponse response = SmartHomeResponse.CreateErrorResponse(request.Directive.Header, ErrorTypes.TEMPERATURE_VALUE_OUT_OF_RANGE);

            Assert.Null(response.Context);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header, Namespaces.ALEXA_THERMOSTATCONTROLLER, HeaderNames.ERROR_RESPONSE);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(TemperatureOutOfRangeErrorPayload), response.GetPayloadType());
            TemperatureOutOfRangeErrorPayload p = response.Event.Payload as TemperatureOutOfRangeErrorPayload;

            Assert.Equal(ErrorTypes.TEMPERATURE_VALUE_OUT_OF_RANGE, p.Type);
            Assert.Null(p.Message);
            Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(response));
            p.Message = "The requested temperature of -15 is out of range";
            Assert.Null(p.ValidRange);
            p.ValidRange = new TemperatureValidRange(new Setpoint(15.0, Scale.CELSIUS), new Setpoint(20.0, Scale.CELSIUS));
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("TemperatureOOR", response);
        }
Exemplo n.º 4
0
        public void ResponseCreation_SetTemperatureSingleMode_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_T_TEMPERATURE_SINGLEMODE_REQUEST);
            SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header);

            Assert.Null(response.Context);
            response.Context = new Context();
            Property p = new Property(Namespaces.ALEXA_THERMOSTATCONTROLLER, PropertyNames.TARGET_SETPOINT,
                                      new Setpoint(25.0, Scale.CELSIUS), DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);
            Property p3 = new Property(Namespaces.ALEXA_COLORTEMPERATURECONTROLLER, PropertyNames.THERMOSTATMODE,
                                       ThermostatModes.HEAT, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);
            ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK);
            Property p4 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value,
                                       DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);

            response.Context.Properties.Add(p);
            response.Context.Properties.Add(p3);
            response.Context.Properties.Add(p4);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(Payload), response.GetPayloadType());
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("SetTemperatureSingleMode", response);
        }
        public void ResponseCreation_CameraStream_Test()
        {
            SmartHomeRequest  requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(INIT_CAMERA_STREAMS_REQUEST);
            SmartHomeResponse response          = new SmartHomeResponse(requestFromString.Directive.Header);

            Assert.NotNull(response);
            Assert.Null(response.Context);
            response.Context = new Context();
            response.Context.Properties.Add(new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, new ConnectivityPropertyValue(ConnectivityModes.OK),
                                                         DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200));
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, requestFromString.Directive.Header, Namespaces.ALEXA_CAMERASTREAMCONTROLLER);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(ResponseCameraStreamsPayload), response.GetPayloadType());
            ResponseCameraStreamsPayload p = e.Payload as ResponseCameraStreamsPayload;

            Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(response));
            p.CameraStreams = new System.Collections.Generic.List <ResponseCameraStream>();
            p.CameraStreams.Add(new ResponseCameraStream("rtsp://*****:*****@link.to.video:443/feed1.mp4", CameraProtocols.RTSP,
                                                         new Resolution(1920, 1080), CameraAuthorizationTypes.BASIC, VideoCodecs.H264, AudioCodecs.AAC, 30,
                                                         DateTime.Parse("2017-09-27T20:30:30.45Z").ToUniversalTime()));
            p.CameraStreams.Add(new ResponseCameraStream("rtsp://*****:*****@link.to.video:443/feed2.mp4", CameraProtocols.RTSP,
                                                         new Resolution(1280, 720), CameraAuthorizationTypes.DIGEST, VideoCodecs.MPEG2, AudioCodecs.G711,
                                                         30, DateTime.Parse("2017-09-27T20:30:30.45Z").ToUniversalTime()));
            p.ImageURI = "https://*****:*****@link.to.image/image.jpg";
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("CameraStream", response);
        }
Exemplo n.º 6
0
        public void ResponseCreation_TemperatureSensor_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(REPORT_STATE);
            SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header);

            Assert.Null(response.Context);
            response.Context = new Context();
            Setpoint s = new Setpoint(24.0, Scale.CELSIUS);
            Property p = new Property(Namespaces.ALEXA_TEMPERATURESENSOR, PropertyNames.TEMPERATURE, 50,
                                      DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);
            ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK);
            Property p2 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value,
                                       DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);

            response.Context.Properties.Add(p);
            response.Context.Properties.Add(p2);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header, headerName: HeaderNames.STATE_REPORT);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(Payload), response.GetPayloadType());
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("TemperatureSensor", response);
        }
        public void ResponseCreation_ColorTemperatureResponse_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_COLORTEMPERATURE);
            SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header);

            Assert.Null(response.Context);
            response.Context = new Context();
            Color    color = new Color(350.5, 0.7138, 0.6524);
            Property p     = new Property(Namespaces.ALEXA_COLORTEMPERATURECONTROLLER, PropertyNames.COLOR_TEMPERATURE_IN_KELVIN,
                                          5000, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);
            ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK);
            Property p2 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value,
                                       DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);

            response.Context.Properties.Add(p);
            response.Context.Properties.Add(p2);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(Payload), response.GetPayloadType());
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("ColorTemperature", response);
        }
Exemplo n.º 8
0
        public void ResponseCreation_Deactivate_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(DEACTIVATE);
            SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header);

            Assert.Null(response.Context);
            response.Context = new Context();
            ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK);
            Property p2 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value,
                                       DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);

            response.Context.Properties.Add(p2);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header, Namespaces.ALEXA_SCENECONTROLLER, HeaderNames.DEACTIVATION_STARTED);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(SceneStartedResponsePayload), response.GetPayloadType());
            SceneStartedResponsePayload p = response.Event.Payload as SceneStartedResponsePayload;

            Assert.Null(p.Cause);
            Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(response));
            p.Cause     = new Cause(CauseTypes.APP_INTERACTION);
            p.Timestamp = DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime();
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("Deactivate", response);
        }
Exemplo n.º 9
0
        public void ResponseCreation_ChannelResponse_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(CHANGE_CHANNEL);
            SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header);

            //Context
            Assert.Null(response.Context);
            response.Context = new Context();
            Channel  channel = new Channel("1234", "callsign1", "callsign2");
            Property p       = new Property(Namespaces.ALEXA_CHANNELCONTROLLER, PropertyNames.CHANNEL, channel,
                                            DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);
            Property p2 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, new ConnectivityPropertyValue(ConnectivityModes.OK),
                                       DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200);

            response.Context.Properties.Add(p);
            response.Context.Properties.Add(p2);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header);
            Assert.Null(e.Endpoint);
            Scope s = new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon");

            e.Endpoint = new Endpoint("endpoint-001", s);
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(Payload), e.Payload.GetType());
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("ChannelResponse", response);
        }
Exemplo n.º 10
0
        public void ResponseCreation_AdjustBrightness_Test()
        {
            SmartHomeRequest  requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(ADJUST_BRIGHTNESS_REQUEST);
            SmartHomeResponse response          = new SmartHomeResponse(requestFromString.Directive.Header);

            Assert.NotNull(response);
            Assert.Null(response.Context);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, requestFromString.Directive.Header);
            Assert.Null(e.Endpoint);
            Assert.NotNull(e.Payload);
            Util.Util.WriteJsonToConsole("AdjustBrightness", response);
        }
Exemplo n.º 11
0
        public void ResponseCreation_SetBrightness_Test()
        {
            SmartHomeRequest  requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_BRIGHTNESS_REQUEST);
            SmartHomeResponse response          = new SmartHomeResponse(requestFromString.Directive.Header);

            Assert.NotNull(response);
            Assert.Null(response.Context);
            response.Context = new Context();
            response.Context.Properties.Add(new Property(Namespaces.ALEXA_BRIGHTNESSCONTROLLER, PropertyNames.BRIGHTNESS, 75,
                                                         DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200));
            response.Context.Properties.Add(new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, new ConnectivityPropertyValue(ConnectivityModes.OK),
                                                         DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200));
            Assert.NotNull(response.Event);
            Event e = response.Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, requestFromString.Directive.Header);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(Payload), e.Payload.GetType());
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("SetBrightness", response);
        }
Exemplo n.º 12
0
        public void ResponseCreation_GeneralError_Test()
        {
            SmartHomeRequest  request  = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_T_TEMPERATURE_TRIPLEMODE_REQUEST);
            SmartHomeResponse response = SmartHomeResponse.CreateErrorResponse(request.Directive.Header, ErrorTypes.THERMOSTAT_IS_OFF);

            Assert.Null(response.Context);
            Assert.NotNull(response.Event);
            Assert.Equal(typeof(Event), response.Event.GetType());
            Event e = response.Event as Event;

            TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header, Namespaces.ALEXA_THERMOSTATCONTROLLER, HeaderNames.ERROR_RESPONSE);
            Assert.Null(e.Endpoint);
            e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon"));
            Assert.NotNull(e.Payload);
            Assert.Equal(typeof(ErrorPayload), response.GetPayloadType());
            ErrorPayload p = response.Event.Payload as ErrorPayload;

            Assert.Equal(ErrorTypes.THERMOSTAT_IS_OFF, p.Type);
            Assert.Null(p.Message);
            Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(response));
            p.Message = "The thermostat is off, cannot turn on due to safety reasons";
            Assert.NotNull(JsonConvert.SerializeObject(response));
            Util.Util.WriteJsonToConsole("GeneralErrorThermostat", response);
        }