public void WhenReminderFilterByStatusReady()
        {
            var filter = ReminderItemFilter.ByStatus(ReminderItemStatus.Ready);

            Assert.NotNull(filter);
            Assert.IsTrue(filter.IsByStatus);
        }
        public void WhenCreatedItemsFindByReadyStatus_ShouldReturnEmpty()
        {
            storage.Add(
                new ReminderItem(Guid.NewGuid(), "header", "message one", DateTimeOffset.Now.AddSeconds(-1), "User"));

            var result = storage.FindBy(
                ReminderItemFilter.ByStatus(ReminderItemStatus.Ready));

            Assert.IsEmpty(result);
        }
        public void GivenReadyItems_WhenFindByReadyStatus_ShouldReturnElements()
        {
            var storage = new ReminderItemStorage(
                CreateReminderItem(datetime: DateTimeOffset.UtcNow.AddMinutes(-1), status: ReminderItemStatus.Ready));

            var result = storage.FindBy(
                ReminderItemFilter.ByStatus(ReminderItemStatus.Ready)
                );

            Assert.IsNotEmpty(result);
        }
Exemple #4
0
        private void OnSenderTimerTick(object state)           //sends matching objects
        {
            var items = _storage.FindBy(ReminderItemFilter.ByStatus(ReminderItemStatus.Ready));

            foreach (var item in items)
            {
                item.Status = ReminderItemStatus.Sent;
                _storage.Update(item);
                ReminderSent?.Invoke(this, new ReminderSentEventArgs(item));
            }
        }
        private void OnSenderTimerTick(object state)
        {
            var items = _storage.FindBy(ReminderItemFilter.ByStatus(ReminderItemStatus.Ready));

            foreach (var item in items)
            {
                item.Status = ReminderItemStatus.Sent;
                _storage.Update(item);
                _sender.send(new ReminderNotification(item.Title, item.Message, item.UserId));
            }
        }
        public async Task Find_GivenRemindersWithStatus_ShouldReturnNotEmptyCollection()
        {
            var status  = ReminderItemStatus.Created;
            var storage = new ReminderStorage(
                Create.Reminder.WithStatus(status)
                );

            var result = await storage.FindByAsync(ReminderItemFilter.ByStatus(status));

            CollectionAssert.IsNotEmpty(result);
        }
        private void OnCreatedItemTimerTick(object _)
        {
            var filter = ReminderItemFilter
                         .ByStatus(ReminderItemStatus.Created)
                         .At(DateTimeOffset.UtcNow);
            var items = _storage.FindBy(filter);

            foreach (var item in items)
            {
                _storage.Update(item.ReadyToSend());
            }
        }
Exemple #8
0
        public void GivenCreatedItem_WhenFrindByReadyStatus_ShouldReturnEmpty()
        {
            var storage  = new ReminderItemStorage();
            var Reminder = new[]
            { new ReminderItem(Guid.NewGuid(), "Title1", "Message1", DateTimeOffset.UtcNow, "User_id1"),
              new ReminderItem(Guid.NewGuid(), "Title2", "Message2", DateTimeOffset.UtcNow.AddSeconds(-20), "User_id2"),
              new ReminderItem(Guid.NewGuid(), "Title3", "Message3", DateTimeOffset.UtcNow.AddSeconds(+20), "User_id3") };

            storage.Add(Reminder);
            var result = storage.FindBy(ReminderItemFilter.ByStatus(ReminderItemStatus.Ready));

            Assert.IsEmpty(result);
        }
        public async Task WhenReminderList_IfStatusSpecified_ShouldReturnMatchingItems()
        {
            using var factory = new ReminderWebApplicationFactory();
            var storage = factory
                          .WithItems(
                Create.Reminder.WithStatus(ReminderItemStatus.Ready),
                Create.Reminder.WithStatus(ReminderItemStatus.Created))
                          .GetClient();

            var items = await storage.FindByAsync(
                ReminderItemFilter.ByStatus(ReminderItemStatus.Ready)
                );

            Assert.AreEqual(1, items.Length);
        }
        public async Task FindAsync_GivenExistingItemsWithSpecifiedStatuses_ShouldReturnNotEmptyCollection()
        {
            //Arrange
            var storage = new ReminderStorage(DatabaseTestsHelper.ConnectionString);
            await storage.AddAsync(Create.Reminder.WithStatus(ReminderItemStatus.Created));

            await storage.AddAsync(Create.Reminder.WithStatus(ReminderItemStatus.Ready));

            await storage.AddAsync(Create.Reminder.WithStatus(ReminderItemStatus.Ready));

            //Act
            var found = await storage.FindAsync(ReminderItemFilter.ByStatus(ReminderItemStatus.Ready));

            //Assert
            CollectionAssert.IsNotEmpty(found);
        }
        private void OnReadyItemTimerTick(object _)
        {
            var filter = ReminderItemFilter.ByStatus(ReminderItemStatus.Ready);
            var items  = _storage.FindBy(filter);

            foreach (var item in items)
            {
                try
                {
                    ItemNotified?.Invoke(this, new NotifyReminderModel(item));
                    OnItemSent(item);
                }
                catch (Exception ex)
                {
                    OnItemFailed(item);
                }
            }
        }
Exemple #12
0
        public void GivenItemWithCreatedStatusAndDatetime_WhenTimersExecutesAndReceiverFailed_ThenStatusChangedToFailed()
        {
            // Arrange
            var storage = new ReminderItemStorage(
                CreateReminderItem(datetime: DateTimeOffset.UtcNow.AddMinutes(-1), status: ReminderItemStatus.Created)
                );

            using var scheduler = CreateScheduler(storage, FailedSender);

            // Act
            scheduler.Run();
            WaitTimers();

            // Assert
            var items = storage.FindBy(
                ReminderItemFilter.ByStatus(ReminderItemStatus.Failed)
                );

            Assert.IsNotEmpty(items);
        }
Exemple #13
0
        private void OnReadyItemTimerTick(object _)
        {
            var filter = ReminderItemFilter.ByStatus(ReminderItemStatus.Ready);
            var items  = _storage.FindBy(filter);

            foreach (var item in items)
            {
                try
                {
                    _sender.Send(
                        new Notification(item.ContactId, item.Message, item.MessageDate)
                        );
                    OnItemSent(item);
                }
                catch (Exception ex)
                {
                    OnItemFailed(item);
                }
            }
        }
Exemple #14
0
        private void OnSenderTimerTick(object state)
        {
            var items = _storage.FindBy(ReminderItemFilter.ByStatus(ReminderItemStatus.Ready));

            foreach (var item in items)
            {
                var notification = new ReminderNotification(
                    item.Title,
                    item.Message,
                    item.User.ChatId);

                try
                {
                    _sender.Send(notification);
                    UpdateStatus(item, ReminderItemStatus.Sent);
                }
                catch (HttpRequestException exception)
                {
                    _logger.LogWarning("Failed to sent item", exception);
                    UpdateStatus(item, ReminderItemStatus.Failed);
                }
            }
        }
Exemple #15
0
        public void test2()
        {
            var reminder = new ReminderItem[] { new ReminderItem(Guid.NewGuid()
                                                                 , "Test1"
                                                                 , "Reminder1"
                                                                 , DateTimeOffset.UtcNow.AddMinutes(-1)
                                                                 , "UserName") };
            var storage = new ReminderItemStorage(reminder);

            using var cheduler = new ReminderScheduler(
                      storage,
                      new ReminderItemReceiver(),
                      new ReminderItemSender(),
                      new ReminderSchedulerSettings(TimeSpan.FromMilliseconds(300),
                                                    TimeSpan.FromMilliseconds(500))
                      );

            cheduler.Run();
            Thread.Sleep(TimeSpan.FromMilliseconds(800));
            var item = storage.FindBy(ReminderItemFilter.ByStatus(ReminderItemStatus.Filed));

            // goto нет sleep
            Assert.IsNotNull(item);
        }
Exemple #16
0
 public void GivenStatus_IsByStatus_ShouldBeTrue()
 {
     Assert.True(ReminderItemFilter.ByStatus(ReminderItemStatus.Ready).IsByStatus);
 }
Exemple #17
0
 public void Test1()
 {
     var f1 = ReminderItemFilter.ByStatus(ReminderItemStatus.Ready);
     var f2 = ReminderItemFilter.FromNow();
 }