Exemplo n.º 1
0
        public void SendNotification_1EventAfter0SecondThen1After3Minutes_Expect1NotificationSentAfter5Minutes()
        {
            //Arrange
            var eventEmitter = new MvvmLightMessenger();

            var robot = Substitute.For <IRobot>();

            robot.Messenger.Returns(eventEmitter);

            var scheduler      = new TestScheduler();
            var jiraAggregator = new JiraAggregatorSut(robot, scheduler);

            var user = new User {
                displayName = "Laurent Kempé", name = "laurent"
            };

            var addCommentEvent1 = new JiraModel
            {
                issue = new Issue {
                    key = "LK-10", fields = new Fields {
                        reporter = user, assignee = user
                    }
                },
                webhookEvent = "jira:issue_created",
                comment      = new CommentDetails(),
                user         = user
            };

            var addCommentEvent2 = new JiraModel
            {
                issue = new Issue {
                    key = "LK-10", fields = new Fields {
                        reporter = user, assignee = user
                    }
                },
                webhookEvent = "jira:issue_updated",
                comment      = new CommentDetails(),
                user         = user
            };

            //Act
            scheduler.Schedule(TimeSpan.FromSeconds(0), () => eventEmitter.Publish("JiraEvent", addCommentEvent1));
            scheduler.Schedule(TimeSpan.FromSeconds(120), () => eventEmitter.Publish("JiraEvent", addCommentEvent2));

            scheduler.AdvanceTo(TimeSpan.FromSeconds(181).Ticks);
            robot.Received(0).SendNotification("", "", "Message", true);

            scheduler.AdvanceTo(TimeSpan.FromMinutes(5).Ticks);

            //Assert
            robot.Received(1).SendNotification(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), true);
        }
Exemplo n.º 2
0
        public void SendNotification_1EventAfter0SecondThen1After3Minutes_Expect1NotificationSentAfter5Minutes()
        {
            //Arrange
            var eventEmitter = new MvvmLightMessenger();

            var robot = Substitute.For<IRobot>();
            robot.EventEmitter.Returns(eventEmitter);

            var scheduler = new TestScheduler();
            var jiraAggregator = new JiraAggregatorSut(robot, scheduler);

            var user = new User { displayName = "Laurent Kempé", name = "laurent" };

            var addCommentEvent1 = new JiraModel
            {
                issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } },
                webhookEvent = "jira:issue_created",
                comment = new CommentDetails(),
                user = user
            };

            var addCommentEvent2 = new JiraModel
            {
                issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } },
                webhookEvent = "jira:issue_updated",
                comment = new CommentDetails(),
                user = user
            };

            //Act
            scheduler.Schedule(TimeSpan.FromSeconds(0), () => eventEmitter.Emit("JiraEvent", addCommentEvent1));
            scheduler.Schedule(TimeSpan.FromSeconds(120), () => eventEmitter.Emit("JiraEvent", addCommentEvent2));

            scheduler.AdvanceTo(TimeSpan.FromSeconds(181).Ticks);
            robot.Received(0).SendNotification("", "", "Message", true);

            scheduler.AdvanceTo(TimeSpan.FromMinutes(5).Ticks);

            //Assert
            robot.Received(1).SendNotification(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), true);
        }