Skip to content

Commit 42e5a1b

Browse files
committed
refactor multiple namespaces to support multiple languages, add Java test data
1 parent 5777b65 commit 42e5a1b

File tree

290 files changed

+20104
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+20104
-19
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace Typewriter.Test
4+
{
5+
[TestClass]
6+
public class CSharpMultipleNamespacesTests
7+
{
8+
[TestMethod]
9+
public void Test()
10+
{
11+
MultipleNamespacesTestRunner.Run(TestLanguage.CSharp);
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace Typewriter.Test
4+
{
5+
[TestClass]
6+
public class JavaMultipleNamespacesTests
7+
{
8+
[TestMethod]
9+
public void Test()
10+
{
11+
MultipleNamespacesTestRunner.Run(TestLanguage.Java);
12+
}
13+
}
14+
}

test/Typewriter.Test/CSharpMultipleNamespacesSupportTests.cs renamed to test/Typewriter.Test/MultipleNamespacesTestRunner.cs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using System;
3+
using System.Collections.Generic;
34
using System.IO;
4-
using System.Text;
55
using System.Linq;
6-
using System.Runtime.InteropServices;
7-
using System.Collections.Generic;
6+
using System.Text;
87

98
namespace Typewriter.Test
109
{
11-
[TestClass]
12-
public class CSharpMultipleNamespaceSupportTests
10+
// supported test languages
11+
public enum TestLanguage
1312
{
14-
private const string OutputDirectoryName = "OutputDirectory";
15-
private const string TestDataCSharpDirectoryName = "TestDataCSharp";
13+
CSharp,
14+
Java
15+
}
16+
17+
public static class MultipleNamespacesTestRunner
18+
{
19+
private const string OutputDirectoryPrefix = "OutputDirectory";
20+
private const string TestDataDirectoryPrefix = "TestData";
1621
private const string MetadataDirectoryName = "Metadata";
1722

18-
[TestMethod]
19-
public void Test()
23+
public static void Run(TestLanguage language)
2024
{
2125
// Arrange
26+
var languageStr = language.ToString();
27+
var outputDirectoryName = OutputDirectoryPrefix + languageStr;
28+
var testDataDirectoryName = TestDataDirectoryPrefix + languageStr;
29+
2230
var currentDirectory = Directory.GetCurrentDirectory();
23-
var outputDirectory = Path.Combine(currentDirectory, OutputDirectoryName);
24-
var dataDirectory = Path.Combine(currentDirectory, TestDataCSharpDirectoryName);
31+
var outputDirectory = Path.Combine(currentDirectory, outputDirectoryName);
32+
var dataDirectory = Path.Combine(currentDirectory, testDataDirectoryName);
2533
var metadataFile = Path.Combine(currentDirectory, MetadataDirectoryName, "MetadataMultipleNamespaces.xml");
26-
var typewriterParameters = $"-v Info -m {metadataFile} -o {outputDirectory} -g Files";
34+
var typewriterParameters = $"-v Info -m {metadataFile} -o {outputDirectory} -g Files -l {languageStr}";
2735

2836
// Act
2937
if (Directory.Exists(outputDirectory))
@@ -36,7 +44,7 @@ public void Test()
3644
// Assert
3745
var testOutputBuilder = new StringBuilder();
3846
var errorCounter = 0;
39-
foreach (var (expectedFilePath, actualOutputFilePath) in GetFilePaths(dataDirectory))
47+
foreach (var (expectedFilePath, actualOutputFilePath) in GetFilePaths(language, dataDirectory, testDataDirectoryName, outputDirectoryName))
4048
{
4149
if (File.Exists(actualOutputFilePath))
4250
{
@@ -56,7 +64,7 @@ public void Test()
5664
dataDirectory,
5765
outputDirectory,
5866
string.Empty,
59-
$"If the changes are expected, please replace the contents of {TestDataCSharpDirectoryName} with the contents of {OutputDirectoryName}.",
67+
$"If the changes are expected, please replace the contents of {testDataDirectoryName} with the contents of {outputDirectoryName}.",
6068
string.Empty,
6169
"Details of failures:");
6270

@@ -90,11 +98,24 @@ private static void CompareFiles(StringBuilder testOutputBuilder, string expecte
9098
/// converts expected file paths into actual output file paths as well for a later diff.
9199
/// </summary>
92100
/// <param name="dataDirectory">Data directory full path</param>
93-
/// <returns>Pairs of expected and actual file paths as an enumerable</returns>
94-
private static IEnumerable<(string, string)> GetFilePaths(string dataDirectory)
101+
/// <param name="testDataDirectoryName">test data directory name, e.g. TestDataCSharp</param>
102+
/// <param name="outputDirectoryName">output directory name, e.g. OutputDirectoryCSharp</param>
103+
/// <returns></returns>
104+
private static IEnumerable<(string, string)> GetFilePaths(TestLanguage language, string dataDirectory, string testDataDirectoryName, string outputDirectoryName)
95105
{
96-
return from file in new DirectoryInfo(dataDirectory).GetFiles("*.cs", SearchOption.AllDirectories)
97-
let actualOutputFilePath = file.FullName.Replace(TestDataCSharpDirectoryName, OutputDirectoryName)
106+
string extension = string.Empty;
107+
switch (language)
108+
{
109+
case TestLanguage.CSharp:
110+
extension = "*.cs";
111+
break;
112+
case TestLanguage.Java:
113+
extension = "*.java";
114+
break;
115+
}
116+
117+
return from file in new DirectoryInfo(dataDirectory).GetFiles(extension, SearchOption.AllDirectories)
118+
let actualOutputFilePath = file.FullName.Replace(testDataDirectoryName, outputDirectoryName)
98119
let expectedFilePath = file.FullName
99120
select (expectedFilePath, actualOutputFilePath);
100121
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
package com.microsoft.graph.models.extensions;
6+
import com.microsoft.graph.concurrency.*;
7+
import com.microsoft.graph.core.*;
8+
import com.microsoft.graph.http.*;
9+
import com.microsoft.graph.serializer.*;
10+
import java.util.Arrays;
11+
import java.util.EnumSet;
12+
import com.microsoft.graph.models.extensions.Entity;
13+
14+
15+
import com.google.gson.JsonObject;
16+
import com.google.gson.JsonElement;
17+
import com.google.gson.annotations.*;
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
21+
// **NOTE** This file was generated by a tool and any changes will be overwritten.
22+
23+
/**
24+
* The class for the Call.
25+
*/
26+
public class Call extends Entity implements IJsonBackedObject {
27+
28+
29+
/**
30+
* The Subject.
31+
*
32+
*/
33+
@SerializedName("subject")
34+
@Expose
35+
public String subject;
36+
37+
38+
/**
39+
* The raw representation of this class
40+
*/
41+
private JsonObject rawObject;
42+
43+
/**
44+
* The serializer
45+
*/
46+
private ISerializer serializer;
47+
48+
/**
49+
* Gets the raw representation of this class
50+
*
51+
* @return the raw representation of this class
52+
*/
53+
public JsonObject getRawObject() {
54+
return rawObject;
55+
}
56+
57+
/**
58+
* Gets serializer
59+
*
60+
* @return the serializer
61+
*/
62+
protected ISerializer getSerializer() {
63+
return serializer;
64+
}
65+
66+
/**
67+
* Sets the raw JSON object
68+
*
69+
* @param serializer the serializer
70+
* @param json the JSON object to set this object to
71+
*/
72+
public void setRawObject(final ISerializer serializer, final JsonObject json) {
73+
this.serializer = serializer;
74+
rawObject = json;
75+
76+
}
77+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
package com.microsoft.graph.models.extensions;
6+
import com.microsoft.graph.concurrency.*;
7+
import com.microsoft.graph.core.*;
8+
import com.microsoft.graph.http.*;
9+
import com.microsoft.graph.serializer.*;
10+
import java.util.Arrays;
11+
import java.util.EnumSet;
12+
import com.microsoft.graph.models.extensions.Call;
13+
import com.microsoft.graph2.callrecords.models.extensions.CallRecord;
14+
import com.microsoft.graph.models.extensions.Entity;
15+
import com.microsoft.graph.requests.extensions.CallCollectionResponse;
16+
import com.microsoft.graph.requests.extensions.CallCollectionPage;
17+
import com.microsoft.graph2.callrecords.requests.extensions.CallRecordCollectionResponse;
18+
import com.microsoft.graph2.callrecords.requests.extensions.CallRecordCollectionPage;
19+
20+
21+
import com.google.gson.JsonObject;
22+
import com.google.gson.JsonElement;
23+
import com.google.gson.annotations.*;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
27+
// **NOTE** This file was generated by a tool and any changes will be overwritten.
28+
29+
/**
30+
* The class for the Cloud Communications.
31+
*/
32+
public class CloudCommunications extends Entity implements IJsonBackedObject {
33+
34+
35+
/**
36+
* The Calls.
37+
*
38+
*/
39+
public CallCollectionPage calls;
40+
41+
/**
42+
* The Call Records.
43+
*
44+
*/
45+
public CallRecordCollectionPage callRecords;
46+
47+
48+
/**
49+
* The raw representation of this class
50+
*/
51+
private JsonObject rawObject;
52+
53+
/**
54+
* The serializer
55+
*/
56+
private ISerializer serializer;
57+
58+
/**
59+
* Gets the raw representation of this class
60+
*
61+
* @return the raw representation of this class
62+
*/
63+
public JsonObject getRawObject() {
64+
return rawObject;
65+
}
66+
67+
/**
68+
* Gets serializer
69+
*
70+
* @return the serializer
71+
*/
72+
protected ISerializer getSerializer() {
73+
return serializer;
74+
}
75+
76+
/**
77+
* Sets the raw JSON object
78+
*
79+
* @param serializer the serializer
80+
* @param json the JSON object to set this object to
81+
*/
82+
public void setRawObject(final ISerializer serializer, final JsonObject json) {
83+
this.serializer = serializer;
84+
rawObject = json;
85+
86+
87+
if (json.has("calls")) {
88+
final CallCollectionResponse response = new CallCollectionResponse();
89+
if (json.has("[email protected]")) {
90+
response.nextLink = json.get("[email protected]").getAsString();
91+
}
92+
93+
final JsonObject[] sourceArray = serializer.deserializeObject(json.get("calls").toString(), JsonObject[].class);
94+
final Call[] array = new Call[sourceArray.length];
95+
for (int i = 0; i < sourceArray.length; i++) {
96+
array[i] = serializer.deserializeObject(sourceArray[i].toString(), Call.class);
97+
array[i].setRawObject(serializer, sourceArray[i]);
98+
}
99+
response.value = Arrays.asList(array);
100+
calls = new CallCollectionPage(response, null);
101+
}
102+
103+
if (json.has("callRecords")) {
104+
final CallRecordCollectionResponse response = new CallRecordCollectionResponse();
105+
if (json.has("[email protected]")) {
106+
response.nextLink = json.get("[email protected]").getAsString();
107+
}
108+
109+
final JsonObject[] sourceArray = serializer.deserializeObject(json.get("callRecords").toString(), JsonObject[].class);
110+
final CallRecord[] array = new CallRecord[sourceArray.length];
111+
for (int i = 0; i < sourceArray.length; i++) {
112+
array[i] = serializer.deserializeObject(sourceArray[i].toString(), CallRecord.class);
113+
array[i].setRawObject(serializer, sourceArray[i]);
114+
}
115+
response.value = Arrays.asList(array);
116+
callRecords = new CallRecordCollectionPage(response, null);
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)