Пример #1
0
        public void CalculateNextReminderDate_Should_Return_Null_For_Active_Not_Null_DateGoal_Less_Or_Equal_compareWithDate(
            string stringDateGoal, string stringCompareWithDate)
        {
            // prepare test data
            DateTimeOffset.TryParseExact(stringDateGoal,
                                         "dd.MM.yyyy HH:mm:ss.fff zzz",
                                         CultureInfo.InvariantCulture.DateTimeFormat,
                                         DateTimeStyles.None,
                                         out DateTimeOffset dateGoal);
            DateTimeOffset.TryParseExact(stringCompareWithDate,
                                         "dd.MM.yyyy HH:mm:ss.fff zzz",
                                         CultureInfo.InvariantCulture.DateTimeFormat,
                                         DateTimeStyles.None,
                                         out DateTimeOffset compareWithDate);

            // do the test
            DateTimeOffset?actual = ReminderItem.CalculateNextReminderDate(true,
                                                                           FrequencyTypes.None,
                                                                           null,
                                                                           dateGoal,
                                                                           compareWithDate);

            // check the results
            Assert.Null(actual);
        }
Пример #2
0
        private void SendMessage(ReminderItem item)
        {
            SendingResultTypes sendingResult      = SendingResultTypes.Failed;
            AggregateException aggregateException = null;
            Exception          exception          = null;

            try
            {
                (sendingResult, aggregateException) = Sender.Send(item.GetChatId(), item.Message);
            }
            catch (Exception e)
            {
                exception = e;
            }

            if (exception == null && aggregateException == null &&
                (sendingResult == SendingResultTypes.Success || sendingResult == SendingResultTypes.WrongText))
            {
                // WrongText пока не отрабатывается никак
                item.NextReminderDate = ReminderItem.CalculateNextReminderDate(
                    item.IsActive,
                    item.FrequencyType,
                    item.DateBegin,
                    item.DateGoal,
                    item.NextReminderDate ?? DateTimeOffset.Now);

                if (item.NextReminderDate == null)
                {
                    item.IsActive = false;
                }
                item.ThreadGuid   = null;
                item.IsProcessing = false;
            }
            else
            {
                item.ThreadGuid       = null;
                item.IsProcessing     = false;
                item.LastSendingError =
                    $"{nameof(sendingResult)}: {sendingResult}\t" +
                    $"{nameof(aggregateException)}: {aggregateException?.Message??"None"}\t" +
                    $"{nameof(exception)}: {exception?.Message??"None"}";
            }

            ((ICruStorage <ReminderItem>)Storage).Update(item);

            //ReminderItem r = item;
            //Console.WriteLine($"Send remainder {r.Id}\t{r.NextReminderDate:HH:mm:ss}\t{r.ThreadGuid}\t{r.Message}"+
            //    $"\tNow {DateTimeOffset.Now:HH:mm:ss}");
        }