예제 #1
0
        public void Two_Objects_Given_Same_Constructor_Args_Should_Be_Equal(RgbValue red, RgbValue green, RgbValue blue)
        {
            // Arrange & Act
            var a = new RgbColour(red, green, blue);
            var b = new RgbColour(red, green, blue);

            // Assert
            a.Should().Be(b);
        }
예제 #2
0
        public void Constructor_Given_Null_Blue_Arg_Throws_ArgumentNullExpection(RgbValue red, RgbValue green, RgbValue blue)
        {
            // Arrange
            blue = null;

            Action act = () => new RgbColour(red, green, blue);

            // Act & Assert
            act.Should().Throw <ArgumentNullException>();
        }
예제 #3
0
        public void Constructor_Given_Args_Sets_Properties(RgbValue red, RgbValue green, RgbValue blue)
        {
            // Arrange & Act
            var actual = new RgbColour(red, green, blue);

            // Assert
            actual.Red.Should().Be(red);
            actual.Green.Should().Be(green);
            actual.Blue.Should().Be(blue);
        }
        public void SetColorOfGroup(HttpContext context, string groupId)
        {
            if (context.Request.Payload.Length > 0)
            {
                string   json     = context.Request.Payload.ReadAll();
                RgbValue rgbValue = JsonSerializer.DeserializeJson <RgbValue>(json);

                int id = ApiBase.ParseId(groupId);
                if (rgbValue == null)
                {
                    throw new BadRequestException(BadRequestException.MSG_INVALID_PAYLOAD);
                }
                _groupHandler.SetColorOfGroup(id, rgbValue.Rgb);
                context.Response.Status = HttpStatus.OK;
            }
            else
            {
                throw new BadRequestException(BadRequestException.MSG_PAYLOAD_EXPECTED);
            }
        }
예제 #5
0
        public void SetLed(HttpContext context, string ledId)
        {
            if (context.Request.Payload.Length > 0)
            {
                string   json     = context.Request.Payload.ReadAll();
                RgbValue rgbValue = JsonSerializer.DeserializeJson <RgbValue>(json);
                if (rgbValue == null)
                {
                    throw new BadRequestException(BadRequestException.MSG_INVALID_PAYLOAD);
                }
                _ledHandler.SetColor(ledId, rgbValue.Rgb);

                Led    response     = _ledHandler.GetLed(ledId);
                string jsonResponse = JsonSerializer.SerializeJson(response);
                context.Response.Payload.Write(jsonResponse);
                context.Response.Status = HttpStatus.OK;
            }
            else
            {
                throw new BadRequestException(BadRequestException.MSG_PAYLOAD_EXPECTED);
            }
        }