コード例 #1
0
        public void Should_Fail_When_Cidr_Has_Two_Ranges()
        {
            const string cidr = "10.0.0.0/24/24";
            var validatorMock = new Mock<ICloudNetworksValidator>();
            validatorMock.Setup(v => v.ValidateCidr(cidr));

            try
            {
                var cloudNetworksValidator = new CloudNetworksValidator();
                cloudNetworksValidator.ValidateCidr(cidr);
                Assert.Fail("Expected CidrFormatException was not thrown");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(string.Format("ERROR: CIDR {0} must have exactly one / character", cidr), ex.Message);
            }
        }
コード例 #2
0
        public void Should_Fail_When_Cidr_Missing_Slash()
        {
            const string cidr = "10.0.0.0";
            var validatorMock = new Mock<ICloudNetworksValidator>();
            validatorMock.Setup(v => v.ValidateCidr(cidr));

            try
            {
                var cloudNetworksValidator = new CloudNetworksValidator();
                cloudNetworksValidator.ValidateCidr(cidr);
                Assert.Fail("Expected CidrFormatException was not thrown");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(string.Format("ERROR: CIDR {0} is missing /", cidr), ex.Message);
            }
        }
コード例 #3
0
        public void Should_Fail_When_Null_Cidr()
        {
            const string cidr = null;
            var validatorMock = new Mock<ICloudNetworksValidator>();
            validatorMock.Setup(v => v.ValidateCidr(cidr));

            try
            {
                var cloudNetworksValidator = new CloudNetworksValidator();
                cloudNetworksValidator.ValidateCidr(cidr);
                Assert.Fail("Expected CidrFormatException was not thrown");
            }
            catch (Exception ex)
            {

                Assert.AreEqual("ERROR: CIDR cannot be null\r\nParameter name: cidr", ex.Message);
            }
        }
コード例 #4
0
        public void Should_Fail_When_Cidr_Has_Invalid_IP_Segment()
        {
            const string cidr = "10.0.0.256/24";
            var validatorMock = new Mock<ICloudNetworksValidator>();
            validatorMock.Setup(v => v.ValidateCidr(cidr));

            try
            {
                var cloudNetworksValidator = new CloudNetworksValidator();
                cloudNetworksValidator.ValidateCidr(cidr);
                Assert.Fail("Expected CidrFormatException was not thrown");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(string.Format("ERROR: IP address segment ({0}) of CIDR is not a valid IP address", "10.0.0.256"), ex.Message);
            }
        }
コード例 #5
0
        public void Should_Pass_When_Cidr_Has_IPV6_IP_Segment()
        {
            const string cidr = "2001:db8::/32";
            var validatorMock = new Mock<ICloudNetworksValidator>();
            validatorMock.Setup(v => v.ValidateCidr(cidr));

            var cloudNetworksValidator = new CloudNetworksValidator();
            cloudNetworksValidator.ValidateCidr(cidr);
        }
コード例 #6
0
        public void Should_Fail_When_Cidr_Has_Invalid_Range()
        {
            const string cidr = "10.0.0.0/33";
            var validatorMock = new Mock<ICloudNetworksValidator>();
            validatorMock.Setup(v => v.ValidateCidr(cidr));

            try
            {
                var cloudNetworksValidator = new CloudNetworksValidator();
                cloudNetworksValidator.ValidateCidr(cidr);
                Assert.Fail("Expected CidrFormatException was not thrown");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(string.Format("ERROR: CIDR range segment {0} must be between 1 and 32", "33"), ex.Message);
            }
        }
コード例 #7
0
        public void Should_Pass_When_Cidr_Has_IPV4_IP_Segment()
        {
            const string cidr = "192.0.2.0/24";
            var validatorMock = new Mock<INetworksValidator>();
            validatorMock.Setup(v => v.ValidateCidr(cidr));

            var cloudNetworksValidator = new CloudNetworksValidator();
            cloudNetworksValidator.ValidateCidr(cidr);
        }