public void ShouldGenerateKnownTypeAttributeWithXsdExtendedTypes() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); rootElement.ServiceContractModel.ImplementationTechnology = new ServiceContractWCFExtensionProvider(); rootElement.ServiceContractModel.SerializerType = Microsoft.Practices.ServiceFactory.ServiceContracts.SerializerType.DataContractSerializer; Operation op1 = new Operation(Store); op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; XsdMessage request = new XsdMessage(Store); request.Name = "Request1"; request.Element = @"xsd://SampleData/BaseTypes.xsd?LandmarkPoint"; request.ServiceContractModel = rootElement.ServiceContractModel; WCFXsdMessageContract wcfXsdMc = new WCFXsdMessageContract(); wcfXsdMc.ModelElement = request; request.ObjectExtender = wcfXsdMc; op1.Request = request; string content = RunTemplate(rootElement); EnsureType(ref content, "Request1"); EnsureType(ref content, "LandmarkBase"); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); ServiceKnownTypeAttribute attribute = TypeAsserter.AssertAttribute <ServiceKnownTypeAttribute>(method); Assert.AreEqual <string>("LandmarkBase", attribute.Type.Name); }
public void TestSoapDocumentMethodAttributeParanmeters() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); rootElement.ServiceContractModel.ImplementationTechnology = new ServiceContractAsmxExtensionProvider(); rootElement.ServiceContractModel.SerializerType = SerializerType.XmlSerializer; Operation op1 = new Operation(Store); op1.ObjectExtender = new AsmxOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; string content = RunTemplate(rootElement); EnsureType(ref content, "MyType"); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); SoapDocumentMethodAttribute soapAttr = TypeAsserter.AssertAttribute <SoapDocumentMethodAttribute>(method); Assert.AreEqual(soapAttr.ParameterStyle, SoapParameterStyle.Wrapped); Assert.AreEqual <string>(soapAttr.Action, rootElement.Namespace + "/" + op1.Action); }
public void TestRequestGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; Message request = new Message(Store); request.Name = "Request1"; op1.Request = request; string content = RunTemplate(rootElement); EnsureType(ref content, "Request1"); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); Assert.AreEqual <int>(1, method.GetParameters().Length); Assert.AreEqual <string>("Request1", ((ParameterInfo)method.GetParameters().GetValue(0)).ParameterType.Name); Assert.AreEqual <string>("Void", method.ReturnType.Name); }
public void TestAsyncOperationGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); WCFOperationContract wfcOperationContract = new WCFOperationContract(); wfcOperationContract.AsyncPattern = true; op1.ObjectExtender = wfcOperationContract; op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); MethodInfo beginMethod = TypeAsserter.AssertMethod("Begin" + op1.Name, generatedType); Assert.AreEqual <int>(2, beginMethod.GetParameters().Length); Assert.AreEqual <string>("IAsyncResult", beginMethod.ReturnType.Name); MethodInfo endMethod = TypeAsserter.AssertMethod("End" + op1.Name, generatedType); Assert.AreEqual <int>(1, endMethod.GetParameters().Length); Assert.AreEqual <string>("Void", endMethod.ReturnType.Name); }
public void ShouldGetActionValueWithDefaultUriSlashEnded() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace + "/"); Operation op1 = new Operation(Store); op1.ServiceContract = rootElement; op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; // commit the tx and trigger the OperationAddRule so the action value will be filled with the default value this.transaction.Commit(); this.transaction = Store.TransactionManager.BeginTransaction(); op1.Name = "op2"; this.transaction.Commit(); this.transaction = null; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); OperationContractAttribute operation = TypeAsserter.AssertAttribute <OperationContractAttribute>(method); Assert.AreEqual <string>(rootElement.Namespace + rootElement.Name + "/op2", operation.Action); }
public void TestOperationGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); Assert.AreEqual <int>(0, method.GetParameters().Length); Assert.AreEqual <string>("Void", method.ReturnType.Name); OperationContractAttribute operation = TypeAsserter.AssertAttribute <OperationContractAttribute>(method); Assert.AreEqual <string>(op1.Action, operation.Action); Assert.IsNull(operation.Name); Assert.AreEqual <bool>(op1.IsOneWay, operation.IsOneWay); Assert.AreEqual <bool>(((WCFOperationContract)op1.ObjectExtender).IsTerminating, operation.IsTerminating); Assert.AreEqual <bool>(((WCFOperationContract)op1.ObjectExtender).IsInitiating, operation.IsInitiating); Assert.AreEqual <ProtectionLevel>(((WCFOperationContract)op1.ObjectExtender).ProtectionLevel, operation.ProtectionLevel); Assert.IsNull(operation.ReplyAction); Assert.IsTrue(operation.HasProtectionLevel); }
public void TestReplyActionGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); WCFOperationContract oc = new WCFOperationContract(); oc.ReplyAction = "foo"; op1.ObjectExtender = oc; op1.Name = "op1"; op1.ServiceContract = rootElement; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); OperationContractAttribute operation = TypeAsserter.AssertAttribute <OperationContractAttribute>(method); Assert.AreEqual <string>(oc.ReplyAction, operation.ReplyAction); }
public void TestOperationWithoutResponse() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); Service rootElement = CreateDefaultService(); rootElement.ServiceContract = CreateServiceContract(rootElement.ServiceContractModel, ServiceContractName, OperationName, RequestName, null); string content = RunTemplate(rootElement); EnsureType(ref content, ServiceContractInterfaceName); EnsureType(ref content, RequestName); string implementationContent = this.GetImplementationContent(ImplementationKind.Request); Type generatedType = CompileAndGetType(content + implementationContent); TypeAsserter.AssertInterface(GetFullServiceContractInterfaceName(), generatedType); MethodInfo method = TypeAsserter.AssertMethod(OperationName, generatedType); Assert.AreEqual <string>(RequestName, ((ParameterInfo)method.GetParameters().GetValue(0)).ParameterType.Name); Assert.AreEqual <string>("Void", method.ReturnType.Name); }
public void TestXsdMessageUnwrappedRequestGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); rootElement.ServiceContractModel.ImplementationTechnology = new ServiceContractAsmxExtensionProvider(); rootElement.ServiceContractModel.SerializerType = SerializerType.XmlSerializer; Operation op1 = new Operation(Store); op1.ObjectExtender = new AsmxOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; XsdMessage request = new XsdMessage(Store); request.Name = "Request1"; request.Element = @"xsd://schemas\file.xsd?MyType"; request.IsWrapped = false; request.ServiceContractModel = rootElement.ServiceContractModel; AsmxXsdMessageContract wcfXsdMc = new AsmxXsdMessageContract(); wcfXsdMc.ModelElement = request; request.ObjectExtender = wcfXsdMc; op1.Request = request; string content = RunTemplate(rootElement); EnsureType(ref content, "MyType"); Type generatedType = CompileAndGetType(content); MethodInfo method = TypeAsserter.AssertMethod(op1.Name, generatedType); Assert.AreEqual <int>(1, method.GetParameters().Length); Assert.AreEqual <string>("MyType", ((ParameterInfo)method.GetParameters().GetValue(0)).ParameterType.Name); Assert.AreEqual <string>("Void", method.ReturnType.Name); }
public void TestMultipleOperationsGeneration() { ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.ServiceContractDsl.Tests.xml"); ServiceContract rootElement = CreateRoot(ServiceContractElementName, ServiceContractElementNamespace); Operation op1 = new Operation(Store); op1.ObjectExtender = new WCFOperationContract(); op1.Name = "op1"; op1.Action = "op1"; op1.ServiceContract = rootElement; Operation op2 = new Operation(Store); op2.ObjectExtender = new WCFOperationContract(); op2.Name = "op2"; op2.Action = "op2"; op2.ServiceContract = rootElement; string content = RunTemplate(rootElement); Type generatedType = CompileAndGetType(content); TypeAsserter.AssertMethod(op1.Name, generatedType); TypeAsserter.AssertMethod(op2.Name, generatedType); }