Exemplo n.º 1
0
        public void RiskModSystem_IsRisky_TestRiskyResult()
        {
            var ev = MakeTestBIPostNeedsRiskAssessmentEvent(12);

            var m = new MockRepository();
            var reader = m.DynamicMock<IDnaDataReader>();
            var creator = m.Stub<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("predict_withoutentryid")).Return(reader);
            reader.Stub(x => x.GetIntReturnValue()).Return(1);
            m.ReplayAll();

            var rm = new RiskModSystem(creator, false);

            bool risky = rm.IsRisky(ev);

            Assert.IsTrue(risky);
        }
Exemplo n.º 2
0
        public void RiskModSystem_When_Disabled_Check_RecordPostModerationDecision_Returns_False()
        {
            // Create with "Disabled" is true
            var rm = new RiskModSystem(null, true);

            var postModDecisionEvent = new BIPostModerationDecisionEvent(null);
            bool recModDec = rm.RecordPostModerationDecision(postModDecisionEvent);
            Assert.IsFalse(recModDec);
        }
Exemplo n.º 3
0
        public void RiskModSystem_When_Disabled_Check_RecordPostToForumEvent_Returns_False()
        {
            // Create with "Disabled" is true
            var rm = new RiskModSystem(null, true);

            var postEvent = new BIPostToForumEvent(null);
            bool? risky;
            bool recPost = rm.RecordPostToForumEvent(postEvent, out risky);
            Assert.IsFalse(recPost);
        }
Exemplo n.º 4
0
        public void RiskModSystem_When_Disabled_Check_IsRisky_Returns_True()
        {
            // Create with "Disabled" is true
            var rm = new RiskModSystem(null, true);

            var postAssessEvent = new BIPostNeedsRiskAssessmentEvent(null, null);
            bool risky = rm.IsRisky(postAssessEvent);
            Assert.IsTrue(risky);
        }
Exemplo n.º 5
0
        public void RiskModSystem_IsRisky_TestExceptionHandledAndReturnsTrue()
        {
            var ev = MakeTestBIPostNeedsRiskAssessmentEvent(12);

            var m = new MockRepository();
            var reader = m.DynamicMock<IDnaDataReader>();
            var creator = m.Stub<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("predict_withoutentryid")).Return(reader);
            reader.Stub(x => x.GetIntReturnValue()).Return(0).WhenCalled(x => { throw new Exception("Hello!"); });
            m.ReplayAll();

            var rm = new RiskModSystem(creator, false);

            bool risky = rm.IsRisky(ev);

            Assert.IsTrue(risky);
        }
Exemplo n.º 6
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);
                }
            }
         }