public void SuccessfulResponseCodes_IsEmptyByDefault()
 {
     using (var test = TelemetryProcessorTest <RequestTelemetryProcessor> .Create())
     {
         Assert.Empty(test.Processor.SuccessfulResponseCodes);
     }
 }
        public void Process_ThrowsForNullItem()
        {
            using (var test = TelemetryProcessorTest <RequestTelemetryProcessor> .Create())
            {
                var exception = Assert.Throws <ArgumentNullException>(() => test.Processor.Process(item: null));

                Assert.Equal("item", exception.ParamName);
            }
        }
        public void Process_SetsSuccessToTrueForRequestTelemetryWithSuccessfulResponseCode(bool actualSuccess)
        {
            var responseCode = 400;
            var telemetry    = new RequestTelemetry()
            {
                ResponseCode = responseCode.ToString(),
                Success      = actualSuccess
            };

            using (var test = TelemetryProcessorTest <RequestTelemetryProcessor> .Create())
            {
                test.NextProcessor.Setup(x => x.Process(It.IsNotNull <RequestTelemetry>()))
                .Verifiable();

                test.Processor.SuccessfulResponseCodes.Add(responseCode);
                test.Processor.Process(telemetry);

                Assert.True(telemetry.Success);
            }
        }
        public void Process_AlwaysCallsNextProcessorForRequestTelemetry(int responseCode)
        {
            var telemetry = new RequestTelemetry()
            {
                ResponseCode = responseCode.ToString(),
                Success      = false
            };

            using (var test = TelemetryProcessorTest <RequestTelemetryProcessor> .Create())
            {
                test.NextProcessor.Setup(x => x.Process(It.Is <RequestTelemetry>(rt => ReferenceEquals(rt, telemetry))));

                test.Processor.SuccessfulResponseCodes.Add(400);
                test.Processor.Process(telemetry);

                test.NextProcessor.Verify(
                    x => x.Process(It.Is <RequestTelemetry>(rt => ReferenceEquals(rt, telemetry))),
                    Times.Once());
            }
        }
        public void Process_DoesNotModifySuccessForRequestTelemetryWithOtherResponseCodes(
            string responseCode,
            bool actualSuccess)
        {
            var telemetry = new RequestTelemetry()
            {
                ResponseCode = responseCode,
                Success      = actualSuccess
            };

            using (var test = TelemetryProcessorTest <RequestTelemetryProcessor> .Create())
            {
                test.NextProcessor.Setup(x => x.Process(It.IsNotNull <RequestTelemetry>()))
                .Verifiable();

                test.Processor.SuccessfulResponseCodes.Add(400);
                test.Processor.Process(telemetry);

                Assert.Equal(actualSuccess, telemetry.Success);
            }
        }
        public void Process_MultipleSuccessfulResponseCodes_SetsSuccessToTrueForRequestTelemetryWithSuccessfulResponseCode(
            int responseCode)
        {
            var telemetry = new RequestTelemetry()
            {
                ResponseCode = responseCode.ToString(),
                Success      = false
            };

            using (var test = TelemetryProcessorTest <RequestTelemetryProcessor> .Create())
            {
                test.NextProcessor.Setup(x => x.Process(It.IsNotNull <RequestTelemetry>()))
                .Verifiable();

                test.Processor.SuccessfulResponseCodes.Add(400);
                test.Processor.SuccessfulResponseCodes.Add(404);

                test.Processor.Process(telemetry);

                Assert.True(telemetry.Success);
            }
        }