Ejemplo n.º 1
0
        public void Create_CreateRecordFuncThrowsException_ExceptionIsPropogated()
        {
            var source       = new object();
            var record       = new object();
            var createRecord = new Func <object, object, object>((src, rt) => throw new InternalTestFailureException());

            var recordFactory = new RecordFactory(createRecord);

            recordFactory.Create(source);
        }
Ejemplo n.º 2
0
        public void Create_RecordTypeProviderIsNotProvided_RecordIsCreated()
        {
            var source       = new object();
            var record       = new object();
            var createRecord = new Func <object, object, object>((src, rt) => src.Equals(source) ? record : null);

            var recordFactory = new RecordFactory(createRecord);

            var returnedRecord = recordFactory.Create(source);

            Assert.AreEqual(record, returnedRecord);
        }
Ejemplo n.º 3
0
        public void Create_RecordTypeProviderThrowsException_ExceptionIsPropogated()
        {
            var source             = new object();
            var record             = new object();
            var recordType         = "RecordType";
            var createRecord       = new Func <object, object, object>((src, rt) => src.Equals(source) && rt.Equals(recordType) ? record : null);
            var recordTypeProvider = MockRepository.GenerateMock <IRecordTypeProvider>();

            recordTypeProvider.Stub(x => x.GetRecordType(Arg <object> .Is.Anything)).Throw(new InternalTestFailureException());

            var recordFactory = new RecordFactory(createRecord, recordTypeProvider);

            recordFactory.Create(source);
        }
Ejemplo n.º 4
0
        public void Create_RecordTypeProviderIsProvided_RecordIsCreated()
        {
            var source             = new object();
            var record             = new object();
            var recordType         = "RecordType";
            var createRecord       = new Func <object, object, object>((src, rt) => src.Equals(source) && rt.Equals(recordType) ? record : null);
            var recordTypeProvider = MockRepository.GenerateMock <IRecordTypeProvider>();

            recordTypeProvider.Expect(x => x.GetRecordType(Arg <object> .Is.Equal(source))).Return(recordType).Repeat.Once();

            var recordFactory = new RecordFactory(createRecord, recordTypeProvider);

            var returnedRecord = recordFactory.Create(source);

            recordTypeProvider.VerifyAllExpectations();

            Assert.AreEqual(record, returnedRecord);
        }
Ejemplo n.º 5
0
        public void ParseResponse(byte[] recvBytes, int length)
        {
            MemoryStream memoryStream = new MemoryStream(recvBytes, 0, length);

            byte[] flagBytes              = new byte[2];
            byte[] transactionId          = new byte[2];
            byte[] questions              = new byte[2];
            byte[] answerRRs              = new byte[2];
            byte[] authorityRRs           = new byte[2];
            byte[] additionalRRCountBytes = new byte[2];
            byte[] nsType  = new byte[2];
            byte[] nsClass = new byte[2];

            this._bytesReceived = length;

            // Parse DNS Response
            memoryStream.Read(transactionId, 0, 2);
            memoryStream.Read(flagBytes, 0, 2);
            memoryStream.Read(questions, 0, 2);
            memoryStream.Read(answerRRs, 0, 2);
            memoryStream.Read(authorityRRs, 0, 2);
            memoryStream.Read(additionalRRCountBytes, 0, 2);

            // Parse Header
            _transactionId = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(transactionId, 0));
            _flags         = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(flagBytes, 0));
            _queryResponse = (QueryResponse)(_flags & (ushort)FlagMasks.QueryResponseMask);
            _opCode        = (OpCode)(_flags & (ushort)FlagMasks.OpCodeMask);
            _nsFlags       = (NsFlags)(_flags & (ushort)FlagMasks.NsFlagMask);
            _rCode         = (RCode)(_flags & (ushort)FlagMasks.RCodeMask);

            // Parse Questions Section
            _questions    = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(questions, 0));
            _answerRRs    = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(answerRRs, 0));
            _authorityRRs = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(authorityRRs, 0));
            ushort additionalRRCount = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(additionalRRCountBytes, 0));

            _additionalRecords      = new List <IDnsRecord>();
            _answers                = new DnsRecordBase[_answerRRs];
            _authoritiveNameServers = new DnsRecordBase[_authorityRRs];

            // Parse Queries
            _queryRequest = this.ParseQuery(ref memoryStream);

            // Read dnsType
            memoryStream.Read(nsType, 0, 2);

            // Read dnsClass
            memoryStream.Read(nsClass, 0, 2);

            _nsType  = (NsType)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsType, 0));
            _nsClass = (NsClass)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsClass, 0));

            // Read in Answer Blocks
            for (int i = 0; i < _answerRRs; i++)
            {
                _answers[i] = RecordFactory.Create(ref memoryStream);
            }

            // Parse Authority Records
            for (int i = 0; i < _authorityRRs; i++)
            {
                _authoritiveNameServers[i] = RecordFactory.Create(ref memoryStream);
            }

            // Parse Additional Records
            for (int i = 0; i < additionalRRCount; i++)
            {
                _additionalRecords.Add(RecordFactory.Create(ref memoryStream));
            }
        }