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"); }
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); }
/// <summary> /// Method used to write history log details. /// </summary> /// <param name="context"> message details</param> /// <param name="requestId">request id of the message</param> /// <param name="commandType">command type</param> /// <param name="trainId">list of train ids</param> /// <param name="messageStatus">message status</param> /// <param name="startDate"> start date of activation</param> /// <param name="endDate">end date of activation</param> /// <returns>Error code if any</returns> public static ResultCodeEnum WriteLog(string context, Guid requestId, PIS.Ground.Core.Data.CommandType commandType, string trainId, MessageStatusType messageStatus, DateTime startDate, DateTime endDate) { if (HistoryLoggerConfiguration.Used) { return(HistoryLogger.WriteLog(context, requestId, commandType, trainId, messageStatus, startDate, endDate)); } else { return(ResultCodeEnum.RequestAccepted); } }
public void TestCancelLog() { 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); Assert.AreEqual(ResultCodeEnum.RequestAccepted, res); }
public void TestMaxCountTest() { for (int i = 0; i < 100; i++) { Guid id = Guid.NewGuid(); HistoryLogger.WriteLog("TestWritelog", id, CommandType.SendScheduledMessage, "TRAIN" + i.ToString(), MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now); } List <CommandType> lst = new List <CommandType>(); lst.Add(CommandType.CancelScheduledMessage); lst.Add(CommandType.SendScheduledMessage); string str; ResultCodeEnum res = HistoryLogger.GetAllLog(lst, DateTime.Parse("2012-06-26"), DateTime.Parse("2012-06-29"), 0, out str); Assert.AreEqual(ResultCodeEnum.OutputLimitExceed, res); }
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"); }
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"); }
public void TestWriteLogTrain_Error() { ResultCodeEnum res = HistoryLogger.WriteLog("Test1", Guid.NewGuid(), CommandType.SendScheduledMessage, "", MessageStatusType.InstantMessageDistributionProcessing, DateTime.Now, DateTime.Now); Assert.AreNotEqual(ResultCodeEnum.RequestAccepted, res); }