Beispiel #1
0
        public void When_the_path_is_a_Uri_it_requests_metadata_from_the_cloud()
        {
            var metadataPath = Any.UriPath(1);
            var metadata     = Any.String(1);

            using (var mockService = new MockService()
                                     .OnRequest(c => c.Request.Path.ToString() == "/" + metadataPath && c.Request.Method == "GET")
                                     .RespondWith((c, b) => c.Response.Write(metadata)))
            {
                var metadataUri = mockService.GetBaseAddress() + metadataPath;

                MetadataResolver.GetMetadata(metadataUri)
                .Should().Be(metadata);
            }
        }
Beispiel #2
0
        public void When_the_path_is_local_it_gets_metadata_from_the_filesystem()
        {
            var workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var inputFiles       = Any.FileAndContentsDictionary(1);
            var metadataPath     = Path.Combine(workingDirectory, inputFiles.First().Key);
            var metadata         = inputFiles.First().Value;

            try
            {
                WriteAsTextFiles(inputFiles);

                MetadataResolver.GetMetadata(metadataPath)
                .Should().Be(metadata);
            }
            finally
            {
                DeleteFiles(inputFiles);
            }
        }
Beispiel #3
0
        public static void Run(TestLanguage language, bool isBeta = false)
        {
            string getMetadataFile(TestLanguage testLanguage)
            {
                switch (testLanguage)
                {
                case TestLanguage.CSharp:
                case TestLanguage.Java:
                    return(MetadataMultipleNamespacesFile);

                case TestLanguage.TypeScript:
                case TestLanguage.PHP:
                case TestLanguage.ObjC:
                    return(MetadataWithSubNamespacesFile);

                default:
                    throw new ArgumentException("unexpected test language", nameof(testLanguage));
                }
            }

            // Arrange
            var languageStr           = language.ToString();
            var directoryPostfix      = languageStr + (isBeta ? "Beta" : string.Empty);
            var outputDirectoryName   = OutputDirectoryPrefix + directoryPostfix;
            var testDataDirectoryName = TestDataDirectoryPrefix + directoryPostfix;

            var currentDirectory = Path.GetDirectoryName(typeof(MultipleNamespacesTestRunner).Assembly.Location); //Directory.GetCurrentDirectory();
            var outputDirectory  = Path.Combine(currentDirectory, outputDirectoryName);
            var dataDirectory    = Path.Combine(currentDirectory, testDataDirectoryName);
            var metadataFile     = Path.Combine(currentDirectory, MetadataDirectoryName, getMetadataFile(language));

            var csdlContents = MetadataResolver.GetMetadata(metadataFile);
            var options      = new Options
            {
                Verbosity      = VerbosityLevel.Info,
                Output         = outputDirectory,
                GenerationMode = GenerationMode.Files,
                Language       = languageStr
            };

            if (language == TestLanguage.Java)
            {
                options.EndpointVersion = "v1.0"; // fixes java generation test as the endpoint contains the version and the default options are not applied in this testing mode
            }
            if (isBeta)
            {
                if (TestLanguage.PHP == language)
                {
                    options.Properties = new List <string> {
                        "php.namespacePrefix:Beta"
                    };
                }

                if (TestLanguage.TypeScript == language)
                {
                    options.Properties = new List <string> {
                        "typescript.namespacePostfix:beta"
                    };
                }
            }

            // Act
            if (Directory.Exists(outputDirectory))
            {
                Directory.Delete(outputDirectory, recursive: true); // clean up any previous runs
            }

            Generator.GenerateFiles(csdlContents, options);

            // Assert
            var testOutputBuilder = new StringBuilder();
            var errorCounter      = 0;

            foreach (var(expectedFilePath, actualOutputFilePath) in GetFilePaths(language, dataDirectory, testDataDirectoryName, outputDirectoryName))
            {
                if (File.Exists(actualOutputFilePath))
                {
                    CompareFiles(testOutputBuilder, expectedFilePath, actualOutputFilePath, ref errorCounter);
                }
                else
                {
                    testOutputBuilder.AppendLine();
                    testOutputBuilder.AppendLine($"{++errorCounter}. Output file is not generated: {actualOutputFilePath}");
                }
            }

            if (errorCounter > 0)
            {
                string message = string.Join(Environment.NewLine,
                                             "A diff between following folders are strongly encouraged to see if the changes are intended:",
                                             dataDirectory,
                                             outputDirectory,
                                             string.Empty,
                                             $"If the changes are expected, please replace the contents of {testDataDirectoryName} with the contents of {outputDirectoryName}.",
                                             string.Empty,
                                             "Details of failures:");

                Assert.Fail(message + testOutputBuilder.ToString());
            }
        }