Example #1
0
        public void CanQueueNotifications()
        {
            _messages.Clear();

            Project project = ProjectData.GenerateProject(generateId: true, name: "Project1", nextSummaryEndOfDayTicks: DateTime.UtcNow.AddHours(OFFSET).AddMinutes(-1).Ticks);

            Repository.Add(project);

            Project project2 = ProjectData.GenerateProject(generateId: true, name: "Project2", nextSummaryEndOfDayTicks: DateTime.UtcNow.AddHours(OFFSET).AddMilliseconds(250).Ticks);

            Repository.Add(project2);

            var job = new DailyNotificationJob(Repository as ProjectRepository, _messageFactoryMock.Object);

            job.Run(new JobContext("Daily Summary", "", DateTime.Now, JobStatus.None, null, null, null));

            Assert.Equal(1, _messages.Count);
            Assert.Equal(project.NextSummaryEndOfDayTicks + TimeSpan.TicksPerDay, Repository.GetById(project.Id).NextSummaryEndOfDayTicks);
            Assert.Equal(project2.NextSummaryEndOfDayTicks, Repository.GetById(project2.Id).NextSummaryEndOfDayTicks);

            job.Run(new JobContext("Daily Summary", "", DateTime.Now, JobStatus.None, null, null, null));

            Assert.Equal(1, _messages.Count);
            Assert.Equal(project.NextSummaryEndOfDayTicks + TimeSpan.TicksPerDay, Repository.GetById(project.Id).NextSummaryEndOfDayTicks);
            Assert.Equal(project2.NextSummaryEndOfDayTicks, Repository.GetById(project2.Id).NextSummaryEndOfDayTicks);

            Thread.Sleep(250);
            job.Run(new JobContext("Daily Summary", "", DateTime.Now, JobStatus.None, null, null, null));

            Assert.Equal(2, _messages.Count);
            Assert.Equal(project.NextSummaryEndOfDayTicks + TimeSpan.TicksPerDay, Repository.GetById(project.Id).NextSummaryEndOfDayTicks);
            Assert.Equal(project2.NextSummaryEndOfDayTicks + TimeSpan.TicksPerDay, Repository.GetById(project2.Id).NextSummaryEndOfDayTicks);
        }
Example #2
0
        public void CanQueueNotificationsInMultiThreadedEnvironment()
        {
            _messages.Clear();
            const int numberOfProjects = 30;

            List <Project> projects = ProjectData.GenerateProjects(numberOfProjects, true, organizationId: TestConstants.OrganizationId3, nextSummaryEndOfDayTicks: DateTime.UtcNow.AddHours(OFFSET).AddMinutes(-1).Ticks).ToList();

            Repository.Add(projects);

            List <Project> projects2 = ProjectData.GenerateProjects(numberOfProjects, true, organizationId: TestConstants.OrganizationId4, nextSummaryEndOfDayTicks: DateTime.UtcNow.AddHours(OFFSET - 1).AddMinutes(-1).Ticks).ToList();

            Repository.Add(projects2);

            // TODO: We need to have some kind of lock to where we can unit test this.
            Parallel.For(0, 5, (i) => {
                var job = new DailyNotificationJob(Repository as ProjectRepository, _messageFactoryMock.Object);
                job.Run(new JobContext("Daily Summary", "", DateTime.Now, JobStatus.None, null, null, null));
            });

            Assert.Equal(numberOfProjects, _messages.Count);
            List <Project> updatedProjects = Repository.GetByOrganizationId(TestConstants.OrganizationId3).ToList();

            foreach (Project project in updatedProjects)
            {
                Project originalProject = projects.First(p => String.Equals(p.Id, project.Id));
                Assert.Equal(originalProject.NextSummaryEndOfDayTicks + TimeSpan.TicksPerDay, project.NextSummaryEndOfDayTicks);
            }

            List <Project> updatedProjects2 = Repository.GetByOrganizationId(TestConstants.OrganizationId4).ToList();

            foreach (Project project in updatedProjects2)
            {
                Project originalProject = projects.First(p => String.Equals(p.Id, project.Id));
                Assert.Equal(originalProject.NextSummaryEndOfDayTicks, project.NextSummaryEndOfDayTicks);
            }
        }