public void PrepareNotificationBucket_should_sort_all_events_and_add_needed_event_in_a_new_bucket() { // Arrange var eventTest = new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(3).AddSeconds(50)) { Name = "event1", NotifyBefore = new TimeSpan(0, 0, 0) }; var events = new List <IEvent>() { eventTest, new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(15).AddSeconds(50)) { Name = "event2", NotifyBefore = new TimeSpan(0, 0, 0) }, new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(3).AddSeconds(50)) { Name = "event3", NotifyBefore = new TimeSpan(0, 0, 0) }, }; //Act NotificationBucket result = Scheduler.PrepareNotificationBucket(events); //Assert result.Should().NotBeNull(); result.NextEvents.Should().HaveCount(2); result.NextEvents.Should().Contain(eventTest); }
public void NotifyForAll(NotificationBucket notificationBucket) { foreach (var item in notificationBucket.NextEvents) { item.Notify(); PostProcessNotification(item); } }
public void NotifyForAll_should_do_notification_for_each_event_in_bucket() { //Arrange var events = new List <IEvent>() { Substitute.For <IEvent>(), Substitute.For <IEvent>(), Substitute.For <IEvent>(), }; var notificationBucket = new NotificationBucket(events); //Act BucketNotifierInstance.NotifyForAll(notificationBucket); //Assert events.ForEach(e => e.Received(1).Notify()); }
public void Remove_should_remove_old_event() { //Arrang var eventTest = new OneTimeEvent(_notifier, new DateTime(2000, 12, 10)); var events = new List <IEvent>() { eventTest, new OneTimeEvent(_notifier, new DateTime(2000, 12, 10)), new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(15).AddSeconds(50)), }; NotificationBucketInstance = new NotificationBucket(events); //Act NotificationBucketInstance.Remove(eventTest); //Assert NotificationBucketInstance.Should().NotBeNull(); NotificationBucketInstance.NextEvents.Should().HaveCount(2); NotificationBucketInstance.NextEvents.Should().NotContain(eventTest); }
public void Add_should_add_new_event() { //Arrang створюються змінні для того щоб виконати тестування var events = new List <IEvent>() { new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(10).AddSeconds(60)), new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(15).AddSeconds(50)), new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(4).AddSeconds(40)), new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(3).AddSeconds(40)), }; NotificationBucketInstance = new NotificationBucket(events); var newEvent = new OneTimeEvent(_notifier, DateTime.Now.AddMinutes(10).AddSeconds(60)); //Act виконуються визначенні дії над системою NotificationBucketInstance.Add(newEvent); //Assert очікуваний результат NotificationBucketInstance.Should().NotBeNull(); NotificationBucketInstance.NextEvents.Should().HaveCount(5); NotificationBucketInstance.NextEvents.Should().Contain(events); }