1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Diagnostics . CodeAnalysis ;
4
+ using System . Linq ;
5
+ using System . Text ;
6
+ using System . Threading . Tasks ;
7
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
8
+ using PcapDotNet . Packets . Dhcp ;
9
+ using PcapDotNet . Packets . Ethernet ;
10
+ using PcapDotNet . Packets . IpV4 ;
11
+ using PcapDotNet . Packets . TestUtils ;
12
+ using PcapDotNet . Packets . Transport ;
13
+
14
+ namespace PcapDotNet . Packets . Test
15
+ {
16
+ /// <summary>
17
+ /// Summary description for ArpTests
18
+ /// </summary>
19
+ [ TestClass ]
20
+ [ ExcludeFromCodeCoverage ]
21
+ public class DhcpTests
22
+ {
23
+ /// <summary>
24
+ /// Gets or sets the test context which provides
25
+ /// information about and functionality for the current test run.
26
+ /// </summary>
27
+ public TestContext TestContext { get ; set ; }
28
+
29
+ #region Additional test attributes
30
+
31
+ //
32
+ // You can use the following additional attributes as you write your tests:
33
+ //
34
+ // Use ClassInitialize to run code before running the first test in the class
35
+ // [ClassInitialize()]
36
+ // public static void MyClassInitialize(TestContext testContext) { }
37
+ //
38
+ // Use ClassCleanup to run code after all tests in a class have run
39
+ // [ClassCleanup()]
40
+ // public static void MyClassCleanup() { }
41
+ //
42
+ // Use TestInitialize to run code before running each test
43
+ // [TestInitialize()]
44
+ // public void MyTestInitialize() { }
45
+ //
46
+ // Use TestCleanup to run code after each test has run
47
+ // [TestCleanup()]
48
+ // public void MyTestCleanup() { }
49
+ //
50
+
51
+ #endregion Additional test attributes
52
+
53
+ [ TestMethod ]
54
+ public void RandomDhcpTest ( )
55
+ {
56
+ int seed = new Random ( ) . Next ( ) ;
57
+ Console . WriteLine ( "Seed: " + seed ) ;
58
+ Random random = new Random ( seed ) ;
59
+
60
+ for ( int i = 0 ; i != 1000 ; ++ i )
61
+ {
62
+ EthernetLayer ethernetLayer = random . NextEthernetLayer ( EthernetType . None ) ;
63
+
64
+ IpV4Layer ipV4Layer = random . NextIpV4Layer ( null ) ;
65
+ ipV4Layer . HeaderChecksum = null ;
66
+
67
+ UdpLayer udpLayer = random . NextUdpLayer ( ) ;
68
+ udpLayer . Checksum = null ;
69
+
70
+ DhcpLayer dhcpLayer = random . NextDhcpLayer ( ) ;
71
+
72
+ Packet packet = PacketBuilder . Build ( DateTime . Now , ethernetLayer , ipV4Layer , udpLayer , dhcpLayer ) ;
73
+
74
+ Assert . IsTrue ( packet . IsValid , "IsValid" ) ;
75
+ DhcpLayer actualLayer = ( DhcpLayer ) packet . Ethernet . Ip . Udp . Dhcp . ExtractLayer ( ) ;
76
+ if ( ! Object . Equals ( dhcpLayer , actualLayer ) )
77
+ {
78
+ Console . WriteLine ( actualLayer ) ;
79
+ }
80
+ Assert . AreEqual ( dhcpLayer , actualLayer , "DHCP Layer" ) ;
81
+ }
82
+ }
83
+ }
84
+ }
0 commit comments