示例#1
0
        public void OnAgentStatusChanged(object sender, IntelEventArgs args)
        {
            switch (args.EventType)
            {
            case IntelEventType.AgentEnter:
                var offline = (from a in this.Agents where a.IsOnline == false select a).ToArray();

                foreach (var a in offline)
                {
                    this.Agents.Remove(a);
                }

                AgentViewModel agentViewModel = new AgentViewModel(args.AgentProfile);
                agentViewModel.IsOnline = true;
                this.Agents.Add(agentViewModel);
                break;

            case IntelEventType.AgentLeave:
                var agent = (from a in this.Agents where a.Agent == args.AgentProfile.Agent select a).First();
                if (agent != null)
                {
                    agent.IsOnline = false;
                }

                break;
            }
        }
示例#2
0
 public void ConstructorTest_With_ValidAgent_and_NullImage()
 {
     string         agent   = "agent";
     Bitmap         image   = null;
     string         caption = "caption";
     IntelEventArgs target  = new IntelEventArgs(new IntelData(agent, image, caption));
 }
示例#3
0
        public void OnImageryReceived(object sender, IntelEventArgs args)
        {
            ImageryViewModel imageViewModel = new ImageryViewModel(args.AgentProfile.Agent, args.Image, args.Caption);

            this.MostRecentImagery = imageViewModel;
            this.Imagery.Add(imageViewModel);
        }
示例#4
0
 public void ConstructorTest_With_NullAgent_and_Image()
 {
     string         agent   = null;
     Bitmap         image   = new Bitmap(100, 100);
     string         caption = "caption";
     IntelEventArgs target  = new IntelEventArgs(new IntelData(agent, image, caption));
 }
示例#5
0
        public void ConstructorTest_With_ValidAgent_and_EventType()
        {
            string         agent     = "agent";
            IntelEventType eventType = IntelEventType.AgentEnter;
            IntelEventArgs target    = new IntelEventArgs(new AgentProfile(agent));

            Assert.AreEqual <string>(agent, target.AgentProfile.Agent);
            Assert.AreEqual <IntelEventType>(eventType, target.EventType);
        }
示例#6
0
        public void Enter_AgentStatusChangeEvent_Returns_Correct_IntelEventArg()
        {
            string         agent = "agent";
            IntelEventArgs args  = null;

            _target.AgentStatusChanged += new System.EventHandler <IntelEventArgs>((o, e) => { args = e; });
            _target.Enter(new AgentProfile(agent));

            Assert.AreEqual <string>(agent, args.AgentProfile.Agent);
            Assert.AreEqual <IntelEventType>(IntelEventType.AgentEnter, args.EventType);
        }
示例#7
0
        public void ConstructorTest_With_ValidAgent_and_Image()
        {
            string         agent   = "agent";
            Bitmap         image   = new Bitmap(100, 100);
            string         caption = "caption";
            IntelEventArgs target  = new IntelEventArgs(new IntelData(agent, image, caption));

            Assert.AreEqual <string>(agent, target.AgentProfile.Agent);
            Assert.AreEqual <Bitmap>(image, target.Image);
            Assert.AreEqual <string>(caption, target.Caption);
            Assert.AreEqual <IntelEventType>(IntelEventType.IntelReceived, target.EventType);
        }
示例#8
0
        public void SendItel_IntelReceivedEvent_Returns_Correct_IntelEventArg()
        {
            string agent   = "agent";
            string caption = "caption";
            Bitmap image   = new Bitmap(100, 100);

            IntelEventArgs args = null;

            _target.IntelReceived += new System.EventHandler <IntelEventArgs>((o, e) => { args = e; });
            IntelData data = new IntelData(agent, image, caption);

            _target.SendIntel(data);

            Assert.AreEqual <string>(agent, args.AgentProfile.Agent);
            Assert.AreEqual <Bitmap>(image, args.Image);
            Assert.AreEqual <string>(caption, args.Caption);
            Assert.AreEqual <IntelEventType>(IntelEventType.IntelReceived, args.EventType);
        }
        public void IntelReported()
        {
            TestHelpers.CreateRequestMock(channelUri, channelBody);

            var chan1Mock = new Mock<IntelChannel>(MockBehavior.Loose);
            chan1Mock.Object.Name = channelList[0];
            chan1Mock.SetupGet(x => x.Status).Returns(IntelStatus.Waiting);
            var chan2Mock = new Mock<IntelChannel>(MockBehavior.Loose);
            chan2Mock.Object.Name = channelList[0];
            chan2Mock.SetupGet(x => x.Status).Returns(IntelStatus.Active);

            var containerMock = new Mock<IntelChannelContainer>(MockBehavior.Loose) {
                CallBase = true
            };
            containerMock.Protected()
                .Setup<IntelChannel>("CreateChannel", channelList[0])
                .Returns(delegate() {
                    var obj = chan1Mock.Object;
                    var method = typeof(IntelChannelContainer)
                        .GetMethod("OnIntelReported", BindingFlags.NonPublic | BindingFlags.Instance);
                    obj.IntelReported += (sender, e) => method
                        .Invoke(containerMock.Object, new object[] { e });
                    return obj;
                });
            containerMock.Protected()
                .Setup<IntelChannel>("CreateChannel", channelList[1])
                .Returns(delegate() {
                    var obj = chan2Mock.Object;
                    var method = typeof(IntelChannelContainer)
                        .GetMethod("OnIntelReported", BindingFlags.NonPublic | BindingFlags.Instance);
                    obj.IntelReported += (sender, e) => method
                        .Invoke(containerMock.Object, new object[] { e });
                    return obj;
                });

            var raised = new List<IntelEventArgs>();
            var e1 = new IntelEventArgs(
                channelList[0],
                DateTime.UtcNow,
                "test message");
            var e2 = new IntelEventArgs(
                channelList[1],
                DateTime.UtcNow,
                "test message");
            var e3 = new IntelEventArgs(
                channelList[0],
                DateTime.UtcNow,
                "test message");

            using (var container = containerMock.Object) {
                container.ChannelListUri = channelUri;
                container.IntelReported += delegate(object sender, IntelEventArgs e) {
                    Assert.AreEqual(container, sender);
                    Assert.IsNotNull(e);
                    lock (raised) {
                        raised.Add(e);
                    }
                };
                container.Start();
                Thread.Sleep(100);

                chan1Mock.Object.OnIntelReported(e1);
                chan2Mock.Object.OnIntelReported(e2);
                chan1Mock.Object.OnIntelReported(e3);
                Thread.Sleep(100);

                Assert.AreEqual(IntelStatus.Active, container.Status);
            }

            CollectionAssert.AreEquivalent(
                new IntelEventArgs[] { e1, e2, e3 },
                raised);
        }
示例#10
0
 public void ConstructorTest_With_NullAgent_and_EventType()
 {
     string         agent  = null;
     IntelEventArgs target = new IntelEventArgs(new AgentProfile(agent));
 }
        public void IntelReported()
        {
            var sent = new IntelEventArgs("channel", DateTime.UtcNow, "message");
            IntelEventArgs received = null;

            using (var channel = new IntelChannel()) {
                channel.IntelReported += (sender, e) => {
                    Assert.IsNull(received, "IntelReported was raised multiple times.");
                    Assert.AreEqual(channel, sender);
                    received = e;
                };
                channel.OnIntelReported(sent);
                Thread.Sleep(10);
                Assert.AreEqual(1, channel.IntelCount);
            }

            Assert.AreEqual(sent, received);
        }
        public void WebErrorClear()
        {
            var reporterMock = new Mock<IntelReporter>(MockBehavior.Loose) {
                CallBase = true
            };

            TestHelpers.CreateRequestMock(serviceUri, "200 AUTH 0123456789ABCDEF 5");
            TestHelpers.CreateRequestMock(channelListUri, channelBody);

            var testEvent = new IntelEventArgs(channelList[0], DateTime.UtcNow, "Test Message");
            var sessionMock = new Mock<IntelSession>(MockBehavior.Loose, "username", "password", serviceUri);
            sessionMock.Setup(x => x.Report(testEvent.Channel, testEvent.Timestamp, testEvent.Message))
                .Returns(true);

            IntelSession session = null;
            reporterMock.Protected()
                .Setup<IntelSession>("GetSession", ItExpr.IsAny<bool>())
                .Returns(new Func<IntelSession>(delegate() {
                    if (session == null) throw new WebException();
                    return session;
                }));

            using (var testDir = new TempDirectory()) {
                using (var reporter = reporterMock.Object) {
                    reporter.Path = testDir.FullName;
                    reporter.Username = "******";
                    reporter.PasswordHash = "password";

                    reporter.ServiceUri = serviceUri;
                    reporter.ChannelListUri = channelListUri;

                    reporter.Start();
                    Thread.Sleep(100);
                    Assert.AreEqual(IntelStatus.NetworkError, reporter.Status);

                    reporter.OnIntelReported(testEvent);
                    Thread.Sleep(100);
                    Assert.AreEqual(IntelStatus.NetworkError, reporter.Status);
                    Assert.AreEqual(1, reporter.IntelDropped);
                    Assert.AreEqual(0, reporter.IntelSent);

                    session = sessionMock.Object;
                    reporter.OnIntelReported(testEvent);
                    Thread.Sleep(100);
                    Assert.AreEqual(IntelStatus.Active, reporter.Status);
                    Assert.AreEqual(1, reporter.IntelDropped);
                    Assert.AreEqual(1, reporter.IntelSent);
                }
            }
        }
        public void NetworkErrorToAuthError()
        {
            var reporterMock = new Mock<IntelReporter>(MockBehavior.Loose) {
                CallBase = true
            };

            TestHelpers.CreateRequestMock(channelListUri, String.Join("\r\n", channelList));
            var testEvent = new IntelEventArgs(channelList[0], DateTime.UtcNow, "Test Message");
            var sessionMock = new Mock<IntelSession>(MockBehavior.Loose, "username", "password", serviceUri);
            sessionMock.Setup(x => x.Report(testEvent.Channel, testEvent.Timestamp, testEvent.Message))
                .Returns(true);

            Exception exception = new WebException();
            reporterMock.Protected()
                .Setup<IntelSession>("GetSession", ItExpr.IsAny<bool>())
                .Returns(() => { throw exception; });

            using (var testDir = new TempDirectory()) {
                using (var reporter = reporterMock.Object) {
                    reporter.Path = testDir.FullName;
                    reporter.Username = "******";
                    reporter.PasswordHash = "password";
                    reporter.AuthenticationRetryTimeout = new TimeSpan(0, 0, 0, 0, 10);

                    reporter.ServiceUri = serviceUri;
                    reporter.ChannelListUri = channelListUri;

                    reporter.Start();
                    Thread.Sleep(100);
                    Assert.AreEqual(IntelStatus.NetworkError, reporter.Status);

                    reporter.OnIntelReported(testEvent);
                    Thread.Sleep(100);
                    Assert.AreEqual(IntelStatus.NetworkError, reporter.Status);
                    Assert.AreEqual(1, reporter.IntelDropped);
                    Assert.AreEqual(0, reporter.IntelSent);

                    exception = new AuthenticationException();
                    reporter.OnIntelReported(testEvent);
                    Thread.Sleep(100);
                    Assert.AreEqual(IntelStatus.AuthenticationError, reporter.Status);
                    Assert.AreEqual(2, reporter.IntelDropped);
                    Assert.AreEqual(0, reporter.IntelSent);
                }
            }
        }
        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);
                }
            }
        }