示例#1
0
        public void all_predicates()
        {
            XRecord record;
            DnsName owner = DnsName.Parse("test.com.");

            byte[]          rdata          = new byte[0];
            DnsRecordType[] allRecordTypes = (DnsRecordType[])Enum.GetValues(typeof(DnsRecordType));

            foreach (PredicateTestCase @case in PREDICATE_TEST_CASES)
            {
                Assert.IsFalse(@case.Predicate(null));
                foreach (DnsRecordType type in @case.Types)
                {
                    record = new XRecord(owner, type, DnsRecordClass.IN, TimeSpan.FromHours(1), rdata);
                    Assert.IsTrue(@case.Predicate(record), "{0} expected to return true for {1}", @case.Predicate.Method, type);
                }
                foreach (DnsRecordType type in allRecordTypes)
                {
                    if ([email protected](type))
                    {
                        record = new XRecord(owner, type, DnsRecordClass.IN, TimeSpan.FromHours(1), rdata);
                        Assert.IsFalse(@case.Predicate(record), "{0} expected to return false for {1}", @case.Predicate.Method, type);
                    }
                }
            }
        }
示例#2
0
        private static DnsName ReadName(byte[] buffer, int offset, out int next)
        {
            StringBuilder sb = new StringBuilder();

            ReadName(sb, buffer, offset, 0, out next);

            return(DnsName.Parse(sb.ToString()));
        }
示例#3
0
        /// <summary>
        /// Makes an SRV query name for the specified <paramref name="service"/>,
        /// <paramref name="protocol"/> and <paramref name="name"/>.
        /// </summary>
        /// <param name="service">The requested service.</param>
        /// <param name="protocol">The requested protocol.</param>
        /// <param name="name">The name.</param>
        /// <returns>The SRV query name for the specified <paramref name="service"/>,
        /// <paramref name="protocol"/> and <paramref name="name"/>.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="service"/>, <paramref name="protocol"/> or
        /// <paramref name="name"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsFormatException">
        /// Thrown when the format of the resultant name is invalid because of:
        /// <list type="bullet">
        /// <item><paramref name="service"/> contains invalid characters</item>
        /// <item>the length <paramref name="service"/> is greater than the maximum label
        /// length</item>
        /// <item><paramref name="protocol"/> contains invalid characters</item>
        /// <item>the length <paramref name="protocol"/> is greater than the maximum label
        /// length</item>
        /// <item>the length of the resultant name is greater than
        /// <see cref="AK.Net.Dns.DnsName.MaxLength"/></item>
        /// </list>
        /// </exception>
        public static DnsName MakeName(string service, string protocol, DnsName name)
        {
            Guard.NotNull(service, "service");
            Guard.NotNull(protocol, "protocol");
            Guard.NotNull(name, "name");

            return(DnsName.Parse(string.Format("_{0}._{1}.{2}", service, protocol, name.Name)));
        }
 public EquivalenceClassCollection <DnsQuestion> GetEquivalenceClasses()
 {
     return(EquivalenceClassCollection <DnsQuestion> .FromDistinctInstances(
                new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.Any),
                new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.CH),
                new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.HS),
                new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.IN),
                new DnsQuestion(DnsName.Parse("test.co.uk"), DnsQueryType.A, DnsQueryClass.IN)
                ));
 }
        public void ctor_sets_correct_properties()
        {
            DnsQueryClass cls      = DnsQueryClass.IN;
            DnsQueryType  type     = DnsQueryType.A;
            DnsName       name     = DnsName.Parse("test.com");
            DnsQuestion   question = new DnsQuestion(name, type, cls);

            Assert.AreEqual(cls, question.Class);
            Assert.AreEqual(type, question.Type);
            Assert.AreEqual(name, question.Name);
        }
示例#6
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the
        /// pecified context and culture information.
        /// </summary>
        /// <param name="context">
        /// An <see cref="System.ComponentModel.ITypeDescriptorContext"/> that
        /// provides a format context.
        /// </param>
        /// <param name="culture">
        /// The <see cref="System.Globalization.CultureInfo"/> to use as the
        /// current culture.
        /// </param>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// An object that represents the converted value.
        /// </returns>
        /// <exception cref="System.NotSupportedException">
        /// The conversion cannot be performed.
        /// </exception>
        public override object ConvertFrom(ITypeDescriptorContext context,
                                           CultureInfo culture, object value)
        {
            string nameString = value as string;

            if (nameString != null)
            {
                return(DnsName.Parse(nameString));
            }

            return(base.ConvertFrom(context, culture, value));
        }
示例#7
0
        private static DnsName MakeIPv4Name(IPAddress address)
        {
            byte[]        bytes = address.GetAddressBytes();
            StringBuilder sb    = new StringBuilder();

            for (int i = bytes.Length - 1; i >= 0; --i)
            {
                sb.Append(bytes[i].ToString(DnsUtility.DnsCulture)).Append('.');
            }
            sb.Append(PtrRecord.IPv4NameSuffix);

            return(DnsName.Parse(sb.ToString()));
        }
        public void write_writes_data_in_correct_order_and_with_correct_arguments()
        {
            MockRepository mocks    = new MockRepository();
            IDnsWriter     writer   = mocks.StrictMock <IDnsWriter>();
            DnsQuestion    question = new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.MX, DnsQueryClass.IN);

            using (mocks.Ordered()) {
                writer.WriteName(question.Name);
                writer.WriteQueryType(question.Type);
                writer.WriteQueryClass(question.Class);
            }
            mocks.ReplayAll();
            question.Write(writer);
            mocks.VerifyAll();
        }
示例#9
0
        public void exchanges_is_readonly_list()
        {
            MXInfo info = new MXInfo(DOMAIN, EXCHANGES);

            info.Exchanges.Add(DnsName.Parse("mx5.test.com"));
        }
示例#10
0
        public void write_throws_if_writer_is_null()
        {
            DnsQuestion question = new DnsQuestion(DnsName.Parse("test.com"), DnsQueryType.A, DnsQueryClass.IN);

            question.Write(null);
        }