예제 #1
0
        public void ValidateNullStringToBeNull()
        {
            // Given
            var validator = new StringValidator(null);

            // When
            validator.Be(null);

            // Then
            Assert.True(true);
        }
예제 #2
0
        public void ValidateStringToBeValue()
        {
            // Given
            var validator = new StringValidator("string");

            // When
            validator.Be("string");

            // Then
            Assert.True(true);
        }
예제 #3
0
        public void ValidateStringToBeCaseInsensitiveValue()
        {
            // Given
            var validator = new StringValidator("string");

            // When
            validator.Be("STRING", ignoreCase: true);

            // Then
            Assert.True(true);
        }
예제 #4
0
        public void OverrideMessageFormatterSuccess()
        {
            // Given

            // When
            TestConfiguration.SetMessageFormatterFor(nameof(TestConfigurationTest.OverrideMessageFormatterSuccess), new MockFormatter());
            var validator = new StringValidator("foo"); // use a StringValidator here as one implementation of a ContextValidator
            var exception = Assert.Throws <XunitException>(() => validator.Be("bar"));

            // Then
            Assert.NotNull(exception);
            Assert.Equal("MockMessage", exception.Message);
        }
예제 #5
0
        public void OverrideCallerContextSuccess()
        {
            // Given

            // When
            TestConfiguration.SetCallerContextFor(nameof(TestConfigurationTest.OverrideCallerContextSuccess), new MockContext());
            var validator = new StringValidator("foo"); // use a StringValidator here as one implementation of a ContextValidator
            var exception = Assert.Throws <XunitException>(() => validator.Be("bar"));

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

            Assert.Equal($"{rn}MockContext{rn}is \"foo\"{rn}but was expected to be \"bar\"", exception.Message);
        }
예제 #6
0
        public void ValidateStringToBeCaseSensitiveValueViolated()
        {
            // Given
            var validator = new StringValidator("string");

            // When
            var exception = Assert.Throws <XunitException>(() => validator.Be("STRING"));

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

            Assert.Equal(
                $"{rn}validator{rn}is \"string\"{rn}but was expected to be \"STRING\"",
                exception.UserMessage);
        }
예제 #7
0
        public void ValidateNullStringToBeValueViolated()
        {
            // Given
            var validator = new StringValidator(null);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.Be("other"));

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

            Assert.Equal(
                $"{rn}validator{rn}is \"\"{rn}but was expected to be \"other\"",
                exception.UserMessage);
        }
예제 #8
0
        public void ValidateStringToBeValueViolated()
        {
            // Given
            var validator = new StringValidator("string");

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

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

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