Пример #1
0
        public void TryParse_given_postalCodeAndLocality_maps_postalCode_and_locality(string postalCodeAndLocality, string expectedPostalCode, string expectedLocality)
        {
            var parsed = PostalCodeValidator.TryParse(postalCodeAndLocality, out var postalCode, out var locality);

            Assert.Equal(expectedPostalCode, postalCode);
            Assert.Equal(expectedLocality, locality);
        }
Пример #2
0
        public void TryParse_given_2000_Frederiksberg_returns_true()
        {
            var valid = PostalCodeValidator.TryParse("2000 Frederiksberg", out var postalCode, out var locality);

            Assert.True(valid);
            Assert.Equal("2000", postalCode);
            Assert.Equal("Frederiksberg", locality);
        }
Пример #3
0
        public void TryParse_given_2720_Vanløse_returns_true()
        {
            var valid = PostalCodeValidator.TryParse("2720 Vanløse", out var postalCode, out var locality);

            Assert.True(valid);
            Assert.Equal("2720", postalCode);
            Assert.Equal("Vanløse", locality);
        }
Пример #4
0
        public void TryParse_given_postal_code_and_locality_outs_locality(string postalCodeAndLocality, string expectedLocality)
        {
            var val = new PostalCodeValidator();

            val.TryParse(postalCodeAndLocality, out var _, out var actualLocality);

            Assert.Equal(expectedLocality, actualLocality);
        }
Пример #5
0
        public void TryParse_given_postal_code_and_locality_returns_true(string postalCodeAndLocality)
        {
            var val = new PostalCodeValidator();

            var actual = val.TryParse(postalCodeAndLocality, out var _, out var _);

            Assert.True(actual);
        }
Пример #6
0
        public void IsValid_given_invalid_code_returns_true(string code)
        {
            var val = new PostalCodeValidator();

            var actual = val.IsValid(code);

            Assert.False(actual);
        }
Пример #7
0
        public void IsValid_given_2000_returns_true()
        {
            // Arrange
            var postalCode = "2000";

            // Act
            var valid = PostalCodeValidator.IsValid(postalCode);

            // Assert
            Assert.True(valid);
        }
Пример #8
0
        public void CodeIsNull()
        {
            // Arrange
            var validator = new PostalCodeValidator(null, codeService);

            //Act
            validator.Validate(controller.ModelState);

            // Assert
            controller.ModelState.IsValid.Should().BeTrue();
        }
Пример #9
0
        public void IsValid_given_2000foo_returns_false()
        {
            // Arrange
            var postalCode = "2000foo";

            // Act
            var valid = PostalCodeValidator.IsValid(postalCode);

            // Assert
            Assert.False(valid);
        }
Пример #10
0
        public void TryParse_given_2000_Frederiksberg_returns_true_and_outs_values()
        {
            var    input = "2000 Frederiksberg";
            string postalCode;
            string locality;

            var actual = PostalCodeValidator.TryParse(input, out postalCode, out locality);

            Assert.True(actual);
            Assert.Equal("2000", postalCode);
            Assert.Equal("Frederiksberg", locality);
        }
Пример #11
0
        public void CodeNotExistsCodeServiceReturnsEmpty()
        {
            // Arrange
            codeServiceMockSetup.Setup(c => c.GetPostalCodeByCode(It.IsAny <string>(), false)).Returns(string.Empty);
            var validator = new PostalCodeValidator("code", codeServiceMockSetup.Object);

            //Act
            validator.Validate(controller.ModelState);

            // Assert
            controller.ModelState.IsValid.Should().BeFalse();
        }
Пример #12
0
        public void IsValid()
        {
            var v = new PostalCodeValidator();

            Assert.IsTrue(v.IsValid("12-345", null));
            Assert.IsTrue(v.IsValid(null, null));
            Assert.IsTrue(v.IsValid(string.Empty, null));

            Assert.IsFalse(v.IsValid("12 -345", null));
            Assert.IsFalse(v.IsValid("12345", null));
            Assert.IsFalse(v.IsValid(" 12-345", null));
            Assert.IsFalse(v.IsValid("12-345 ", null));
        }
Пример #13
0
        public void TryParse_given_2100_København_Ø_return_true_and_sets_fields()
        {
            // Arrange
            var    postalCodeAndLocality = "2100 København Ø";
            string postalCode;
            string locality;

            // Act
            var valid = PostalCodeValidator.TryParse(postalCodeAndLocality,
                                                     out postalCode, out locality);

            // Assert
            Assert.True(valid);
            Assert.Equal("2100", postalCode);
            Assert.Equal("København Ø", locality);
        }
Пример #14
0
        public void IsValid_given_2000_returns_true()
        {
            var valid = PostalCodeValidator.IsValid("2000");

            Assert.True(valid);
        }
Пример #15
0
        public void IsValid_given_postalCode_returns_expected(string postalCode, bool expected)
        {
            var valid = PostalCodeValidator.IsValid(postalCode);

            Assert.Equal(expected, valid);
        }
Пример #16
0
        public void IsValid_given_100_Tórshavn_returns_true()
        {
            var valid = PostalCodeValidator.IsValid("100");

            Assert.True(valid);
        }
Пример #17
0
        public void TryParse_given_postalCodeAndLocality_returns_true(string postalCodeAndLocality)
        {
            var parsed = PostalCodeValidator.TryParse(postalCodeAndLocality, out var _, out var _);

            Assert.True(parsed);
        }
Пример #18
0
        public void IsValid_given_2000x_returns_false()
        {
            var valid = PostalCodeValidator.IsValid("2000x");

            Assert.False(valid);
        }
Пример #19
0
        public void IsValid_given_2000_returns_true()
        {
            var actual = PostalCodeValidator.IsValid("2000");

            Assert.True(actual);
        }