Skip to content

Commit ff37121

Browse files
committed
fix test runs in the same process
1 parent 5ddf256 commit ff37121

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/GraphODataTemplateWriter/CodeHelpers/PHP/TypeHelperPHP.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static string GetPHPNamespace(OdcmType currentType, TemplateWriterSetting
203203
var namespacePrefix = string.Empty;
204204
// TemplateWriterSettings.Properties are set at the Typewriter command line. Check the command line
205205
// documentation for more information on how the TemplateWriterSettings.Properties is used.
206-
if (settings.Properties.ContainsKey("php.namespacePrefix"))
206+
if (settings.Properties?.ContainsKey("php.namespacePrefix") == true)
207207
{
208208
namespacePrefix = settings.Properties["php.namespacePrefix"];
209209
}
@@ -262,7 +262,7 @@ public static string GetPHPEntityTypeReference(string @namespace, TemplateWriter
262262
case "Beta\\Microsoft\\Graph\\Model":
263263
return "Entity";
264264
default:
265-
if (settings.Properties.ContainsKey("php.namespacePrefix"))
265+
if (settings.Properties?.ContainsKey("php.namespacePrefix") == true)
266266
{
267267
return $"\\{settings.Properties["php.namespacePrefix"]}\\Microsoft\\Graph\\Model\\Entity";
268268
}

src/GraphODataTemplateWriter/PathWriters/PHPPathWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private string CreateNamespace(string @namespace, string folderName)
4646

4747
// TemplateWriterSettings.Properties are set at the Typewriter command line. Check the command line
4848
// documentation for more information on how the TemplateWriterSettings.Properties is used.
49-
if (ConfigurationService.Settings.Properties.ContainsKey("php.namespacePrefix"))
49+
if (ConfigurationService.Settings.Properties?.ContainsKey("php.namespacePrefix") == true)
5050
{
5151
namespaceBuilder.Append($"{ConfigurationService.Settings.Properties["php.namespacePrefix"]}."); // e.g. "com.Beta."
5252
}

src/GraphODataTemplateWriter/Settings/ConfigurationService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Microsoft.Graph.ODataTemplateWriter.Settings
44
{
55
using System;
66
using System.Collections.Generic;
7+
using System.Linq;
78
using System.Reflection;
89
using System.Reflection.Emit;
910
using Vipr.Core;
@@ -105,7 +106,13 @@ public static TemplateWriterSettings Settings
105106
{
106107
get
107108
{
108-
if (templateWriterSettings == null || templateWriterSettings.TargetLanguage != ConfigurationService.targetLanguage)
109+
// settings are considered new if
110+
// 1. templateWriterSettings are not initialized
111+
// 2. targetLanguage or properties are different between templateWriterSettings and ConfigurationService
112+
if (templateWriterSettings == null
113+
|| templateWriterSettings.TargetLanguage != ConfigurationService.targetLanguage
114+
|| (templateWriterSettings.Properties == null ^ ConfigurationService.properties == null) // when only one of them is null, they are different
115+
|| (templateWriterSettings.Properties != null && templateWriterSettings.Properties.SequenceEqual(ConfigurationService.properties)))
109116
{
110117
templateWriterSettings = _configurationProvider != null
111118
? LoadSettingsForLanguage()

test/Typewriter.Test/MultipleNamespacesTestRunner.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ string getMetadataFile(TestLanguage testLanguage)
6262
var outputDirectory = Path.Combine(currentDirectory, outputDirectoryName);
6363
var dataDirectory = Path.Combine(currentDirectory, testDataDirectoryName);
6464
var metadataFile = Path.Combine(currentDirectory, MetadataDirectoryName, getMetadataFile(language));
65-
var typewriterParameters = $"-v Info -m {metadataFile} -o {outputDirectory} -g Files -l {languageStr}";
65+
66+
var csdlContents = MetadataResolver.GetMetadata(metadataFile);
67+
var options = new Options
68+
{
69+
Verbosity = VerbosityLevel.Info,
70+
Output = outputDirectory,
71+
GenerationMode = GenerationMode.Files,
72+
Language = languageStr
73+
};
6674

6775
if (isPhpBeta)
6876
{
69-
typewriterParameters += " -p php.namespacePrefix:Beta";
77+
options.Properties = new List<string> { "php.namespacePrefix:Beta" };
7078
}
7179

7280
// Act
@@ -75,7 +83,7 @@ string getMetadataFile(TestLanguage testLanguage)
7583
Directory.Delete(outputDirectory, recursive: true); // clean up any previous runs
7684
}
7785

78-
Program.Main(typewriterParameters.Split(' '));
86+
Generator.GenerateFiles(csdlContents, options);
7987

8088
// Assert
8189
var testOutputBuilder = new StringBuilder();

0 commit comments

Comments
 (0)