public void TestHeaderUpdatesApplied() { AdsServiceInspectorBehavior behavior = new AdsServiceInspectorBehavior(); AdManagerSoapHeaderInspector inspector = new AdManagerSoapHeaderInspector(); behavior.Add(inspector); AdManagerSoapClient <IMockAdsService> service = new AdManagerSoapClient <IMockAdsService>( new BasicHttpBinding(), new EndpointAddress("https://www.google.com")); #if NET452 service.Endpoint.Behaviors.Add(behavior); #else service.Endpoint.EndpointBehaviors.Add(behavior); #endif 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); }
public void TestApplicationNameRequired() { AdManagerSoapHeaderInspector inspector = new AdManagerSoapHeaderInspector() { Config = new AdManagerAppConfig() }; RequestHeader header = new RequestHeader() { networkCode = "12345" }; inspector.RequestHeader = header; inspector.Config.ApplicationName = null; Assert.Throws(typeof(AdManagerApiException), delegate() { inspector.BeforeSendRequest(ref this.message, this.channel); }, "No exception was thrown for a null application name"); inspector.Config.ApplicationName = AdManagerAppConfig.DEFAULT_APPLICATION_NAME; Assert.Throws(typeof(AdManagerApiException), delegate() { inspector.BeforeSendRequest(ref this.message, this.channel); }, "No exception was thrown for the default application name"); inspector.Config.ApplicationName = ""; Assert.Throws(typeof(AdManagerApiException), delegate() { inspector.BeforeSendRequest(ref this.message, this.channel); }, "No exception was thrown for an empty string application name"); }
public void TestNullHeaderInvalid() { AdManagerSoapHeaderInspector inspector = new AdManagerSoapHeaderInspector() { Config = new AdManagerAppConfig() }; Assert.Throws(typeof(AdManagerApiException), delegate() { inspector.BeforeSendRequest(ref this.message, this.channel); }, "No exception was thrown for a null header"); }
public void TestNullConfigInvalid() { AdManagerSoapHeaderInspector inspector = new AdManagerSoapHeaderInspector() { Config = null, RequestHeader = new RequestHeader() { networkCode = "12345" } }; Assert.Throws(typeof(AdManagerApiException), delegate() { inspector.BeforeSendRequest(ref this.message, this.channel); }, "No exception was thrown for a null Config"); }
public void TestValidHeaderApplied() { AdManagerSoapHeaderInspector inspector = new AdManagerSoapHeaderInspector(); RequestHeader header = new RequestHeader() { networkCode = "12345", }; AdManagerAppConfig config = new AdManagerAppConfig(); 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); } }
public void TestEmptyResponseHeader() { AdManagerSoapHeaderInspector inspector = new AdManagerSoapHeaderInspector(); Assert.DoesNotThrow(() => inspector.AfterReceiveReply(ref this.message, this.channel)); }