Beispiel #1
0
        public void Should_be_valid_if_there_are_no_tags()
        {
            //Arrange
            var point = new Point
            {
                Measurement = "x",
                Fields      = new Dictionary <string, object> {
                    { "A", "1" }
                },
            };
            var validator = new PointValidator();

            //Act
            var response = validator.Validate(point);

            //Assert
            Assert.That(response, Is.Empty);
        }
Beispiel #2
0
        public void Should_be_invalid_if_there_are_no_fields()
        {
            //Arrange
            var point = new Point
            {
                Measurement = "x",
                Tags        = new Dictionary <string, object> {
                    { "B", "2" }
                }
            };
            var validator = new PointValidator();

            //Act
            var response = validator.Validate(point);

            //Assert
            Assert.That(response, Is.Not.Empty);
            Assert.That(response.First(), Is.EqualTo("There are no fields for measurement x."));
        }
Beispiel #3
0
        public void Should_be_invalid_if_there_is_no_measurement_name()
        {
            //Arrange
            var point = new Point
            {
                Fields = new Dictionary <string, object> {
                    { "A", "1" }
                },
                Tags = new Dictionary <string, object> {
                    { "B", "2" }
                }
            };
            var validator = new PointValidator();

            //Act
            var response = validator.Validate(point);

            //Assert
            Assert.That(response, Is.Not.Empty);
            Assert.That(response.First(), Is.EqualTo("There is no name for measurement."));
        }
Beispiel #4
0
        public void AddPoint(int userId, int filmId, int point)
        {
            var p = new PointValidator();

            var result = p.Validate(point);

            if (result.Errors.Count != 0)
            {
                throw new Exception(string.Join("\n", result.Errors.Select(x => x.ErrorMessage)));
            }

            var t = _pointRepository.Get(userId, filmId);

            if (t == null)
            {
                _pointRepository.Add(userId, filmId, point);
            }
            else
            {
                _pointRepository.Update(userId, filmId, point);
            }
        }
Beispiel #5
0
        public void Should_be_invalid_when_field_value_is_missing()
        {
            //Arrange
            var point = new Point
            {
                Measurement = "x",
                Fields      = new Dictionary <string, object> {
                    { "A", null }
                },
                Tags = new Dictionary <string, object> {
                    { "B", "2" }
                }
            };
            var validator = new PointValidator();

            //Act
            var response = validator.Validate(point);

            //Assert
            Assert.That(response, Is.Not.Empty);
            Assert.That(response.First(), Is.EqualTo("Value missing for field A for measurement x."));
        }