Exemplo n.º 1
0
        public void CompileAndVerifyGeneratedCode()
        {
            TestServiceUtil.ServiceUriGenerator = new ServiceUriGenerator();
            foreach (var descriptor in TestServiceDescriptors)
            {
                var serviceWrapper = new DefaultServiceWrapper(descriptor.Value);
                try
                {
                    serviceWrapper.StartService();

                    var edmx = RetrieveServiceModelEdmx(serviceWrapper.ServiceUri);
                    Assert.IsNotNull(edmx);

                    // retrieve the IEdmModel corresponding with the edmx
                    byte[] byteArray = Encoding.UTF8.GetBytes(edmx);
                    var    message   = new StreamResponseMessage(new MemoryStream(byteArray));
                    message.SetHeader("Content-Type", MimeTypes.ApplicationXml);

                    IEdmModel model = null;
                    using (var messageReader = new ODataMessageReader(message))
                    {
                        model = messageReader.ReadMetadataDocument();
                    }

                    foreach (var languageOption in languageOptions)
                    {
                        foreach (var useDataServiceCollection in useDataServiceCollectionBools)
                        {
                            var generatedCode = this.Generate(edmx, descriptor.Key, languageOption, useDataServiceCollection);
                            this.CompileAndVerify(generatedCode, languageOption == ODataT4CodeGenerator.LanguageOption.CSharp, model);
                        }
                    }
                }
                finally
                {
                    serviceWrapper.StopService();
                }
            }
        }
Exemplo n.º 2
0
        public void VerifyGeneratedCodeString()
        {
            TestServiceUtil.ServiceUriGenerator = new ServiceUriGenerator();
            foreach (var descriptor in TestServiceDescriptors.Where(tsd => tsd.Key.StartsWith(NameSpacePrefixReference)))
            {
                var serviceWrapper = new DefaultServiceWrapper(descriptor.Value);
                try
                {
                    serviceWrapper.StartService();
                    var edmx = RetrieveServiceModelEdmx(serviceWrapper.ServiceUri);
                    Assert.IsNotNull(edmx);

                    foreach (var languageOption in languageOptions)
                    {
                        foreach (var useDataServiceCollection in useDataServiceCollectionBools)
                        {
                            var extension = languageOption == ODataT4CodeGenerator.LanguageOption.CSharp ? "cs" : "vb";
                            var path      = languageOption == ODataT4CodeGenerator.LanguageOption.CSharp ? @".\CS" : @".\VB";
                            path += useDataServiceCollection ? "DSCReferences" : "References";
                            path  = Path.Combine(path, descriptor.Key + "." + extension);
                            var expectedCode  = File.ReadAllText(path);
                            var generatedCode = this.Generate(edmx, descriptor.Key, languageOption, useDataServiceCollection);
                            this.VerifyGeneratedCodeString(expectedCode, generatedCode, path);

                            // To generate the updated client layer files, uncomment this, and then copy the resulting files under folder
                            // CSDSCReferences & CSReferences & VBDSCReferences & VBReferences to the reference projects
                            //this.GenerateClientCodeFile(edmx, path, descriptor.Key, languageOption, useDataServiceCollection);
                        }
                    }
                }
                finally
                {
                    serviceWrapper.StopService();
                }
            }
        }