コード例 #1
0
    public static void WrapperNamespace_Property_Sets(string wrapperNamespace)
    {
        MessageContractAttribute messageCA = new MessageContractAttribute();

        messageCA.WrapperNamespace = wrapperNamespace;
        Assert.Equal(wrapperNamespace, messageCA.WrapperNamespace);
    }
コード例 #2
0
    public static void IsWrapped_Property_Sets(bool isWrapped)
    {
        MessageContractAttribute messageCA = new MessageContractAttribute();

        messageCA.IsWrapped = isWrapped;
        Assert.Equal(isWrapped, messageCA.IsWrapped);
    }
コード例 #3
0
		public void ShouldGenerateCorrectElementNameInMessageContract()
		{
			ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");
			XsdMessage rootElement = CreateRoot<XsdMessage>(MessageContractElementName, MessageContractElementNamespace);
			rootElement.IsWrapped = true;
			rootElement.Element = "xsd:\\file.xsd?MyType";
			rootElement.ServiceContractModel.ProjectMappingTable = "WCF";
			rootElement.ServiceContractModel.SerializerType = SerializerType.DataContractSerializer;

			string content = RunTemplate(rootElement);
			
			EnsureType(ref content, "MyType");
			Type generatedType = CompileAndGetType(content);
			Assert.AreEqual<string>(MessageContractElementName, generatedType.Name);
			Assert.AreEqual<string>(DefaultNamespace, generatedType.Namespace);
			Assert.AreEqual<int>(2, generatedType.GetConstructors().Length);
			MessageContractAttribute messageContract = TypeAsserter.AssertAttribute<MessageContractAttribute>(generatedType);
			Assert.AreEqual<string>(MessageContractElementName, messageContract.WrapperName);
			Assert.IsNotNull(messageContract.WrapperNamespace);
			Assert.IsTrue(messageContract.IsWrapped);
			PropertyInfo property = generatedType.GetProperty("MyType");
			Assert.IsNotNull(property);
			MessageBodyMemberAttribute bodyAttr = TypeAsserter.AssertAttribute<MessageBodyMemberAttribute>(property);
			Assert.AreEqual<string>(messageContract.WrapperNamespace, bodyAttr.Namespace);
			Assert.AreEqual<int>(0, bodyAttr.Order);
		}
コード例 #4
0
    public static void Default_Ctor_Initializes_Properties()
    {
        // Verify new MessageContractAttribute() initializes correct defaults.
        MessageContractAttribute messageCA = new MessageContractAttribute();

        Assert.True(messageCA.IsWrapped);

        // Assert.True for more informative message
        Assert.True(messageCA.WrapperName == null, "WrapperName should be null");
        Assert.True(messageCA.WrapperNamespace == null, "WrapperNamespace should be null");
    }
コード例 #5
0
		public void ShouldNotGenerateWithUnwrappedMessage()
		{
			ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");
			XsdMessage rootElement = CreateRoot<XsdMessage>(MessageContractElementName, MessageContractElementNamespace);
			rootElement.IsWrapped = false;
			rootElement.Element = "xsd:\\file.xsd?MyType";
			rootElement.ServiceContractModel.ProjectMappingTable = "WCF";
			rootElement.ServiceContractModel.SerializerType = SerializerType.DataContractSerializer;

			string content = RunTemplate(rootElement);

			EnsureType(ref content, "MyType");
			Type generatedType = CompileAndGetType(content);
			MessageContractAttribute messageContract = TypeAsserter.AssertAttribute<MessageContractAttribute>(generatedType);
			Assert.IsFalse(messageContract.IsWrapped);
		}
コード例 #6
0
        static MessageDescriptionCollection MessageContractToMessagesDescription(
            Type src, string defaultNamespace, string action)
        {
            MessageContractAttribute mca =
                ContractDescriptionGenerator.GetMessageContractAttribute(src);

            if (mca == null)
            {
                throw new ArgumentException(String.Format("Type {0} and its ancestor types do not have MessageContract attribute.", src));
            }

            MessageDescriptionCollection messages = new MessageDescriptionCollection();

            messages.Add(ContractDescriptionGenerator.CreateMessageDescription(src, defaultNamespace, action, true, mca));
            messages.Add(ContractDescriptionGenerator.CreateMessageDescription(src, defaultNamespace, action, false, mca));
            return(messages);
        }
コード例 #7
0
        private static MessageContractAttribute ConvertFromServiceModelMessageContractAttribute(object attr)
        {
            Fx.Assert(attr.GetType().FullName.Equals(ServiceReflector.SMMessageContractAttributeFullName), "Expected attribute of type System.ServiceModel.MessageContract");
            var messageContract = new MessageContractAttribute();

            messageContract.IsWrapped = GetProperty <bool>(attr, nameof(MessageContractAttribute.IsWrapped));
            string tmpStr = GetProperty <string>(attr, nameof(MessageContractAttribute.WrapperName));

            if (!string.IsNullOrEmpty(tmpStr))
            {
                messageContract.WrapperName = tmpStr;
            }
            tmpStr = GetProperty <string>(attr, nameof(MessageContractAttribute.WrapperNamespace));
            if (!string.IsNullOrEmpty(tmpStr))
            {
                messageContract.WrapperNamespace = tmpStr;
            }
            return(messageContract);
        }
コード例 #8
0
        public void ShouldGenerateCorrectElementNameInMessageContract()
        {
            ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml");
            Message rootElement = CreateRoot <Message>(MessageContractElementName, MessageContractElementNamespace);

            rootElement.ServiceContractModel.ProjectMappingTable = "WCF";

            string content = RunTemplate(rootElement);

            Type generatedType = CompileAndGetType(content);
            MessageContractAttribute messageContract = TypeAsserter.AssertAttribute <MessageContractAttribute>(generatedType);

            Assert.AreEqual <string>(MessageContractElementName, generatedType.Name);
            Assert.AreEqual <string>(DefaultNamespace, generatedType.Namespace);
            Assert.IsFalse(messageContract.HasProtectionLevel);
            Assert.IsNull(messageContract.WrapperName);
            Assert.IsNull(messageContract.WrapperNamespace);
            Assert.IsFalse(messageContract.IsWrapped);
        }
コード例 #9
0
        public static MessageDescription CreateMessageDescription(
            Type messageType, string defaultNamespace, string action, bool isRequest, MessageContractAttribute mca)
        {
            MessageDescription md = new MessageDescription(
                action, isRequest ? MessageDirection.Input :
                MessageDirection.Output);

            md.MessageType = MessageFilterOutByRef(messageType);
            if (mca.HasProtectionLevel)
            {
                md.ProtectionLevel = mca.ProtectionLevel;
            }

            MessageBodyDescription mb = md.Body;

            if (mca.IsWrapped)
            {
                mb.WrapperName      = mca.WrapperName ?? messageType.Name;
                mb.WrapperNamespace = mca.WrapperNamespace ?? defaultNamespace;
            }

            int index = 0;

            foreach (MemberInfo bmi in messageType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                Type   mtype = null;
                string mname = null;
                if (bmi is FieldInfo)
                {
                    FieldInfo fi = (FieldInfo)bmi;
                    mtype = fi.FieldType;
                    mname = fi.Name;
                }
                else if (bmi is PropertyInfo)
                {
                    PropertyInfo pi = (PropertyInfo)bmi;
                    mtype = pi.PropertyType;
                    mname = pi.Name;
                }
                else
                {
                    continue;
                }

                MessageBodyMemberAttribute mba = GetMessageBodyMemberAttribute(bmi);
                if (mba == null)
                {
                    continue;
                }

                MessagePartDescription pd = CreatePartCore(mba, mname, defaultNamespace);
                pd.Index      = index++;
                pd.Type       = MessageFilterOutByRef(mtype);
                pd.MemberInfo = bmi;
                mb.Parts.Add(pd);
            }

            // FIXME: fill headers and properties.
            return(md);
        }
コード例 #10
0
    public static void WrapperName_Property_Sets_Throws_ArgumentNull(string wrapperName)
    {
        MessageContractAttribute messageCA = new MessageContractAttribute();

        Assert.Throws <ArgumentNullException>(() => messageCA.WrapperName = wrapperName);
    }
コード例 #11
0
        public static MessageDescription CreateMessageDescription(
            Type messageType, string defaultNamespace, string action, bool isRequest, bool isCallback, MessageContractAttribute mca)
        {
            MessageDescription md = new MessageDescription(action, isRequest ^ isCallback ? MessageDirection.Input : MessageDirection.Output)
            {
                IsRequest = isRequest
            };

            md.MessageType = MessageFilterOutByRef(messageType);
            if (mca.HasProtectionLevel)
            {
                md.ProtectionLevel = mca.ProtectionLevel;
            }

            MessageBodyDescription mb = md.Body;

            if (mca.IsWrapped)
            {
                mb.WrapperName      = mca.WrapperName ?? messageType.Name;
                mb.WrapperNamespace = mca.WrapperNamespace ?? defaultNamespace;
            }

            int index = 0;

            foreach (MemberInfo bmi in messageType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                Type   mtype = null;
                string mname = null;
                if (bmi is FieldInfo)
                {
                    FieldInfo fi = (FieldInfo)bmi;
                    mtype = fi.FieldType;
                    mname = fi.Name;
                }
                else if (bmi is PropertyInfo)
                {
                    PropertyInfo pi = (PropertyInfo)bmi;
                    mtype = pi.PropertyType;
                    mname = pi.Name;
                }
                else
                {
                    continue;
                }

                var mha = bmi.GetCustomAttribute <MessageHeaderAttribute> (false);
                if (mha != null)
                {
                    var pd = CreateHeaderDescription(mha, mname, defaultNamespace);
                    pd.Type       = MessageFilterOutByRef(mtype);
                    pd.MemberInfo = bmi;
                    md.Headers.Add(pd);
                }
                var mpa = bmi.GetCustomAttribute <MessagePropertyAttribute> (false);
                if (mpa != null)
                {
                    var pd = new MessagePropertyDescription(mpa.Name ?? mname);
                    pd.Type       = MessageFilterOutByRef(mtype);
                    pd.MemberInfo = bmi;
                    md.Properties.Add(pd);
                }
                var mba = GetMessageBodyMemberAttribute(bmi);
                if (mba != null)
                {
                    var pd = CreatePartCore(mba, mname, defaultNamespace);
                    if (pd.Index <= 0)
                    {
                        pd.Index = index++;
                    }
                    pd.Type       = MessageFilterOutByRef(mtype);
                    pd.MemberInfo = bmi;
                    mb.Parts.Add(pd);
                }
            }

            return(md);
        }
コード例 #12
0
        private void FindErrorsForMessage(Dictionary <int, Type> validated, Type message, MessageContractAttribute a)
        {
            if (!a.GetClassType().IsAssignableFrom(message))
            {
                _errors.Add(message, $"[Type Error]:  The type used as an argument to the EngineMessageContract " +
                            $"for the message {message} is not valid. The type {a.GetClassType()} is " +
                            $"not an instance of {message}");
            }
            else if (validated.TryGetValue(a.GetId(), out var current))
            {
                _errors.Add(message, $"[Code Error]:  The message {message} has a message code " +
                            $"of {a.GetInputId()} but that code is already in use by {current}");
            }
            else
            {
                validated.Add(a.GetId(), a.GetClassType());

                if (a.GetType() == typeof(EngineMessageContractAttribute))
                {
                    HighestCodeFound = System.Math.Max(HighestCodeFound, a.GetInputId());
                }
            }
        }