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); }
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_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.")); }
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); } }
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.")); }