public void Should_return_some_if_some_are_valid()
        {
            //Arrange
            var points = new[]
            {
                new Point
                {
                    Measurement = "x",
                    Fields      = new Dictionary <string, object> {
                        { "A", "1" }
                    },
                    Tags = new Dictionary <string, object> {
                        { "B", "2" }
                    }
                },
                new Point
                {
                },
            };
            var validator = new PointValidator();

            //Act
            var response = validator.Clean(points);

            //Assert
            Assert.That(response, Is.Not.Empty);
            Assert.That(response.Count(), Is.EqualTo(1));
        }
Пример #2
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);
        }
Пример #3
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."));
        }
        public void Should_return_none_if_none_are_valud()
        {
            //Arrange
            var points = new[]
            {
                new Point
                {
                },
                new Point
                {
                },
            };
            var validator = new PointValidator();

            //Act
            var response = validator.Clean(points);

            //Assert
            Assert.That(response, Is.Empty);
        }
Пример #5
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."));
        }
Пример #6
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);
            }
        }
Пример #7
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."));
        }