@@ -8,40 +8,55 @@ public sealed class ComplexTest
88 [ TestMethod ]
99 public void TryParse_ValidDmarcString1_ReturnsTrueAndPopulatesDmarcRecord ( )
1010 {
11- var dmarcRecord = "v=DMARC1; p=reject; rua=mailto:[email protected] , mailto:[email protected] ; pct=100; adkim=s; aspf=s" ; 11+ var recordRaw = "v=DMARC1; p=reject; rua=mailto:[email protected] , mailto:[email protected] ; pct=100; adkim=s; aspf=s" ; 1212
13- var isSuccessful = DmarcRecordDataFragmentParser . TryParse ( dmarcRecord , out var dmarcDataFragment , out var parsingResults ) ;
13+ var isSuccessful = DmarcRecordDataFragmentParser . TryParse ( recordRaw , out var dataFragment , out var parsingResults ) ;
1414
1515 Assert . IsTrue ( isSuccessful ) ;
16- Assert . IsNotNull ( dmarcDataFragment ) ;
17- Assert . AreEqual ( "reject" , dmarcDataFragment . DomainPolicy ) ;
18- Assert . AreEqual ( "mailto:[email protected] , mailto:[email protected] " , dmarcDataFragment . AggregateReportUri ) ; 19- Assert . AreEqual ( "100" , dmarcDataFragment . PolicyPercentage ) ;
20- Assert . AreEqual ( "s" , dmarcDataFragment . DkimAlignmentMode ) ;
21- Assert . AreEqual ( "s" , dmarcDataFragment . SpfAlignmentMode ) ;
16+ Assert . IsNotNull ( dataFragment ) ;
2217 Assert . IsNull ( parsingResults , "ParsingResults is not null" ) ;
18+
19+ if ( dataFragment is not DmarcRecordDataFragmentV1 dataFragmentV1 )
20+ {
21+ Assert . Fail ( "Wrong DmarcRecordDataFragmentV1 class" ) ;
22+ return ;
23+ }
24+
25+ Assert . AreEqual ( "reject" , dataFragmentV1 . DomainPolicy ) ;
26+ Assert . AreEqual ( "mailto:[email protected] , mailto:[email protected] " , dataFragmentV1 . AggregateReportUri ) ; 27+ Assert . AreEqual ( "100" , dataFragmentV1 . PolicyPercentage ) ;
28+ Assert . AreEqual ( "s" , dataFragmentV1 . DkimAlignmentMode ) ;
29+ Assert . AreEqual ( "s" , dataFragmentV1 . SpfAlignmentMode ) ;
2330 }
2431
2532 [ TestMethod ]
2633 public void TryParse_ValidDmarcString2_ReturnsTrueAndPopulatesDmarcRecord ( )
2734 {
28- var dmarcRecordRaw = "v=DMARC1; p=reject; rua=mailto:[email protected] !10m, mailto:[email protected] ; pct=100; adkim=s; aspf=s" ; 35+ var recordRaw = "v=DMARC1; p=reject; rua=mailto:[email protected] !10m, mailto:[email protected] ; pct=100; adkim=s; aspf=s" ; 2936
30- var isDataFragmentParserSuccessful = DmarcRecordDataFragmentParser . TryParse ( dmarcRecordRaw , out var dmarcDataFragment , out var parsingResults ) ;
31- Assert . IsNotNull ( dmarcDataFragment ) ;
37+ var isDataFragmentParserSuccessful = DmarcRecordDataFragmentParser . TryParse ( recordRaw , out var dataFragment , out var parsingResults ) ;
3238
3339 Assert . IsTrue ( isDataFragmentParserSuccessful ) ;
34- Assert . IsNotNull ( dmarcDataFragment ) ;
35- Assert . AreEqual ( "reject" , dmarcDataFragment . DomainPolicy ) ;
36- Assert . AreEqual ( "mailto:[email protected] !10m, mailto:[email protected] " , dmarcDataFragment . AggregateReportUri ) ; 37- Assert . AreEqual ( "100" , dmarcDataFragment . PolicyPercentage ) ;
38- Assert . AreEqual ( "s" , dmarcDataFragment . DkimAlignmentMode ) ;
39- Assert . AreEqual ( "s" , dmarcDataFragment . SpfAlignmentMode ) ;
40+ Assert . IsNotNull ( dataFragment ) ;
4041 Assert . IsNull ( parsingResults , "ParsingResults is not null" ) ;
4142
42- var isParserSuccessful = DmarcRecordParser . TryParse ( dmarcDataFragment , out var dmarcRecord ) ;
43+ if ( dataFragment is not DmarcRecordDataFragmentV1 dataFragmentV1 )
44+ {
45+ Assert . Fail ( "Wrong DmarcRecordDataFragmentV1 class" ) ;
46+ return ;
47+ }
48+
49+ Assert . AreEqual ( "reject" , dataFragmentV1 . DomainPolicy ) ;
50+ Assert . AreEqual ( "mailto:[email protected] !10m, mailto:[email protected] " , dataFragmentV1 . AggregateReportUri ) ; 51+ Assert . AreEqual ( "100" , dataFragmentV1 . PolicyPercentage ) ;
52+ Assert . AreEqual ( "s" , dataFragmentV1 . DkimAlignmentMode ) ;
53+ Assert . AreEqual ( "s" , dataFragmentV1 . SpfAlignmentMode ) ;
54+
55+ var isParserSuccessful = DmarcRecordParser . TryParseV1 ( dataFragmentV1 , out var dmarcRecord ) ;
56+
4357 Assert . IsTrue ( isParserSuccessful ) ;
4458 Assert . IsNotNull ( dmarcRecord ) ;
59+
4560 Assert . AreEqual ( DmarcPolicy . Reject , dmarcRecord . DomainPolicy ) ;
4661 Assert . AreEqual ( DmarcPolicy . Reject , dmarcRecord . SubdomainPolicy ) ;
4762 Assert . AreEqual ( AlignmentMode . Strict , dmarcRecord . DkimAlignmentMode ) ;
@@ -52,23 +67,32 @@ public void TryParse_ValidDmarcString2_ReturnsTrueAndPopulatesDmarcRecord()
5267 [ TestMethod ]
5368 public void TryParse_ValidDmarcString3_ReturnsTrueAndPopulatesDmarcRecord ( )
5469 {
55- var dmarcRecordRaw = "v=DMARC1; p=reject; rua=mailto:[email protected] , mailto:[email protected] ; pct=50; adkim=r; aspf=r" ; 70+ var recordRaw = "v=DMARC1; p=reject; rua=mailto:[email protected] , mailto:[email protected] ; pct=50; adkim=r; aspf=r" ; 5671
57- var isDataFragmentParserSuccessful = DmarcRecordDataFragmentParser . TryParse ( dmarcRecordRaw , out var dmarcDataFragment , out var parsingResults ) ;
58- Assert . IsNotNull ( dmarcDataFragment ) ;
72+ var isDataFragmentParserSuccessful = DmarcRecordDataFragmentParser . TryParse ( recordRaw , out var dataFragment , out var parsingResults ) ;
5973
6074 Assert . IsTrue ( isDataFragmentParserSuccessful ) ;
61- Assert . IsNotNull ( dmarcDataFragment ) ;
62- Assert . AreEqual ( "reject" , dmarcDataFragment . DomainPolicy ) ;
63- Assert . AreEqual ( "mailto:[email protected] , mailto:[email protected] " , dmarcDataFragment . AggregateReportUri ) ; 64- Assert . AreEqual ( "50" , dmarcDataFragment . PolicyPercentage ) ;
65- Assert . AreEqual ( "r" , dmarcDataFragment . DkimAlignmentMode ) ;
66- Assert . AreEqual ( "r" , dmarcDataFragment . SpfAlignmentMode ) ;
75+ Assert . IsNotNull ( dataFragment ) ;
6776 Assert . IsNull ( parsingResults , "ParsingResults is not null" ) ;
6877
69- var isParserSuccessful = DmarcRecordParser . TryParse ( dmarcDataFragment , out var dmarcRecord ) ;
78+ if ( dataFragment is not DmarcRecordDataFragmentV1 dataFragmentV1 )
79+ {
80+ Assert . Fail ( "Wrong DmarcRecordDataFragmentV1 class" ) ;
81+ return ;
82+ }
83+
84+ Assert . AreEqual ( "reject" , dataFragmentV1 . DomainPolicy ) ;
85+ Assert . AreEqual ( "mailto:[email protected] , mailto:[email protected] " , dataFragmentV1 . AggregateReportUri ) ; 86+ Assert . AreEqual ( "50" , dataFragmentV1 . PolicyPercentage ) ;
87+ Assert . AreEqual ( "r" , dataFragmentV1 . DkimAlignmentMode ) ;
88+ Assert . AreEqual ( "r" , dataFragmentV1 . SpfAlignmentMode ) ;
89+
90+
91+ var isParserSuccessful = DmarcRecordParser . TryParseV1 ( dataFragmentV1 , out var dmarcRecord ) ;
92+
7093 Assert . IsTrue ( isParserSuccessful ) ;
7194 Assert . IsNotNull ( dmarcRecord ) ;
95+
7296 Assert . AreEqual ( DmarcPolicy . Reject , dmarcRecord . DomainPolicy ) ;
7397 Assert . AreEqual ( DmarcPolicy . Reject , dmarcRecord . SubdomainPolicy ) ;
7498 Assert . AreEqual ( AlignmentMode . Relaxed , dmarcRecord . DkimAlignmentMode ) ;
@@ -79,21 +103,28 @@ public void TryParse_ValidDmarcString3_ReturnsTrueAndPopulatesDmarcRecord()
79103 [ TestMethod ]
80104 public void TryParse_InvalidDmarcString1_ReturnsTrueAndPopulatesDmarcRecord ( )
81105 {
82- var dmarcRecordRaw = "v=DMARC1; p=reject; rua=mailto:[email protected] , mailto:[email protected] ; pct=50; adkim=t; aspf=t" ; 106+ var recordRaw = "v=DMARC1; p=reject; rua=mailto:[email protected] , mailto:[email protected] ; pct=50; adkim=t; aspf=t" ; 83107
84- var isDataFragmentParserSuccessful = DmarcRecordDataFragmentParser . TryParse ( dmarcRecordRaw , out var dmarcDataFragment , out var parsingResults ) ;
85- Assert . IsNotNull ( dmarcDataFragment ) ;
108+ var isDataFragmentParserSuccessful = DmarcRecordDataFragmentParser . TryParse ( recordRaw , out var dataFragment , out var parsingResults ) ;
86109
87110 Assert . IsTrue ( isDataFragmentParserSuccessful ) ;
88- Assert . IsNotNull ( dmarcDataFragment ) ;
89- Assert . AreEqual ( "reject" , dmarcDataFragment . DomainPolicy ) ;
90- Assert . AreEqual ( "mailto:[email protected] , mailto:[email protected] " , dmarcDataFragment . AggregateReportUri ) ; 91- Assert . AreEqual ( "50" , dmarcDataFragment . PolicyPercentage ) ;
92- Assert . AreEqual ( "t" , dmarcDataFragment . DkimAlignmentMode ) ;
93- Assert . AreEqual ( "t" , dmarcDataFragment . SpfAlignmentMode ) ;
111+ Assert . IsNotNull ( dataFragment ) ;
94112 Assert . IsNotNull ( parsingResults , "ParsingResults is null" ) ;
95113
96- var isParserSuccessful = DmarcRecordParser . TryParse ( dmarcDataFragment , out var dmarcRecord ) ;
114+ if ( dataFragment is not DmarcRecordDataFragmentV1 dataFragmentV1 )
115+ {
116+ Assert . Fail ( "Wrong DmarcRecordDataFragmentV1 class" ) ;
117+ return ;
118+ }
119+
120+ Assert . AreEqual ( "reject" , dataFragmentV1 . DomainPolicy ) ;
121+ Assert . AreEqual ( "mailto:[email protected] , mailto:[email protected] " , dataFragmentV1 . AggregateReportUri ) ; 122+ Assert . AreEqual ( "50" , dataFragmentV1 . PolicyPercentage ) ;
123+ Assert . AreEqual ( "t" , dataFragmentV1 . DkimAlignmentMode ) ;
124+ Assert . AreEqual ( "t" , dataFragmentV1 . SpfAlignmentMode ) ;
125+
126+ var isParserSuccessful = DmarcRecordParser . TryParseV1 ( dataFragmentV1 , out var dmarcRecord ) ;
127+
97128 Assert . IsFalse ( isParserSuccessful ) ;
98129 Assert . IsNull ( dmarcRecord ) ;
99130 }
0 commit comments