public async Task MarksFailedRecordsCorrectlyWhen3Failures() { string domain = "a.b.com"; DomainEntity domainEntity = new DomainEntity(1, domain); DmarcRecordInfo existingRecord = new DmarcRecordInfo("existing record"); Dictionary <DomainEntity, List <RecordEntity> > records = new Dictionary <DomainEntity, List <RecordEntity> > { { domainEntity, new List <RecordEntity> { new RecordEntity(1, domainEntity, existingRecord, RCode.ServFail, 3) } } }; A.CallTo(() => _dnsRecordClient.GetRecord(domain)).Returns(Task.FromResult(new DnsResponse(new List <RecordInfo> { DmarcRecordInfo.EmptyRecordInfo }, RCode.ServFail))); List <RecordEntity> updatedRecords = await _dnsRecordsUpdater.UpdateRecord(records); Assert.That(updatedRecords.Count, Is.EqualTo(2)); Assert.That(updatedRecords[0].EndDate, Is.Not.Null); Assert.That(updatedRecords[0].RecordInfo, Is.EqualTo(existingRecord)); Assert.That(updatedRecords[0].FailureCount, Is.EqualTo(3)); Assert.That(updatedRecords[0].ResponseCode, Is.EqualTo(RCode.ServFail)); Assert.That(updatedRecords[1].EndDate, Is.Null); Assert.That(updatedRecords[1].RecordInfo, Is.EqualTo(null)); Assert.That(updatedRecords[1].FailureCount, Is.EqualTo(-1)); Assert.That(updatedRecords[1].ResponseCode, Is.EqualTo(RCode.ServFail)); }
public async Task NewRecordsCorrectlyCreated() { string domain = "a.b.com"; DomainEntity domainEntity = new DomainEntity(1, domain); DmarcRecordInfo existingRecord = new DmarcRecordInfo("existing record"); DmarcRecordInfo newRecord = new DmarcRecordInfo("new record"); Dictionary <DomainEntity, List <RecordEntity> > records = new Dictionary <DomainEntity, List <RecordEntity> > { { domainEntity, new List <RecordEntity> { new RecordEntity(1, domainEntity, existingRecord, RCode.NoError, 0) } } }; A.CallTo(() => _dnsRecordClient.GetRecord(domain)).Returns(Task.FromResult(new DnsResponse(new List <RecordInfo> { newRecord }, RCode.NoError))); List <RecordEntity> updatedRecords = await _dnsRecordsUpdater.UpdateRecord(records); Assert.That(updatedRecords.Count, Is.EqualTo(2)); Assert.That(updatedRecords[1].Id, Is.Null); Assert.That(updatedRecords[1].EndDate, Is.Null); Assert.That(updatedRecords[1].RecordInfo, Is.EqualTo(newRecord)); }
protected override void AddCommandParmeters(MySqlCommand command, RecordEntity record, int index) { DmarcRecordInfo recordInfo = record.RecordInfo as DmarcRecordInfo; command.Parameters.AddWithValue($"a{index}", record.Id); command.Parameters.AddWithValue($"b{index}", record.Domain.Id); command.Parameters.AddWithValue($"c{index}", recordInfo?.Record); command.Parameters.AddWithValue($"d{index}", record.EndDate); command.Parameters.AddWithValue($"e{index}", record.FailureCount); command.Parameters.AddWithValue($"f{index}", (ushort)record.ResponseCode); }
private RecordEntity CreateRecordEntity(DbDataReader reader, int?recordId, DomainEntity domain) { DmarcRecordInfo dmarcRecordInfo = reader.GetString("record") == null ? DmarcRecordInfo.EmptyRecordInfo : new DmarcRecordInfo(reader.GetString("record")); return(new RecordEntity( recordId, domain, dmarcRecordInfo, (RCode)reader.GetInt16("result_code"), reader.GetInt16("failure_count"))); }
public async Task FailureCountClearedOutOnSuccessfulResponse() { string domain = "a.b.com"; DomainEntity domainEntity = new DomainEntity(1, domain); DmarcRecordInfo existingRecord = new DmarcRecordInfo("existing record"); Dictionary <DomainEntity, List <RecordEntity> > records = new Dictionary <DomainEntity, List <RecordEntity> > { { domainEntity, new List <RecordEntity> { new RecordEntity(1, domainEntity, existingRecord, RCode.ServFail, 1) } } }; A.CallTo(() => _dnsRecordClient.GetRecord(domain)).Returns(Task.FromResult(new DnsResponse(new List <RecordInfo> { DmarcRecordInfo.EmptyRecordInfo }, RCode.NoError))); List <RecordEntity> updatedRecords = await _dnsRecordsUpdater.UpdateRecord(records); Assert.That(updatedRecords.Count, Is.EqualTo(2)); Assert.That(updatedRecords[0].FailureCount, Is.EqualTo(1)); Assert.That(updatedRecords[1].FailureCount, Is.EqualTo(0)); }
public async Task ExistingRecordsRemainUntouched() { string domain = "a.b.com"; DomainEntity domainEntity = new DomainEntity(1, domain); DmarcRecordInfo existingRecord = new DmarcRecordInfo("record", string.Empty, false, false); DmarcRecordInfo incomingRecord = new DmarcRecordInfo("record", string.Empty, false, false); Dictionary <DomainEntity, List <RecordEntity> > records = new Dictionary <DomainEntity, List <RecordEntity> > { { domainEntity, new List <RecordEntity> { new RecordEntity(1, domainEntity, incomingRecord, RCode.NoError, 0) } } }; A.CallTo(() => _dnsRecordClient.GetRecord(domain)).Returns(Task.FromResult(new DnsResponse(new List <RecordInfo> { existingRecord }, RCode.NoError))); List <RecordEntity> updatedRecords = await _dnsRecordsUpdater.UpdateRecord(records); Assert.That(updatedRecords.Count, Is.EqualTo(1)); Assert.That(updatedRecords[0].EndDate, Is.Null); Assert.That(updatedRecords[0].RecordInfo, Is.EqualTo(existingRecord)); }
protected bool Equals(DmarcRecordInfo other) { return(string.Equals(Record, other.Record) && string.Equals(OrgDomain, other.OrgDomain) && IsTld == other.IsTld && IsInherited == other.IsInherited); }
protected bool Equals(DmarcRecordInfo other) { return(string.Equals(Record, other.Record)); }