示例#1
0
        public void TestCancelLogUpdateMessageStatusError()
        {
            Guid           id  = Guid.NewGuid();
            ResultCodeEnum res = HistoryLogger.UpdateMessageStatus("TRAIN1", id, MessageStatusType.InstantMessageDistributionReceived);

            Assert.AreNotEqual(ResultCodeEnum.RequestAccepted, res);
        }
示例#2
0
        public void TestWriteLogMuiltiTrainUpateEmptyError()
        {
            Guid id = Guid.NewGuid();

            HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN1", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now);

            ResultCodeEnum res = HistoryLogger.UpdateMessageStatus("", id, MessageStatusType.InstantMessageDistributionWaitingToSend);

            Assert.AreNotEqual(ResultCodeEnum.RequestAccepted, res);
        }
示例#3
0
 /// <summary>Method to update the message status.</summary>
 /// <param name="trainId">list of train ids.</param>
 /// <param name="requestId">request id of the message.</param>
 /// <param name="messageStatus">message status.</param>
 /// <param name="commandType">Type of message to update.</param>
 /// <returns>Error code if any.</returns>
 public static ResultCodeEnum UpdateMessageStatus(string trainId, Guid requestId, MessageStatusType messageStatus, CommandType commandType)
 {
     if (HistoryLoggerConfiguration.Used)
     {
         return(HistoryLogger.UpdateMessageStatus(trainId, requestId, messageStatus, commandType));
     }
     else
     {
         return(ResultCodeEnum.RequestAccepted);
     }
 }
示例#4
0
        public void TestMethodMarkPendingMessagesAsCanceledByStartup_BehaveAsExpected_WhenDatabaseContainTwoRecordsInProgressState()
        {
            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");

            result = HistoryLogger.UpdateMessageStatus(trainId, requestId, MessageStatusType.InstantMessageDistributionSent, CommandType.SendScheduledMessage);
            Expect(result, Is.EqualTo(ResultCodeEnum.RequestAccepted), "Failed to update status of a request");

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


            requestId   = Guid.NewGuid();
            trainId     = "TRAIN-2";
            messageText = "This is a second scheduled message in progress";

            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(2), "Table MessageContext wasn't updated as expected by method HistoryLogger.WriteLog");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(2), "Table MessageRequest wasn't updated as expected by method HistoryLogger.WriteLog");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(3), "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(2), "Table MessageContext has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageRequestTableName), Is.EqualTo(2), "Table MessageRequest has been updated by method MarkPendingMessagesAsCanceledByStartup while expecting not");
            Expect(CountRecordInTable(MessageStatusTableName), Is.EqualTo(5), "Table MessageStatus wasn't updated as expected by method MarkPendingMessagesAsCanceledByStartup");
        }
示例#5
0
        public void TestCancelLogUpdateMessageStatus()
        {
            Guid id = Guid.NewGuid();

            HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN1", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now);
            HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN2", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now);
            HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN3", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now);
            HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN4", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now);

            ResultCodeEnum res = HistoryLogger.CancelLog(id, CommandType.CancelScheduledMessage, "TRAIN1", MessageStatusType.InstantMessageDistributionProcessing);

            res = HistoryLogger.UpdateMessageStatus("TRAIN1", id, MessageStatusType.InstantMessageDistributionWaitingToSend);
            res = HistoryLogger.UpdateMessageStatus("TRAIN1", id, MessageStatusType.InstantMessageDistributionSent);
            res = HistoryLogger.UpdateMessageStatus("TRAIN1", id, MessageStatusType.InstantMessageDistributionReceived);
            Assert.AreEqual(ResultCodeEnum.RequestAccepted, res);
        }
示例#6
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");
        }