Exemple #1
0
        public void TestMethodMarkPendingMessagesAsCanceledByStartup_BehaveAsExpected_WhenDatabaseContainOneRecordInProgressState()
        {
            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(0), "Expect that table MessageContext is empty");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(0), "Expect that table MessageRequest is empty");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(0), "Expect that table MessageStatus is empty");

            string   messageText = "This is a scheduledMessage in progress";
            Guid     requestId   = Guid.NewGuid();
            string   trainId     = "TRAIN-1";
            DateTime startDate   = DateTime.UtcNow;
            DateTime endDate     = startDate + new TimeSpan(1, 0, 0, 0);

            ResultCodeEnum result = HistoryLogger.WriteLog(messageText, requestId, CommandType.SendScheduledMessage, trainId, MessageStatusType.InstantMessageDistributionProcessing, startDate, endDate);

            Expect(result, Is.EqualTo(ResultCodeEnum.RequestAccepted), "Failed to insert schedule message into the history log");

            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(1), "Table MessageContext wasn't updated as expected by method HistoryLogger.WriteLog");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(1), "Table MessageRequest wasn't updated as expected by method HistoryLogger.WriteLog");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(1), "Table MessageStatus wasn't updated as expected by method HistoryLogger.WriteLog");

            TestDelegate method = () => HistoryLogger.MarkPendingMessagesAsCanceledByStartup();

            Assert.That <TestDelegate>(ref method, Throws.Nothing, "Method MarkPendingMessagesAsCanceledByStartup failed while expecting not");

            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(1), "Table MessageContext has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(1), "Table MessageRequest has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(2), "Table MessageStatus wasn't updated as expected by method MarkPendingMessagesAsCanceledByStartup");
        }
Exemple #2
0
        public void TestMethodMarkPendingMessagesAsCanceledByStartup_BehaveAsExpected_WhenDatabaseIsEmpty()
        {
            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(0), "Expect that table MessageContext is empty");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(0), "Expect that table MessageRequest is empty");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(0), "Expect that table MessageStatus is empty");

            TestDelegate method = () => HistoryLogger.MarkPendingMessagesAsCanceledByStartup();

            Assert.That <TestDelegate>(ref method, Throws.Nothing, "Method MarkPendingMessagesAsCanceledByStartup failed while expecting not");

            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(0), "Table MessageContext has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(0), "Table MessageRequest has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(0), "Table MessageStatus has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
        }
Exemple #3
0
        public void TestMethodMarkPendingMessagesAsCanceledByStartup_BehaveAsExpected_ForAllStatus()
        {
            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(0), "Expect that table MessageContext is empty");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(0), "Expect that table MessageRequest is empty");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(0), "Expect that table MessageStatus is empty");

            int      recordCount     = 0;
            int      finalStateCount = CountFinalStateStatus();
            string   trainId         = "TRAIN-1";
            DateTime startDate       = DateTime.UtcNow;
            DateTime endDate         = startDate + new TimeSpan(1, 0, 0, 0);



            foreach (MessageStatusType status in Enum.GetValues(typeof(MessageStatusType)))
            {
                recordCount++;
                Guid           requestId = Guid.NewGuid();
                string         message   = "This is the scheduled message " + recordCount.ToString();
                ResultCodeEnum result    = HistoryLogger.WriteLog(message, requestId, CommandType.SendScheduledMessage, trainId, status, startDate, endDate);
                Expect(result, Is.EqualTo(ResultCodeEnum.RequestAccepted), "Failed to insert schedule message into the history log for status '" + status.ToString() + "'");
            }


            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(recordCount), "Table MessageContext wasn't updated as expected by method HistoryLogger.WriteLog");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(recordCount), "Table MessageRequest wasn't updated as expected by method HistoryLogger.WriteLog");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(recordCount), "Table MessageStatus wasn't updated as expected by method HistoryLogger.WriteLog");


            TestDelegate method = () => HistoryLogger.MarkPendingMessagesAsCanceledByStartup();

            Assert.That <TestDelegate>(ref method, Throws.Nothing, "Method MarkPendingMessagesAsCanceledByStartup failed while expecting not");

            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(recordCount), "Table MessageContext has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(recordCount), "Table MessageRequest has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(recordCount + (recordCount - finalStateCount)), "Table MessageStatus wasn't updated as expected by method MarkPendingMessagesAsCanceledByStartup");
        }
Exemple #4
0
        public void TestMethodMarkPendingMessagesAsCanceledByStartup_BehaveAsExpected_WhenDatabaseContainFourRecordsInProgressStateAndFourRecorsInFinalState()
        {
            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(0), "Expect that table MessageContext is empty");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(0), "Expect that table MessageRequest is empty");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(0), "Expect that table MessageStatus is empty");

            string   trainId   = "TRAIN-1";
            DateTime startDate = DateTime.UtcNow;
            DateTime endDate   = startDate + new TimeSpan(1, 0, 0, 0);

            KeyValuePair <Guid, string>[] records =
            {
                new KeyValuePair <Guid, String>(Guid.NewGuid(), "This is a message"),
                new KeyValuePair <Guid, String>(Guid.NewGuid(), "This is a message 2"),
                new KeyValuePair <Guid, String>(Guid.NewGuid(), "This is a message 3"),
                new KeyValuePair <Guid, String>(Guid.NewGuid(), "This is a message 4"),
                new KeyValuePair <Guid, String>(Guid.NewGuid(), "This is a message 5"),
                new KeyValuePair <Guid, String>(Guid.NewGuid(), "This is a message 6"),
                new KeyValuePair <Guid, String>(Guid.NewGuid(), "This is a message 7"),
                new KeyValuePair <Guid, String>(Guid.NewGuid(), "This is a message 8"),
            };

            foreach (var recordInfo in records)
            {
                ResultCodeEnum result = HistoryLogger.WriteLog(recordInfo.Value, recordInfo.Key, CommandType.SendScheduledMessage, trainId, MessageStatusType.InstantMessageDistributionProcessing, startDate, endDate);
                Expect(result, Is.EqualTo(ResultCodeEnum.RequestAccepted), "Failed to insert schedule message into the history log");
            }

            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(records.Length), "Table MessageContext wasn't updated as expected by method HistoryLogger.WriteLog");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(records.Length), "Table MessageRequest wasn't updated as expected by method HistoryLogger.WriteLog");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(records.Length), "Table MessageStatus wasn't updated as expected by method HistoryLogger.WriteLog");

            KeyValuePair <Guid, MessageStatusType>[] extraStatus =
            {
                new KeyValuePair <Guid, MessageStatusType>(records[1].Key, MessageStatusType.InstantMessageDistributionSent),
                new KeyValuePair <Guid, MessageStatusType>(records[1].Key, MessageStatusType.InstantMessageDistributionTimedOut),
                new KeyValuePair <Guid, MessageStatusType>(records[5].Key, MessageStatusType.InstantMessageDistributionSent),
                new KeyValuePair <Guid, MessageStatusType>(records[5].Key, MessageStatusType.InstantMessageDistributionReceived),
                new KeyValuePair <Guid, MessageStatusType>(records[3].Key, MessageStatusType.InstantMessageDistributionWaitingToSend),
                new KeyValuePair <Guid, MessageStatusType>(records[2].Key, MessageStatusType.InstantMessageDistributionMessageLimitExceededError),
                new KeyValuePair <Guid, MessageStatusType>(records[7].Key, MessageStatusType.InstantMessageDistributionUnexpectedError)
            };

            foreach (var status in extraStatus)
            {
                ResultCodeEnum result = HistoryLogger.UpdateMessageStatus(trainId, status.Key, status.Value, CommandType.SendScheduledMessage);
                Expect(result, Is.EqualTo(ResultCodeEnum.RequestAccepted), "Failed to update status of a request");
            }


            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(records.Length), "Table MessageContext has been updated by method HistoryLogger.UpdateMessageStatus while expecting not");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(records.Length), "Table MessageRequest has been updated by method HistoryLogger.UpdateMessageStatus while expecting not");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(records.Length + extraStatus.Length), "Table MessageStatus wasn't updated as expected by method HistoryLogger.UpdateMessageStatus");


            TestDelegate method = () => HistoryLogger.MarkPendingMessagesAsCanceledByStartup();

            Assert.That <TestDelegate>(ref method, Throws.Nothing, "Method MarkPendingMessagesAsCanceledByStartup failed while expecting not");

            Expect(CountRecordInTable(MessageContextTableName), Is.EqualTo(records.Length), "Table MessageContext has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(records.Length), "Table MessageRequest has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(records.Length + extraStatus.Length + 4), "Table MessageStatus wasn't updated as expected by method MarkPendingMessagesAsCanceledByStartup");
        }