コード例 #1
0
		public void Init()
		{
			Thread.CurrentThread.CurrentCulture =
				Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

			validator = new NullableDecimalValidator();
			validator.Initialize(new CachedValidationRegistry(), typeof(TestTarget).GetProperty("TargetField"));
			target = new TestTarget();
		}
コード例 #2
0
        public void ValidateDecimalToBeApproximatelyValue()
        {
            // Given
            var validator = new NullableDecimalValidator(42.12345m);

            // When
            validator.BeApproximately(42.123m, 0.1m);

            // Then
            Assert.True(true);
        }
コード例 #3
0
        public void ValidateSByteToBePositive()
        {
            // Given
            var validator = new NullableDecimalValidator(0);

            // When
            validator.BePositive();

            // Then
            Assert.True(true);
        }
コード例 #4
0
        public void ValidateNullableDecimalToBeOneOfExpectedValues()
        {
            // Given
            var validator = new NullableDecimalValidator(null);

            // When
            validator.BeOneOf(new decimal?[] { 10, null });

            // Then
            Assert.True(true);
        }
コード例 #5
0
        public void ValidateNullableDecimalToBeNull()
        {
            // Given
            var validator = new NullableDecimalValidator(null);

            // When
            validator.BeNull();

            // Then
            Assert.True(true);
        }
コード例 #6
0
        public void ValidateDecimalToBeLessThanOrEqualToEqualValue()
        {
            // Given
            var validator = new NullableDecimalValidator(42);

            // When
            validator.BeLessThanOrEqualTo(42);

            // Then
            Assert.True(true);
        }
コード例 #7
0
        public void ValidateDecimalToBeGreaterThanOrEqualToSmallerValue()
        {
            // Given
            var validator = new NullableDecimalValidator(42);

            // When
            validator.BeGreaterThanOrEqualTo(13);

            // Then
            Assert.True(true);
        }
コード例 #8
0
        public void ValidateDecimalToBeBetweenValues()
        {
            // Given
            var validator = new NullableDecimalValidator(42);

            // When
            validator.BeBetween(13, 100);

            // Then
            Assert.True(true);
        }
コード例 #9
0
        public void ValidateDecimalToBeApproximatelyValueViolated()
        {
            // Given
            var validator = new NullableDecimalValidator(42.12345m);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeApproximately(42m, 0.01m, "that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"42,12345\"{rn}but was expected to be approximately \"42\" (+/- 0,01){rn}because that's the bottom line",
                exception.UserMessage);
        }
コード例 #10
0
        public void ValidateSByteToBePositiveViolated()
        {
            // Given
            var validator = new NullableDecimalValidator(-42);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BePositive(because: "that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"-42\"{rn}but was expected to have a positive value{rn}because that's the bottom line",
                exception.UserMessage);
        }
コード例 #11
0
        public void ValidateDecimalToBeOneOfViolated()
        {
            // Given
            var validator = new NullableDecimalValidator(42);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeOneOf(new decimal?[] { 13, 39 }, because: "that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"42\"{rn}but was expected to be one of the following values: \"13\", \"39\"{rn}because that's the bottom line",
                exception.UserMessage);
        }
コード例 #12
0
        public void ValidateNullableToBeNullWithReasonViolated()
        {
            // Given
            var validator = new NullableDecimalValidator(0);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeNull("that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"0\"{rn}but was expected to be null{rn}because that's the bottom line",
                exception.UserMessage);
        }
コード例 #13
0
        public void ValidateNullableDecimalToBeLessThanOrEqualToValueViolated()
        {
            // Given
            var validator = new NullableDecimalValidator(null);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeLessThanOrEqualTo(13, "that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"\"{rn}but was expected to be less than or equal to \"13\"{rn}because that's the bottom line",
                exception.UserMessage);
        }
コード例 #14
0
        public void ValidateDecimalToBeGreaterThanValueViolated()
        {
            // Given
            var validator = new NullableDecimalValidator(42);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeGreaterThan(42, "that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"42\"{rn}but was expected to be greater than \"42\"{rn}because that's the bottom line",
                exception.UserMessage);
        }
コード例 #15
0
        public void ValidateNullableDecimalToBeBetweenValuesMinimumAndMaximumViolated()
        {
            // Given
            var validator = new NullableDecimalValidator(null);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeBetween(100, 13, "that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"\"{rn}but was expected to be between \"100\" and \"13\"{rn}because that's the bottom line",
                exception.UserMessage);
        }