コード例 #1
0
        public void TestApplicationNameRequired()
        {
            DfpSoapHeaderInspector inspector = new DfpSoapHeaderInspector()
            {
                Config = new DfpAppConfig()
            };
            RequestHeader header = new RequestHeader()
            {
                networkCode = "12345"
            };

            inspector.RequestHeader = header;

            Assert.Throws(typeof(DfpApiException), delegate() {
                inspector.BeforeSendRequest(ref this.message, this.channel);
            }, "No exception was thrown for a null application name");

            header.applicationName = DfpAppConfig.DEFAULT_APPLICATION_NAME;
            Assert.Throws(typeof(DfpApiException), delegate() {
                inspector.BeforeSendRequest(ref this.message, this.channel);
            }, "No exception was thrown for the default application name");

            header.applicationName = "";
            Assert.Throws(typeof(DfpApiException), delegate() {
                inspector.BeforeSendRequest(ref this.message, this.channel);
            }, "No exception was thrown for an empty string application name");
        }
コード例 #2
0
        public void TestHeaderUpdatesApplied()
        {
            AdsServiceInspectorBehavior behavior  = new AdsServiceInspectorBehavior();
            DfpSoapHeaderInspector      inspector = new DfpSoapHeaderInspector();

            behavior.Add(inspector);

            DfpSoapClient <IMockAdsService> service = new DfpSoapClient <IMockAdsService>(
                new BasicHttpBinding(),
                new EndpointAddress("https://www.google.com"));

            service.Endpoint.EndpointBehaviors.Add(behavior);

            Assert.IsNull(service.RequestHeader);
            RequestHeader expected = new RequestHeader()
            {
                networkCode = "12345"
            };

            service.RequestHeader = expected;
            Assert.AreEqual(expected, inspector.RequestHeader);

            // Test removing a network code
            expected.networkCode = null;
            Assert.AreEqual(expected, inspector.RequestHeader);
        }
コード例 #3
0
        public void TestNullHeaderInvalid()
        {
            DfpSoapHeaderInspector inspector = new DfpSoapHeaderInspector()
            {
                Config = new DfpAppConfig()
            };

            Assert.Throws(typeof(DfpApiException), delegate() {
                inspector.BeforeSendRequest(ref this.message, this.channel);
            }, "No exception was thrown for a null header");
        }
コード例 #4
0
        public void TestNullConfigInvalid()
        {
            DfpSoapHeaderInspector inspector = new DfpSoapHeaderInspector()
            {
                Config        = null,
                RequestHeader = new RequestHeader()
                {
                    networkCode = "12345"
                }
            };

            Assert.Throws(typeof(DfpApiException), delegate() {
                inspector.BeforeSendRequest(ref this.message, this.channel);
            }, "No exception was thrown for a null Config");
        }
コード例 #5
0
        public void TestValidHeaderApplied()
        {
            DfpSoapHeaderInspector inspector = new DfpSoapHeaderInspector();
            RequestHeader          header    = new RequestHeader()
            {
                networkCode = "12345",
            };
            DfpAppConfig config = new DfpAppConfig();

            config.ApplicationName  = "Unit test application";
            inspector.Config        = config;
            inspector.RequestHeader = (RequestHeader)header.Clone();
            inspector.BeforeSendRequest(ref this.message, this.channel);
            Assert.AreEqual(1, this.message.Headers.Count);
            foreach (RequestHeader appliedHeader in this.message.Headers)
            {
                Assert.AreEqual("12345", appliedHeader.networkCode);
                Assert.AreEqual(config.GetUserAgent(), appliedHeader.applicationName);
            }
        }
コード例 #6
0
        public void TestEmptyResponseHeader()
        {
            DfpSoapHeaderInspector inspector = new DfpSoapHeaderInspector();

            Assert.DoesNotThrow(() => inspector.AfterReceiveReply(ref this.message, this.channel));
        }