예제 #1
0
        public void TheGuideSystem_GetBIEvents_ExpectListOfEvents()
        {
            var rows = new List<DataReaderFactory.TestDatabaseRow>();
            rows.Add(BIEventTestDatabaseRow.CreatePostNeedsRiskAssessmentRow(11, _DT, 12, 13, 14, 15, 16, 17, DateTime.Parse("2010-09-12"), "hello", 23));
            rows.Add(BIEventTestDatabaseRow.CreatePostNeedsRiskAssessmentRow(50, _DT, null, 53, 54, 55, 56, 57, DateTime.Parse("2015-09-12"), "goodbye", 63));
            rows.Add(BIEventTestDatabaseRow.CreatePostToForumRow(70, _DT, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, DateTime.Parse("2020-09-12"), "eh?"));
            DataReaderFactory.CreateMockedDataBaseObjects(_mocks, "getbievents", out _mockcreator, out _mockreader, rows);

            var riskModSystem = _mocks.Stub<IRiskModSystem>();

            var g = new TheGuideSystem(_mockcreator, riskModSystem);

            var eventList = g.GetBIEvents();

            Assert.AreEqual(3, eventList.Count);

            Assert.IsTrue(eventList[0] is BIPostNeedsRiskAssessmentEvent);
            Assert.IsTrue(eventList[1] is BIPostNeedsRiskAssessmentEvent);
            Assert.IsTrue(eventList[2] is BIPostToForumEvent);

            Assert.AreEqual(EventTypes.ET_POSTNEEDSRISKASSESSMENT, eventList[0].EventType);
            Assert.AreEqual(EventTypes.ET_POSTNEEDSRISKASSESSMENT, eventList[1].EventType);
            Assert.AreEqual(EventTypes.ET_POSTTOFORUM, eventList[2].EventType);
        }
예제 #2
0
        private void Helper_TheGuideSystem_TestRecordRiskModDecisionsOnPosts_Processed_CheckTheParamsAreCorrect(bool process, bool? RiskyValue)
        {
            DataReaderFactory.CreateMockedDataBaseObjects(_mocks, "riskmod_recordriskmoddecisionforthreadentry", out _mockcreator, out _mockreader, null);
            var mockreader = _mockreader;
            TheGuideSystem g = new TheGuideSystem(_mockcreator, null);

            var logger = new TestDnaLogger();
            BIEventProcessor.BIEventLogger = logger;

            // We need a IRiskModSystem do we can "Process" the event
            var rm = _mocks.Stub<IRiskModSystem>();
            bool? dummyrisky;
            rm.Stub(x => x.RecordPostToForumEvent(null, out dummyrisky)).IgnoreArguments().OutRef(RiskyValue).Return(true);

            // Create an event and process it
            var evList = new List<BIPostToForumEvent>();
            var ev = MakeTestBIPostToForumEvent(42, rm);
            if (process)
                ev.Process();
            evList.Add(ev);

            // Record the decision in TheGuide system 
            g.RecordRiskModDecisionsOnPosts(evList);

            if (process)
            {
                // Check the logging
                Assert.IsNotNull(logger.logList.Find(x => x.Message == "RecordRiskModDecisionsOnPost() end"));
                Assert.AreEqual(logger.logList[0].ExtendedProperties["SiteId"], 74);
                Assert.AreEqual(logger.logList[0].ExtendedProperties["ForumId"], 75);
                Assert.AreEqual(logger.logList[0].ExtendedProperties["ThreadEntryId"], 42);
                if (RiskyValue.HasValue)
                    Assert.AreEqual(logger.logList[0].ExtendedProperties["Risky"], RiskyValue);
                else
                    Assert.AreEqual(logger.logList[0].ExtendedProperties["Risky"], "NULL");

                // Check the params sent to the sp
                mockreader.AssertWasCalled(x => x.AddParameter("siteid", 74));
                mockreader.AssertWasCalled(x => x.AddParameter("forumid", 75));
                mockreader.AssertWasCalled(x => x.AddParameter("threadentryid", 42));
                mockreader.AssertWasCalled(x => x.AddParameter("risky", RiskyValue));

                mockreader.AssertWasCalled(x => x.Execute());
            }
            else
            {
                Assert.IsTrue(logger.logList.Count == 0);

                mockreader.AssertWasNotCalled(x => x.Execute());
            }
        }
예제 #3
0
        void BIEventProcessor_Tick(object sender, ElapsedEventArgs e)
        {
            if (Monitor.TryEnter(_locker))
            {
                DateTime tickStart = DateTime.Now;

                TickCounter += 1;
                BIEventLogger.Log(TraceEventType.Verbose,"============== Tick start: " + TickCounter);

                RiskModSystem riskModSys = null;
                TheGuideSystem theGuideSys = null;
                List<BIEvent> events = null;

                try
                {
                    riskModSys = new RiskModSystem(RiskModDataReaderCreator, DisableRiskMod);
                    theGuideSys = new TheGuideSystem(TheGuideDataReaderCreator, riskModSys);

                    events = theGuideSys.GetBIEvents();

                    if (events.Count > 0)
                    {
                        ProcessEvents(events,NumThreads);

                        if (RecRiskModDecOnThreadEntries)
                            RecordRiskModDecisionsOnThreadEntries(theGuideSys, events);
                    }
                }
                catch (Exception ex)
                {
                    BIEventLogger.LogException(ex);
                }
                finally
                {
                    try
                    {
                        // Remove events we managed to process, even if an Exception was caught
                        var processedEvents = GetProcessedEventsList(events);
                        if (processedEvents.Count > 0)
                            theGuideSys.RemoveBIEvents(processedEvents);
                    }
                    catch (Exception ex)
                    {
                        BIEventLogger.LogException(ex);
                    }

                    TimeSpan tickTime = DateTime.Now - tickStart;

                    BIEventLogger.Log(TraceEventType.Verbose,"^^^^^^^^^^^^^^ Tick end: " + TickCounter + " (" + tickTime.TotalSeconds+"s)");
                    Monitor.Exit(_locker);
                }
            }
         }