Example #1
0
            public void GoodWarningLogNoException_HasProperEnvironment()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                string expected = ConfigurationHelper.GetActiveConfiguration();

                // act
                log.WriteWarningLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Application.Environment.Equals(expected))),
                        Times.Once,
                        "Application Environment not set properly");
            }
Example #2
0
            public void GoodWarningLogNoException_HasProperSeverity()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                int expected = 2;

                // act
                log.WriteWarningLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.EntryType.Id.Equals(expected))),
                        Times.Once,
                        "Severity level not set properly");
            }
Example #3
0
            public void GoodInformationLog_CallsPublishToQueueAndSetsStackTrace()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                Exception exception             = MakeException();

                // act
                log.WriteInformationLog("Ooops!", exception);

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Exception.StackTrace.Length > 0)),
                        Times.Once,
                        "StackTrace is not being set");
            }
Example #4
0
            public void GoodWarningLogNoException_HasMessage()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                string expected = "test";

                // act
                log.WriteWarningLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Message.Equals(expected))),
                        Times.Once,
                        "Message was not set properly");
            }
Example #5
0
            public void GoodWarningLog_CallsPublishToQueueWithExceptionMessage()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                string expected = "Something went wrong!";

                // act
                log.WriteWarningLog(expected, MakeException());

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Message.Equals(expected))),
                        Times.Once,
                        "Message did not match");
            }
Example #6
0
            public void GoodWarningLogNoException_HasApplicationName()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                string expected = ConfigurationManager.AppSettings["AppName"];

                // act
                log.WriteWarningLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Application.Name.Equals(expected))),
                        Times.Once,
                        "Application Name not set properly");
            }
Example #7
0
            public void GoodWarningLog_CallsPublishToQueueAndSetsMachineName()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                Exception exception             = MakeException();

                // act
                log.WriteWarningLog("Oops!", exception);

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Machine.Name.Length > 0)),
                        Times.Once(),
                        "Machine name did not get set");
            }
Example #8
0
            public void GoodInformationLogNoException_HasMachineName()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                string expected = Environment.MachineName;

                // act
                log.WriteInformationLog("test");

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Machine.Name.Equals(expected))),
                        Times.Once,
                        "Machine.Name not set properly");
            }
Example #9
0
            public void GoodInformationLog_HasTheProperSeverity()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                Exception exception             = MakeException();
                int       expectedSeverity      = 1;

                // act
                log.WriteInformationLog("Oops!", exception);

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.EntryType.Id.Equals(expectedSeverity))),
                        Times.Once(),
                        "Severity level not set to information");
            }
Example #10
0
            public void GoodInformationLog_HasEnvironmentSet()
            {
                // arrange
                MockDependents dependents       = MakeMockDependents();
                EventLogQueueRepositoryImpl log = new EventLogQueueRepositoryImpl(dependents.QueueRepository.Object);
                Exception exception             = MakeException();
                string    expectedConfiguration = ConfigurationHelper.GetActiveConfiguration();

                // act
                log.WriteInformationLog("Oops!", exception);

                // assert
                dependents.QueueRepository
                .Verify(x => x.PublishLogMessage(It.Is <LogMessage>(m => m.Application.Environment.Equals(expectedConfiguration))),
                        Times.Once(),
                        "Environment not set properly");
            }
Example #11
0
        protected void Application_Start()
        {
            try
            {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl("KeithLink.FoundationSvc");
                eventLog.WriteInformationLog("Foundation Service Starting Up");
            }
            catch (Exception ex)
            {
                string sSource = "KeithLink.FoundationSvc";
                string sLog    = "Application";
                string sEvent  = "Error trying to log in startup: " + ex.ToString();

                if (!EventLog.SourceExists(sSource))
                {
                    EventLog.CreateEventSource(sSource, sLog);
                }

                EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Error, 234);
            }
        }
Example #12
0
        private static string GetNextControlNumber()
        {
            try {
                string controlNumber = string.Empty;
                // get tracking number from DB
                using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["BEKDBContext"].ConnectionString)) {
                    using (SqlCommand cmd = new SqlCommand("Orders.usp_GetNextControlNumber", conn)) {
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter parm = new SqlParameter();
                        parm.Direction = ParameterDirection.ReturnValue;
                        cmd.Parameters.Add(parm);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        controlNumber = (int.Parse(cmd.Parameters[0].Value.ToString())).ToString("0000000.##"); // format to main frame of 7 digits
                    }
                }
                return(controlNumber);
            } catch (Exception ex) {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in GetNextControlNumber: ", ex);

                throw ex;
            }
        }
Example #13
0
        public string UpdatePurchaseOrder(Guid userId, Guid orderId, string requestedShipDate, List <PurchaseOrderLineItemUpdate> lineItemUpdates)
        {
            try
            {
                CommerceServer.Core.Runtime.Orders.PurchaseOrder po        = GetPurchaseOrder(userId, orderId);
                CommerceServer.Core.Runtime.Orders.LineItem[]    lineItems = new CommerceServer.Core.Runtime.Orders.LineItem[po.OrderForms[0].LineItems.Count];
                po.OrderForms[0].LineItems.CopyTo(lineItems, 0);
                po["RequestedShipDate"] = requestedShipDate;

                foreach (PurchaseOrderLineItemUpdate i in lineItemUpdates)
                {
                    CommerceServer.Core.Runtime.Orders.LineItem lineItem = lineItems.Where(x => x.ProductId == i.ItemNumber).FirstOrDefault();
                    // find existing item based on item number
                    if (i.Status == "changed" && lineItem != null)
                    {
                        lineItem.Quantity       = i.Quantity;
                        lineItem["Each"]        = i.Each;
                        lineItem["CatchWeight"] = i.CatchWeight;
                        lineItem.Status         = "changed";
                    }
                    if (i.Status == "deleted" && lineItem != null)
                    {
                        lineItem.Status = "deleted";
                    }
                    if (i.Status == "added" && lineItem == null)
                    {
                        CommerceServer.Core.Runtime.Orders.LineItem li = new CommerceServer.Core.Runtime.Orders.LineItem()
                        {
                            ProductId = i.ItemNumber, Quantity = i.Quantity, Status = "added"
                        };
                        li["CatchWeight"]  = i.CatchWeight;
                        li["Each"]         = i.Each;
                        li["Notes"]        = string.Empty;
                        li.ProductCatalog  = i.Catalog;
                        li.Status          = "added";
                        li["LinePosition"] = po.OrderForms[0].LineItems.Count + 1;
                        po.OrderForms[0].LineItems.Add(li);
                    }
                    if (i.Status == "added" && lineItem != null)
                    {
                        lineItem.Quantity       = i.Quantity;
                        lineItem["Each"]        = i.Each;
                        lineItem["CatchWeight"] = i.CatchWeight;
                    }
                }

                if (po.Status.StartsWith("confirmed", StringComparison.InvariantCultureIgnoreCase))
                {
                    po.Status = "Confirmed with un-submitted changes";
                }

                PipelineHelper pipeLineHelper = new PipelineHelper(Extensions.SiteHelper.GetSiteName());
                pipeLineHelper.RunPipeline(og: po,
                                           transacted: true,
                                           loggingEnabled: false,
                                           pipelineName: "Checkout",
                                           pipelinePath: string.Format
                                               ("{0}\\pipelines\\checkout.pcf",
                                               HttpContext.Current.Server.MapPath(".")));

                po.Save();
                return(po.TrackingNumber);
            }
            catch (Exception ex)
            {
                EventLogQueueRepositoryImpl eventLog = new EventLogQueueRepositoryImpl(applicationNameForLogging);
                eventLog.WriteErrorLog("Error in UpdatePurchaseOrder: ", ex);

                throw ex;
            }
        }