public void Test_UdpDataProvider_BigPacket(string ip, int port, bool multicast)
        {
            stop = false;
            events.Clear();
            var p = new Udp.Providers.UdpDataProvider();

            p.RemoteAddress = UdpProviderConfigurator.GetIPAddress(ip);
            p.RemotePort    = port;

            var cts      = new CancellationTokenSource();
            var re       = new ManualResetEvent(false);
            var listener = Task.Factory.StartNew(() => { Listen(re, ip, port, multicast); }, cts.Token);

            re.WaitOne();
            Task.Delay(1000).Wait();

            var target = Enumerable.Range(1, 10000).Select(_ => (byte)255).ToArray();

            using (var scope = new AuditScopeFactory().Create("Test_UdpDataProvider_BigPacket", () => target, EventCreationPolicy.InsertOnEnd, p))
            {
            }

            Task.Delay(1000).Wait();
            Assert.AreEqual(1, events.Count);
        }
        public void Test_UdpDataProvider_PacketOverflow(string ip, int port, bool multicast)
        {
            var p = new Udp.Providers.UdpDataProvider();

            p.RemoteAddress = UdpProviderConfigurator.GetIPAddress(ip);
            p.RemotePort    = port;
            var target = Enumerable.Range(1, 66000).Select(_ => (byte)255).ToArray();

            Assert.Throws <SocketException>(() =>
            {
                using (var scope = new AuditScopeFactory().Create("Test_UdpDataProvider_BigPacket", () => target, EventCreationPolicy.InsertOnEnd, p))
                {
                }
            });
        }
        public void Test_UdpDataProvider_MultiThread(string ip, int port, bool multicast, int N)
        {
            stop = false;
            events.Clear();
            var p = new Udp.Providers.UdpDataProvider();

            p.RemoteAddress = UdpProviderConfigurator.GetIPAddress(ip);
            p.RemotePort    = port;
            var cts      = new CancellationTokenSource();
            var re       = new ManualResetEvent(false);
            var listener = Task.Factory.StartNew(() => { Listen(re, ip, port, multicast); }, cts.Token);

            re.WaitOne();
            Task.Delay(1500).Wait();

            var tasks = new List <Task>();

            for (int i = 0; i < N; i++)
            {
                int a = i;
                tasks.Add(new Task(() =>
                {
                    using (var scope = new AuditScopeFactory().Create("Test_UdpDataProvider_MultiThread_" + a, null, EventCreationPolicy.InsertOnEnd, p))
                    {
                    }
                }));
            }
            for (int i = 0; i < N; i++)
            {
                tasks[i].Start();
            }

            Task.WaitAll(tasks.ToArray());
            Task.Delay(1000).Wait();
            stop = true;
            cts.Cancel();
            Task.Delay(1000).Wait();

            Assert.AreEqual(N, events.Count);
            Assert.IsTrue(events[0].EventType.StartsWith("Test_UdpDataProvider_MultiThread_"));
            Assert.NotNull(events[0].CustomFields["UdpEventId"]);
        }