public void StartWebError()
        {
            using (var testDir = new TempDirectory()) {
                using (var reporter = new IntelReporter()) {
                    reporter.Path = testDir.FullName;
                    reporter.Username = "******";
                    reporter.PasswordHash = "password";

                    reporter.ChannelListUri = channelListUri;
                    TestHelpers.CreateRequestError<WebException>(channelListUri);

                    reporter.ServiceUri = serviceUri;
                    var requestBody = TestHelpers.CreateRequestError<WebException>(serviceUri);

                    reporter.Start();
                    Thread.Sleep(100);

                    Assert.IsTrue(reporter.IsRunning);
                    Assert.IsTrue(requestBody.Length > 0);
                    Assert.AreEqual(IntelStatus.NetworkError, reporter.Status);
                }
            }
        }
        public void StartStop()
        {
            using (var testDir = new TempDirectory()) {
                using (var reporter = new IntelReporter()) {
                    reporter.Path = testDir.FullName;
                    reporter.Username = "******";
                    reporter.PasswordHash = "password";

                    reporter.ChannelListUri = channelListUri;
                    TestHelpers.CreateRequestMock(channelListUri, channelBody);

                    reporter.ServiceUri = serviceUri;
                    var requestBody = TestHelpers.CreateRequestMock(serviceUri, "200 AUTH 0123456789ABCDEF 5");

                    reporter.Start();
                    Thread.Sleep(100);

                    Assert.IsTrue(reporter.IsRunning);
                    Assert.IsTrue(requestBody.Length > 0);
                    Assert.AreEqual(IntelStatus.Active, reporter.Status);
                    Assert.AreEqual(2, reporter.Channels.Count);
                    Assert.IsNotNull(reporter.Channels.Single(x => x.Name == channelList[0]));
                    Assert.IsNotNull(reporter.Channels.Single(x => x.Name == channelList[1]));
                    Assert.IsTrue(reporter.Channels.All(x => x.IsRunning));

                    TestHelpers.Cleanup();
                    requestBody = TestHelpers.CreateRequestMock(serviceUri, "201 AUTH Logged Off");
                    reporter.Stop();
                    Thread.Sleep(100);

                    Assert.IsFalse(reporter.IsRunning);
                    Assert.IsTrue(requestBody.Length > 0);
                    Assert.AreEqual(IntelStatus.Stopped, reporter.Status);
                    Assert.IsTrue(reporter.Channels.All(x => !x.IsRunning));
                }
            }
        }
        public void StartAuthError()
        {
            using (var testDir = new TempDirectory()) {
                using (var reporter = new IntelReporter()) {
                    reporter.Path = testDir.FullName;
                    reporter.Username = "******";
                    reporter.PasswordHash = "password";

                    reporter.ChannelListUri = channelListUri;
                    TestHelpers.CreateRequestMock(channelListUri, String.Join("\r\n", channelList));

                    reporter.ServiceUri = serviceUri;
                    var requestBody = TestHelpers.CreateRequestMock(serviceUri, "500 ERROR AUTH");

                    reporter.Start();
                    Thread.Sleep(100);

                    Assert.IsTrue(reporter.IsRunning);
                    Assert.IsTrue(requestBody.Length > 0);
                    Assert.AreEqual(IntelStatus.AuthenticationError, reporter.Status);
                }
            }
        }
        public void StartNoAuth()
        {
            using (var testDir = new TempDirectory()) {
                using (var reporter = new IntelReporter()) {
                    reporter.Path = testDir.FullName;

                    reporter.ChannelListUri = channelListUri;
                    TestHelpers.CreateRequestMock(channelListUri, String.Join("\r\n", channelList));

                    reporter.Start();
                    Thread.Sleep(100);

                    Assert.IsTrue(reporter.IsRunning);
                    Assert.AreEqual(IntelStatus.AuthenticationError, reporter.Status);
                }
            }
        }
        public void IntelReported()
        {
            using (var testDir = new TempDirectory()) {
                using (var reporter = new IntelReporter()) {
                    reporter.Path = testDir.FullName;
                    IntelEventArgs received = null;
                    reporter.IntelReported += (sender, e) => received = e;

                    reporter.ChannelListUri = channelListUri;
                    TestHelpers.CreateRequestMock(channelListUri, channelBody);

                    reporter.Start();
                    var testEvent = new IntelEventArgs(channelList[0], DateTime.UtcNow, "Test Message");
                    Thread.Sleep(100);
                    Assert.AreEqual(0, reporter.IntelDropped);
                    Assert.AreEqual(0, reporter.IntelSent);

                    reporter.Channels.First().OnIntelReported(testEvent);
                    Thread.Sleep(100);
                    Assert.IsTrue(reporter.IsRunning);
                    Assert.AreEqual(IntelStatus.AuthenticationError, reporter.Status);
                    Assert.AreEqual(received, testEvent);
                    Assert.AreEqual(1, reporter.IntelDropped);
                    Assert.AreEqual(0, reporter.IntelSent);
                }
            }
        }