コード例 #1
0
        public void ExModerationEvent_BuildExModerationEvents_ExpectUriToBeCorrect()
        {
            _mockreader = MockRepository.GenerateStub<IDnaDataReader>();

            _mockreader.Stub(c => c.GetInt32NullAsZero("modid")).Return(0);
            _mockreader.Stub(c => c.GetString("notes")).Return(null);
            _mockreader.Stub(c => c.GetString("uri")).Return(_uri);
            _mockreader.Stub(c => c.GetDateTime("datecompleted")).Return(DateTime.MinValue);
            _mockreader.Stub(c => c.GetInt32NullAsZero("status")).Return(0);
            _mockreader.Stub(c => c.GetString("callbackuri")).Return(null);
            _mockreader.Stub(c => c.GetString("reasontype")).Return(null);
            _mockreader.Stub(c => c.GetString("reasontext")).Return(null);

            ExModerationEvent activity = new ExModerationEvent();
            activity = ExModerationEvent.CreateExModerationEvent(_mockreader);

            Assert.AreEqual(_uri, activity.Uri);
        }
コード例 #2
0
        private HttpStatusCode SendEvent(ExModerationEvent activity)
        {
            IDnaHttpClient client = HttpClientCreator.CreateHttpClient(new Uri(activity.CallBackUri));
            
            String  activityAsJSON = activity.ToJSON();


            ExModLogger.LogRequest(activityAsJSON, activity.CallBackUri);

            HttpContent content =
                HttpContent.Create(activityAsJSON, "application/json");

            try
            {

                using (HttpResponseMessage response = client.Post(new Uri("", UriKind.Relative), content))
                {
                    ExModLogger.LogResponse(response.StatusCode, response);
                    return response.StatusCode;
                }
            }
            catch (HttpProcessingException e)
            {
                // Handle errors due to unreachable urls.
                if (e.Message.Contains(Convert.ToString(HttpStatusCode.GatewayTimeout)))
                {
                    return HttpStatusCode.GatewayTimeout;
                }
                else
                {
                    //Other errors need to be handled and the item marked for reprocessing
                    ExModLogger.LogException(e);
                    return HttpStatusCode.InternalServerError;
                }
            }
        }
コード例 #3
0
        public void ExModerationEvent_SendExModerationEvents_ExpectReasonTextToBeSentEvenIfFailedModerationItemHadNoReasonTextStoredInDatabase()
        {
            _mockreader = MockRepository.GenerateStub<IDnaDataReader>();

            _mockreader.Stub(c => c.GetInt32NullAsZero("modid")).Return(_modId);
            _mockreader.Stub(c => c.GetString("notes")).Return(_notes);
            _mockreader.Stub(c => c.GetString("uri")).Return(_uri);
            _mockreader.Stub(c => c.GetDateTime("datecompleted")).Return(_completedDate);
            _mockreader.Stub(c => c.GetInt32NullAsZero("status")).Return(_decisionId);
            _mockreader.Stub(c => c.GetString("callbackuri")).Return(_callbackUri);
            _mockreader.Stub(c => c.GetString("reasontype")).Return(null);
            _mockreader.Stub(c => c.GetString("reasontext")).Return(null);

            ExModerationEvent activity = new ExModerationEvent();
            activity = ExModerationEvent.CreateExModerationEvent(_mockreader);

            string json = activity.ToJSON();

            Assert.IsTrue(json.Contains("\"reasontext\":\"\""));
        }
コード例 #4
0
        public void ExModerationEvent_SendExModerationEvents_ExpectStatusToBeSent()
        {
            _mockreader = MockRepository.GenerateStub<IDnaDataReader>();

            _mockreader.Stub(c => c.GetInt32NullAsZero("modid")).Return(_modId);
            _mockreader.Stub(c => c.GetString("notes")).Return(_notes);
            _mockreader.Stub(c => c.GetString("uri")).Return(_uri);
            _mockreader.Stub(c => c.GetDateTime("datecompleted")).Return(_completedDate);
            _mockreader.Stub(c => c.GetInt32NullAsZero("status")).Return(_decisionId);
            _mockreader.Stub(c => c.GetString("callbackuri")).Return(_callbackUri);
            _mockreader.Stub(c => c.GetString("reasontype")).Return(_reasonType);
            _mockreader.Stub(c => c.GetString("reasontext")).Return(_reasonText);

            ExModerationEvent activity = new ExModerationEvent();
            activity = ExModerationEvent.CreateExModerationEvent(_mockreader);

            string json = activity.ToJSON();
            string statusValue = Enum.GetName(typeof(ModDecisionEnum), _decisionId);

            Assert.IsTrue(json.Contains("\"status\":\"" + statusValue + "\""));
        }