public void HandleSingleBlast_WhenRefBlastIsNull_UpdatesSingleBlasts()
        {
            // Arrange
            const int blastId = 1;

            SetFakesForHandleBlastMethod();
            var emailFunctions  = new CommunicatorClasses.EmailFunctions();
            var exceptionLogged = false;

            _logCriticalExceptionText = new StringBuilder();
            ShimApplicationLog.LogCriticalErrorExceptionStringInt32StringInt32Int32 =
                (ex, sourceMethod, applicationID, note, gdCharityID, ecnCustomerID) =>
            {
                _logCriticalExceptionText.AppendLine(note);
                exceptionLogged = true;
                return(1);
            };

            // Act
            _privateECNBlastEngineObj.Invoke(HandleSingleBlastMethodName, emailFunctions);

            // Assert
            exceptionLogged.ShouldBeFalse();
            _sqlCommandExceuted.ShouldNotBeNullOrWhiteSpace();
            _sqlCommandExceuted.ShouldContain($"Update BlastSingles set Processed='U' where BlastSingleID={blastId}");
        }
        public void HandleSingleBlast_WhenGetDataTableThrowsException_LogsException()
        {
            // Arrange
            SetFakesForHandleBlastMethod();
            var emailFunctions  = new CommunicatorClasses.EmailFunctions();
            var exceptionLogged = false;

            _logCriticalExceptionText = new StringBuilder();
            ShimApplicationLog.LogCriticalErrorExceptionStringInt32StringInt32Int32 =
                (ex, sourceMethod, applicationID, note, gdCharityID, ecnCustomerID) =>
            {
                _logCriticalExceptionText.AppendLine(note);
                exceptionLogged = true;
                return(1);
            };
            ShimDataFunctions.GetDataTableString = (cmd) =>
            {
                throw new InvalidOperationException(UTException);
            };

            // Act
            _privateECNBlastEngineObj.Invoke(HandleSingleBlastMethodName, emailFunctions);

            // Assert
            exceptionLogged.ShouldSatisfyAllConditions(
                () => exceptionLogged.ShouldBeTrue(),
                () => _logCriticalExceptionText.ToString().ShouldContain($"An exception Happened when handling Blast Engine ID = {engineID} " +
                                                                         $"and Blast Single ID = {int.MinValue}"),
                () => _logCriticalExceptionText.ToString().ShouldContain($"Exception Message: {UTException}"),
                () => _sqlCommandExceuted.ShouldNotBeNullOrWhiteSpace(),
                () => _sqlCommandExceuted.ShouldContain("Update [BlastSingles] set Processed='e' where BlastSingleID = "));
        }
        public void HandleSingleBlast_WhenRefBlastColumnIsNotNull_ExecutesSqlStatements()
        {
            // Arrange
            const int blastId         = 1;
            var       emailFunctions  = new CommunicatorClasses.EmailFunctions();
            var       exceptionLogged = false;
            var       dataTable       = GetDataTable();

            SetFakesForHandleBlastMethod();
            appSettings.Add("LogStatistics", bool.TrueString);
            ShimApplicationLog.LogCriticalErrorExceptionStringInt32StringInt32Int32 =
                (ex, sourceMethod, applicationID, note, gdCharityID, ecnCustomerID) =>
            {
                exceptionLogged = true;
                return(1);
            };
            ShimDataFunctions.GetDataTableString = (cmd) => dataTable;

            // Act
            _privateECNBlastEngineObj.Invoke(HandleSingleBlastMethodName, emailFunctions);

            // Assert
            exceptionLogged.ShouldSatisfyAllConditions(
                () => exceptionLogged.ShouldBeFalse(),
                () => _sqlCommandExceuted.ShouldContain($"exec sp_getBlastSingleEmailStatus {blastId}"),
                () => _sqlCommandExceuted.ShouldContain($"SELECT RefTriggerID FROM TriggerPlans WHERE TriggerPlanID = {dataTable.Rows[0]["LayoutPlanID"]}"),
                () => _sqlCommandExceuted.ShouldContain($"SELECT COUNT(EmailID) AS 'OpensCount'  FROM ECN_ACTIVITY..BlastActivityOpens " +
                                                        $" WHERE BlastID = {blastId} AND EmailID = {dataTable.Rows[0]["EmailID"]}"),
                () => _sqlCommandExceuted.ShouldContain($"DELETE FROM BlastSingles WHERE BlastSingleID = {blastId}"));
        }
Пример #4
0
        public void HandleBlast_WhenBlastIDFetchQueryAndLoggingThrowsException_ExceptionLoggedAtConsole()
        {
            // Arrange
            var emailFunctions = new CommunicatorClasses.EmailFunctions();

            ConsoleActivityLogFileText = new StringBuilder();
            KMCommonFakes.ShimFileFunctions.LogConsoleActivityStringString = (message, suffix) =>
            {
                ConsoleActivityLogFileText.AppendLine($"{suffix}{message}");
            };

            // Act
            _privateECNBlastEngineObj.Invoke(HandleBlastMethodName, emailFunctions);

            // Assert
            ConsoleActivityLogFileText.ShouldSatisfyAllConditions(
                () => ConsoleActivityLogFileText.ToString().ShouldContain("BlastLog_Error logging critical issue "),
                () => ConsoleActivityLogFileText.ToString().ShouldContain($"BlastLog_BlastID:{int.MinValue}"),
                () => ConsoleActivityLogFileText.ToString().ShouldContain("BlastLog_Original Error Stack:"),
                () => ConsoleActivityLogFileText.ToString().
                ShouldContain("BlastLog_System.InvalidOperationException: The ConnectionString property has not been initialized."),
                () => ConsoleActivityLogFileText.ToString().ShouldContain("BlastLog_Exception stack trace:"),
                () => ConsoleActivityLogFileText.ToString().
                ShouldContain("BlastLog_System.NullReferenceException: Object reference not set to an instance of an object."));
        }
Пример #5
0
        public void HandleBlast_WithBlastIDWithMissingField_HandlesBlastSuccessfully()
        {
            // Arrange
            const int blastId    = 1;
            const int customerId = 1;

            SetFakesForHandleBlastMethod();
            SetECNBlastEngineFakes(missingField: SampleMissingField, isLicenseAvailable: true);
            var emailFunctions = new CommunicatorClasses.EmailFunctions();

            // Act
            _privateECNBlastEngineObj.Invoke(HandleBlastMethodName, emailFunctions);

            // Assert
            _isCacheRemoved.ShouldSatisfyAllConditions(
                () => _isCacheRemoved.ShouldBeTrue(),
                () => _isCacheCreated.ShouldBeTrue(),
                () => _isBlastCloned.ShouldBeFalse(),
                () => _isBlastSend.ShouldBeFalse(),
                () => _sqlCommandExceuted.ShouldNotBeNullOrWhiteSpace(),
                () => _sqlCommandExceuted.ShouldContain($"update blast set starttime = getdate() where blastID={blastId}"),
                () => _sqlCommandExceuted.ShouldContain($"Update [Blast] set StatusCode='cancelled' where BlastID ="),
                () => _mailMessage.From.ToString().ShouldBe(FromEmailAddress),
                () => _mailMessage.To.Count.ShouldBe(1),
                () => _mailMessage.To.ShouldContain(new MailAddress(ToEmailAddress)),
                () => _mailMessage.Body.ShouldContain($"Blast has been cancelled."),
                () => _mailMessage.Body.ShouldContain($"Key data is missing - {SampleMissingField}."),
                () => _mailMessage.Subject.ShouldContain($"Blast Issue for Customer: {customerId}, Blast ID: {blastId}"));
        }
Пример #6
0
        public void HandleBlast_WithBlastIDWithAvailableLicenses_HandlesBlastSuccessfully()
        {
            // Arrange
            const int blastId = 1;

            SetFakesForHandleBlastMethod();
            SetECNBlastEngineFakes(isLicenseAvailable: true);
            var emailFunctions = new CommunicatorClasses.EmailFunctions();

            // Act
            _privateECNBlastEngineObj.Invoke(HandleBlastMethodName, emailFunctions);

            // Assert
            _isCacheCreated.ShouldSatisfyAllConditions(
                () => _isCacheCreated.ShouldBeTrue(),
                () => _isCacheRemoved.ShouldBeTrue(),
                () => _isBlastSend.ShouldBeTrue(),
                () => _isBlastCloned.ShouldBeTrue(),
                () => _sqlCommandExceuted.ShouldNotBeNullOrWhiteSpace(),
                () => _sqlCommandExceuted.ShouldContain($"update blast set starttime = getdate() where blastID={blastId}"),
                () => _sqlCommandExceuted.ShouldContain($"Update Blast set StatusCode='Active' where BlastID={blastId}"),
                () => _sqlCommandExceuted.ShouldContain($"update blast set attempttotal=1,successtotal=1,sendtotal=1 where blastID={blastId}"),
                () => _sqlCommandExceuted.ShouldContain("select count(EAID) from emailactivitylog where " +
                                                        $"actiontypecode in ('send','testsend') and blastID={blastId}"));
        }
Пример #7
0
        public void HandleBlast_WithBlastIDHavingNoLicense_HandlesBlastSuccessfully()
        {
            // Arrange
            SetFakesForHandleBlastMethod();
            int blastId = 1, customerId = 1;

            SetECNBlastEngineFakes();
            var emailFunctions = new CommunicatorClasses.EmailFunctions();

            // Act
            _privateECNBlastEngineObj.Invoke(HandleBlastMethodName, emailFunctions);

            // Assert
            _isCacheCreated.ShouldSatisfyAllConditions(
                () => _isCacheCreated.ShouldBeTrue(),
                () => _isCacheRemoved.ShouldBeTrue(),
                () => _isBlastCloned.ShouldBeFalse(),
                () => _sqlCommandExceuted.ShouldNotBeNullOrWhiteSpace(),
                () => _sqlCommandExceuted.ShouldContain("Update [Blast] set StatusCode='NOLICENSE' where BlastID = "),
                () => _mailMessage.From.ToString().ShouldBe(FromEmailAddress),
                () => _mailMessage.To.Count.ShouldBe(1),
                () => _mailMessage.To.ShouldContain(new MailAddress(ToEmailAddress)),
                () => _mailMessage.Body.ShouldContain($"No licenses available. Blast has been set to NOLICENSE."),
                () => _mailMessage.Subject.ShouldContain($"Blast Issue for Customer: {customerId}, Blast ID: {blastId}"));
        }
Пример #8
0
        public void HandleBlast_WhenCreateCacheThrowsGeneralException_ExceptionLoggedAtConsole()
        {
            // Arrange
            var isCacheRemoved = false;
            var emailFunctions = new CommunicatorClasses.EmailFunctions();

            ConsoleActivityLogFileText = new StringBuilder();
            KMCommonFakes.ShimFileFunctions.LogConsoleActivityStringString = (message, suffix) =>
            {
                ConsoleActivityLogFileText.AppendLine($"{suffix}{message}");
            };
            ShimDataFunctions.ExecuteScalarSqlCommand        = (cmd) => "0";
            ShimECNBlastEngine.AllInstances.RemovecacheInt32 = (b, bid) => { isCacheRemoved = true; };
            ShimECNBlastEngine.AllInstances.CreateCacheInt32 = (b, bid) =>
                                                               throw new InvalidOperationException(UTException);

            // Act
            _privateECNBlastEngineObj.Invoke(HandleBlastMethodName, emailFunctions);

            // Assert
            ConsoleActivityLogFileText.ShouldSatisfyAllConditions(
                () => isCacheRemoved.ShouldBeTrue(),
                () => ConsoleActivityLogFileText.ToString().ShouldContain("BlastLog_Error logging critical issue "),
                () => ConsoleActivityLogFileText.ToString().ShouldContain($"BlastLog_BlastID:{0}"),
                () => ConsoleActivityLogFileText.ToString().ShouldContain("BlastLog_Original Error Stack:"),
                () => ConsoleActivityLogFileText.ToString().
                ShouldContain($"BlastLog_System.InvalidOperationException: {UTException}"),
                () => ConsoleActivityLogFileText.ToString().ShouldContain("BlastLog_Exception stack trace:"),
                () => ConsoleActivityLogFileText.ToString().
                ShouldContain("BlastLog_System.NullReferenceException: Object reference not set to an instance of an object."),
                () => ConsoleActivityLogFileText.ToString().ShouldContain("BlastLog_Error setting blast status to error"),
                () => ConsoleActivityLogFileText.ToString().
                ShouldContain("BlastLog_System.InvalidOperationException: The ConnectionString property has not been initialized."));
        }
        public void HandleSingleBlast_WhenRefBlastColumnIsNotNullAndOpensCountIsZero_ExecutesSqlStatements()
        {
            // Arrange
            const int blastId         = 1;
            var       emailFunctions  = new CommunicatorClasses.EmailFunctions();
            var       exceptionLogged = false;

            _sqlCommandExceuted = string.Empty;
            var dataTable = GetDataTable();

            SetFakesForHandleBlastMethod();
            appSettings.Add("LogStatistics", bool.TrueString);
            ShimApplicationLog.LogCriticalErrorExceptionStringInt32StringInt32Int32 =
                (ex, sourceMethod, applicationID, note, gdCharityID, ecnCustomerID) =>
            {
                exceptionLogged = true;
                return(1);
            };
            ShimDataFunctions.GetDataTableString  = (cmd) => dataTable;
            ShimDataFunctions.ExecuteScalarString = (query) =>
            {
                _sqlCommandExceuted += query;
                if (query.Contains("SELECT COUNT(EmailID) AS 'OpensCount'"))
                {
                    return(0);
                }
                return(1);
            };

            // Act
            _privateECNBlastEngineObj.Invoke(HandleSingleBlastMethodName, emailFunctions);

            // Assert
            exceptionLogged.ShouldSatisfyAllConditions(
                () => exceptionLogged.ShouldBeFalse(),
                () => _sqlCommandExceuted.ShouldContain($"exec sp_getBlastSingleEmailStatus {blastId}"),
                () => _sqlCommandExceuted.ShouldContain($"SELECT RefTriggerID FROM TriggerPlans WHERE TriggerPlanID = {dataTable.Rows[0]["LayoutPlanID"]}"),
                () => _sqlCommandExceuted.ShouldContain($"UPDATE BlastSingles SET StartTime = GETDATE() WHERE " +
                                                        $"BlastSingleID = {dataTable.Rows[0]["BlastSingleID"]}"),
                () => _sqlCommandExceuted.ShouldContain($"SELECT COUNT(EmailID) AS 'OpensCount'  FROM ECN_ACTIVITY..BlastActivityOpens  " +
                                                        $"WHERE BlastID = {blastId} AND EmailID = {dataTable.Rows[0]["EmailID"]}"),
                () => _sqlCommandExceuted.ShouldContain($"SELECT COUNT(EmailID) AS 'OpensCount'  FROM ECN5_Communicator..EmailActivityLog eal " +
                                                        $"with(nolock)  WHERE eal.BlastID = {blastId} AND EmailID = {dataTable.Rows[0]["EmailID"]} AND ActionTypeCode = 'open'"),
                () => _sqlCommandExceuted.ShouldContain($"Update BlastSingles set Processed='y', " +
                                                        $"EndTime = GETDATE() where BlastSingleID={dataTable.Rows[0]["BlastSingleID"]}"),
                () => _sqlCommandExceuted.ShouldContain($"Update [Blast] set SendTime=GetDate() where BlastID={blastId}"),
                () => _sqlCommandExceuted.ShouldContain($"select count(SendID) from BlastActivitySends where BlastID={blastId}"),
                () => _sqlCommandExceuted.ShouldContain($"update [blast] set attempttotal=1,successtotal=1,sendtotal=1 where blastID={blastId}"));
        }
Пример #10
0
        public void HandleBlast_WhenCreateCacheThrowsECNException_ExceptionLoggedAtConsole()
        {
            // Arrange
            var isCacheRemoved  = false;
            var exceptionLogged = false;

            _sqlCommandExceuted = string.Empty;
            var emailFunctions = new CommunicatorClasses.EmailFunctions();

            ShimDataFunctions.ExecuteScalarSqlCommand        = (cmd) => "0";
            ShimECNBlastEngine.AllInstances.RemovecacheInt32 = (b, bid) => { isCacheRemoved = true; };
            ShimECNBlastEngine.AllInstances.CreateCacheInt32 = (b, bid) =>
                                                               throw new ECNException(new List <ECNError>
            {
                new ECNError {
                    ErrorMessage = UTException
                }
            });
            ShimApplicationLog.LogCriticalErrorExceptionStringInt32StringInt32Int32 =
                (ex, sourceMethod, applicationID, note, gdCharityID, ecnCustomerID) =>
            {
                exceptionLogged = true;
                return(1);
            };
            ShimDataFunctions.ExecuteSqlCommand = (cmd) =>
            {
                _sqlCommandExceuted = cmd.CommandText;
                return(1);
            };

            // Act
            _privateECNBlastEngineObj.Invoke(HandleBlastMethodName, emailFunctions);

            // Assert
            exceptionLogged.ShouldSatisfyAllConditions(
                () => exceptionLogged.ShouldBeTrue(),
                () => isCacheRemoved.ShouldBeTrue(),
                () => _sqlCommandExceuted.ShouldNotBeNullOrWhiteSpace(),
                () => _sqlCommandExceuted.ShouldContain("Update [Blast] set StatusCode='error' where BlastID = "));
        }
Пример #11
0
        public void HandleBlast_WhenCreateCacheThrowsException_ExceptionLoggedAtConsole()
        {
            // Arrange
            var       isCacheRemoved     = false;
            const int blastId            = 1;
            const int customerId         = 1;
            var       sqlCommandExceuted = string.Empty;
            var       emailFunctions     = new CommunicatorClasses.EmailFunctions();

            _mailMessage = null;
            ShimDataFunctions.ExecuteScalarSqlCommand        = (cmd) => "0";
            ShimECNBlastEngine.AllInstances.RemovecacheInt32 = (b, bid) => { isCacheRemoved = true; };
            ShimECNBlastEngine.AllInstances.CreateCacheInt32 = (b, bid) =>
                                                               throw new BlastHoldException(UTException, new InvalidOperationException(), StatusHold, blastId, customerId);

            ShimDataFunctions.ExecuteSqlCommand = (cmd) =>
            {
                sqlCommandExceuted = cmd.CommandText;
                return(1);
            };
            ShimSmtpClient.AllInstances.SendMailMessage = (smtp, msg) => { _mailMessage = msg; };

            // Act
            _privateECNBlastEngineObj.Invoke(HandleBlastMethodName, emailFunctions);

            // Assert
            sqlCommandExceuted.ShouldSatisfyAllConditions(
                () => sqlCommandExceuted.ShouldNotBeNullOrWhiteSpace(),
                () => sqlCommandExceuted.ShouldContain("Update [Blast] set StatusCode=@NewStatus where BlastID = "),
                () => _mailMessage.ShouldNotBeNull(),
                () => _mailMessage.From.ToString().ShouldBe(FromEmailAddress),
                () => _mailMessage.To.Count.ShouldBe(1),
                () => _mailMessage.To.ShouldContain(new MailAddress(ToEmailAddress)),
                () => _mailMessage.Body.ShouldContain($"Blast Issue for Customer: {customerId}, Blast ID: {blastId} Has been set to {StatusHold}"),
                () => _mailMessage.Body.ShouldContain(UTException),
                () => _mailMessage.Subject.ShouldContain($"Blast Issue for Customer: {customerId}, Blast ID: {blastId} Has been set to {StatusHold}"),
                () => isCacheRemoved.ShouldBeTrue());
        }