public void ThrowOnBehaviorThatNotExistsTest() { NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> element = LoadManager().GetBehavior("NewBehavior"); Assert.IsNotNull(element); Assert.AreEqual("NewBehavior", element.Name); }
/// <summary> /// Updates the behavior. /// </summary> /// <param name="behavior">The behavior.</param> public void UpdateBehavior(NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> behavior) { if (behavior is ServiceBehaviorElement) { if (this.serviceModelSectionGroup.Behaviors.ServiceBehaviors.ContainsKey(behavior.Name)) { this.serviceModelSectionGroup.Behaviors.ServiceBehaviors[behavior.Name] = (ServiceBehaviorElement)behavior; } else { this.serviceModelSectionGroup.Behaviors.ServiceBehaviors.Add((ServiceBehaviorElement)behavior); } } else if (behavior is EndpointBehaviorElement) { if (this.serviceModelSectionGroup.Behaviors.EndpointBehaviors.ContainsKey(behavior.Name)) { this.serviceModelSectionGroup.Behaviors.EndpointBehaviors[behavior.Name] = (EndpointBehaviorElement)behavior; } else { this.serviceModelSectionGroup.Behaviors.EndpointBehaviors.Add((EndpointBehaviorElement)behavior); } } }
public void GetBehaviorTest() { NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> element = LoadManager().GetBehavior(Constants.ServiceBehaviorName); Assert.IsNotNull(element); Assert.AreEqual(Constants.ServiceBehaviorName, element.Name); }
public void GetBehaviorExtensionTest() { NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> element = LoadManager().GetBehavior(Constants.ServiceBehaviorExtension); ServiceCredentialsElement extension = ServiceModelConfigurationManager.GetBehaviorExtensionElement <ServiceCredentialsElement>(element); Assert.IsNotNull(extension); Assert.AreEqual(Constants.TestCert, extension.ServiceCertificate.FindValue); }
public void ClientBehaviorTest() { ServiceModelConfigurationManager manager = LoadManager(); ClientSection client = manager.GetClient(); NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> behavior = manager.GetBehavior(client.Endpoints[0].BehaviorConfiguration); ClientCredentialsElement credentialsSection = ServiceModelConfigurationManager.GetBehaviorExtensionElement <ClientCredentialsElement>(behavior); Assert.AreEqual(Constants.TestCert, credentialsSection.ClientCertificate.FindValue); Assert.AreEqual(System.ServiceModel.Security.X509CertificateValidationMode.ChainTrust, credentialsSection.ServiceCertificate.Authentication.CertificateValidationMode); }
/// <summary> /// Gets the behavior extension element. /// </summary> /// <param name="behavior">The behavior.</param> /// <returns></returns> public static T GetBehaviorExtensionElement <T>(NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> behavior) where T : BehaviorExtensionElement, new() { T behaviorExtensionElement = behavior[typeof(T)] as T; if (behaviorExtensionElement == null) { behaviorExtensionElement = new T(); } return(behaviorExtensionElement); }
public void UpdateBehaviorExtensionTest() { NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> element = LoadManager().GetBehavior(Constants.ServiceBehaviorName); ServiceCredentialsElement extension = new ServiceCredentialsElement(); extension.UserNameAuthentication.MembershipProviderName = Constants.MembershipProviderName; ServiceCredentialsElement updatedExtension = ServiceModelConfigurationManager.GetBehaviorExtensionElement <ServiceCredentialsElement>(element); Assert.IsNotNull(updatedExtension); Assert.AreEqual(updatedExtension.BehaviorType, extension.BehaviorType); Assert.AreEqual(Constants.MembershipProviderName, updatedExtension.UserNameAuthentication.MembershipProviderName); }
/// <summary> /// Updates the behavior extension section. /// </summary> /// <param name="behavior">The behavior.</param> /// <param name="behaviorExtensionSection">The behavior extension section.</param> public static void UpdateBehaviorExtensionSection <T>(NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> behavior, T behaviorExtensionElement) where T : BehaviorExtensionElement { T existingBehaviorExtensionElement = behavior[typeof(T)] as T; if (existingBehaviorExtensionElement != null) { behavior.Remove(existingBehaviorExtensionElement); } behavior.Add(behaviorExtensionElement); }
/// <summary> /// Gets the service model extension element. /// </summary> /// <param name="collection">The collection.</param> /// <param name="extensionType">Type of the extension.</param> /// <returns></returns> public ServiceModelExtensionElement GetServiceModelExtensionElement( NamedServiceModelExtensionCollectionElement <ServiceModelExtensionElement> collection, Type extensionType) { return(collection[extensionType]); }