Skip to content

Commit ed366be

Browse files
committed
embed resource
1 parent ffaf284 commit ed366be

File tree

3 files changed

+40
-145
lines changed

3 files changed

+40
-145
lines changed

sdk/test/Services/S3/UnitTests/AWSSDK.UnitTests.S3.NetFramework.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,9 @@
7575
<Reference Include="System.Configuration"/>
7676
</ItemGroup>
7777

78+
<ItemGroup>
79+
<EmbeddedResource Include="Custom/TestData/mapping.json" />
80+
<EmbeddedResource Include="Custom/TestData/property-aliases.json" />
81+
</ItemGroup>
7882

79-
</Project>
83+
</Project>

sdk/test/Services/S3/UnitTests/Custom/ResponseMapperTests.cs

Lines changed: 26 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -39,168 +39,51 @@ public class ResponseMapperTests
3939
[ClassInitialize]
4040
public static void ClassInitialize(TestContext context)
4141
{
42-
// DEBUG: Log initial setup information
43-
Console.WriteLine("=== DEBUG: ResponseMapperTests ClassInitialize ===");
44-
Console.WriteLine($"Current Working Directory: {Directory.GetCurrentDirectory()}");
42+
// Load mapping.json from embedded resource
43+
var assembly = Assembly.GetExecutingAssembly();
44+
var assemblyName = assembly.GetName().Name;
4545

46-
// Get the test assembly directory and navigate to the source directory
47-
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
48-
Console.WriteLine($"Assembly Location: {assemblyLocation}");
46+
// Build resource names dynamically based on current assembly
47+
var mappingResourceName = $"{assemblyName}.Custom.TestData.mapping.json";
48+
var aliasesResourceName = $"{assemblyName}.Custom.TestData.property-aliases.json";
4949

50-
var testProjectDirectory = Path.GetDirectoryName(assemblyLocation);
51-
Console.WriteLine($"Initial Test Project Directory: {testProjectDirectory}");
52-
53-
// DEBUG: Log directory contents at starting point
54-
if (testProjectDirectory != null && Directory.Exists(testProjectDirectory))
50+
// Read mapping.json
51+
using (var stream = assembly.GetManifestResourceStream(mappingResourceName))
5552
{
56-
Console.WriteLine($"Contents of starting directory '{testProjectDirectory}':");
57-
try
58-
{
59-
var files = Directory.GetFiles(testProjectDirectory);
60-
var dirs = Directory.GetDirectories(testProjectDirectory);
61-
Console.WriteLine($" Files: {string.Join(", ", files.Select(Path.GetFileName))}");
62-
Console.WriteLine($" Directories: {string.Join(", ", dirs.Select(Path.GetFileName))}");
63-
}
64-
catch (Exception ex)
53+
if (stream == null)
54+
throw new FileNotFoundException($"Could not find embedded resource: {mappingResourceName}");
55+
56+
using (var reader = new StreamReader(stream))
6557
{
66-
Console.WriteLine($" Error reading directory: {ex.Message}");
58+
var jsonContent = reader.ReadToEnd();
59+
_mappingJson = JsonDocument.Parse(jsonContent);
6760
}
6861
}
6962

70-
// Navigate up from bin/Debug/net472 to the test project root
71-
int searchDepth = 0;
72-
const int maxSearchDepth = 10; // Prevent infinite loops
73-
74-
while (testProjectDirectory != null && searchDepth < maxSearchDepth)
63+
// Read property-aliases.json
64+
using (var stream = assembly.GetManifestResourceStream(aliasesResourceName))
7565
{
76-
var targetPath = Path.Combine(testProjectDirectory, "Custom", "TestData", "mapping.json");
77-
Console.WriteLine($"Search attempt {searchDepth + 1}: Checking for file at '{targetPath}'");
78-
Console.WriteLine($" Directory exists: {Directory.Exists(testProjectDirectory)}");
79-
Console.WriteLine($" File exists: {File.Exists(targetPath)}");
80-
81-
// DEBUG: Log what's in the current directory
82-
if (Directory.Exists(testProjectDirectory))
66+
if (stream != null)
8367
{
84-
try
68+
using (var reader = new StreamReader(stream))
8569
{
86-
var subdirs = Directory.GetDirectories(testProjectDirectory);
87-
Console.WriteLine($" Subdirectories: {string.Join(", ", subdirs.Select(Path.GetFileName))}");
70+
var aliasContent = reader.ReadToEnd();
71+
_propertyAliasesJson = JsonDocument.Parse(aliasContent);
8872

89-
// Check if Custom directory exists
90-
var customDir = Path.Combine(testProjectDirectory, "Custom");
91-
if (Directory.Exists(customDir))
92-
{
93-
Console.WriteLine($" Custom directory found at: {customDir}");
94-
var customSubdirs = Directory.GetDirectories(customDir);
95-
Console.WriteLine($" Custom subdirectories: {string.Join(", ", customSubdirs.Select(Path.GetFileName))}");
96-
97-
// Check if TestData directory exists
98-
var testDataDir = Path.Combine(customDir, "TestData");
99-
if (Directory.Exists(testDataDir))
100-
{
101-
Console.WriteLine($" TestData directory found at: {testDataDir}");
102-
var testDataFiles = Directory.GetFiles(testDataDir);
103-
Console.WriteLine($" TestData files: {string.Join(", ", testDataFiles.Select(Path.GetFileName))}");
104-
}
105-
else
106-
{
107-
Console.WriteLine($" TestData directory NOT found at: {testDataDir}");
108-
}
109-
}
110-
else
73+
// Convert to dictionary for fast lookup
74+
_propertyAliases = new Dictionary<string, string>();
75+
var aliasesElement = _propertyAliasesJson.RootElement.GetProperty("PropertyAliases");
76+
foreach (var alias in aliasesElement.EnumerateObject())
11177
{
112-
Console.WriteLine($" Custom directory NOT found at: {customDir}");
78+
_propertyAliases[alias.Name] = alias.Value.GetString();
11379
}
11480
}
115-
catch (Exception ex)
116-
{
117-
Console.WriteLine($" Error examining directory: {ex.Message}");
118-
}
11981
}
120-
121-
if (File.Exists(targetPath))
122-
{
123-
Console.WriteLine($"SUCCESS: Found mapping.json at '{targetPath}'");
124-
break;
125-
}
126-
127-
var parentDir = Directory.GetParent(testProjectDirectory);
128-
testProjectDirectory = parentDir?.FullName;
129-
Console.WriteLine($" Moving up to parent: {testProjectDirectory ?? "null"}");
130-
searchDepth++;
131-
}
132-
133-
if (testProjectDirectory == null)
134-
{
135-
Console.WriteLine("ERROR: Exhausted directory search - testProjectDirectory is null");
136-
Console.WriteLine($"Searched {searchDepth} levels up from assembly location: {assemblyLocation}");
137-
throw new FileNotFoundException(
138-
$"Could not locate mapping.json file in test project directory structure. " +
139-
$"Started from: {assemblyLocation}, searched {searchDepth} levels up.");
140-
}
141-
142-
if (searchDepth >= maxSearchDepth)
143-
{
144-
Console.WriteLine($"ERROR: Reached maximum search depth of {maxSearchDepth}");
145-
throw new FileNotFoundException(
146-
$"Could not locate mapping.json file within {maxSearchDepth} directory levels. " +
147-
$"Started from: {assemblyLocation}");
148-
}
149-
150-
var testDataPath = Path.Combine(testProjectDirectory, "Custom", "TestData", "mapping.json");
151-
var aliasesPath = Path.Combine(testProjectDirectory, "Custom", "TestData", "property-aliases.json");
152-
153-
Console.WriteLine($"Final resolved paths:");
154-
Console.WriteLine($" Mapping file: {testDataPath}");
155-
Console.WriteLine($" Aliases file: {aliasesPath}");
156-
Console.WriteLine($" Mapping file exists: {File.Exists(testDataPath)}");
157-
Console.WriteLine($" Aliases file exists: {File.Exists(aliasesPath)}");
158-
159-
// Load the mapping configuration
160-
try
161-
{
162-
var jsonContent = File.ReadAllText(testDataPath);
163-
Console.WriteLine($"Successfully read mapping.json ({jsonContent.Length} characters)");
164-
_mappingJson = JsonDocument.Parse(jsonContent);
165-
Console.WriteLine("Successfully parsed mapping.json");
166-
}
167-
catch (Exception ex)
168-
{
169-
Console.WriteLine($"ERROR reading or parsing mapping.json: {ex.Message}");
170-
throw;
171-
}
172-
173-
// Load property aliases if the file exists
174-
if (File.Exists(aliasesPath))
175-
{
176-
try
82+
else
17783
{
178-
var aliasContent = File.ReadAllText(aliasesPath);
179-
Console.WriteLine($"Successfully read property-aliases.json ({aliasContent.Length} characters)");
180-
_propertyAliasesJson = JsonDocument.Parse(aliasContent);
181-
182-
// Convert to dictionary for fast lookup
18384
_propertyAliases = new Dictionary<string, string>();
184-
var aliasesElement = _propertyAliasesJson.RootElement.GetProperty("PropertyAliases");
185-
foreach (var alias in aliasesElement.EnumerateObject())
186-
{
187-
_propertyAliases[alias.Name] = alias.Value.GetString();
188-
}
189-
Console.WriteLine($"Loaded {_propertyAliases.Count} property aliases");
19085
}
191-
catch (Exception ex)
192-
{
193-
Console.WriteLine($"ERROR reading or parsing property-aliases.json: {ex.Message}");
194-
throw;
195-
}
196-
}
197-
else
198-
{
199-
Console.WriteLine("property-aliases.json not found, using empty aliases dictionary");
200-
_propertyAliases = new Dictionary<string, string>();
20186
}
202-
203-
Console.WriteLine("=== END DEBUG: ClassInitialize completed successfully ===");
20487
}
20588

20689
[ClassCleanup]

sdk/test/UnitTests/AWSSDK.UnitTests.NetFramework.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@
8484
<EmbeddedResource Include="Custom\Runtime\EventStreams\test_vectors\*"/>
8585
<EmbeddedResource Include="Custom\Runtime\TestEndpoints\*.json"/>
8686
<EmbeddedResource Include="Custom\TestTools\ComparerTest.json"/>
87+
88+
<!-- Add S3 test data as embedded resources -->
89+
<EmbeddedResource Include="../Services/S3/UnitTests/Custom/TestData/mapping.json">
90+
<Link>Custom/TestData/mapping.json</Link>
91+
</EmbeddedResource>
92+
<EmbeddedResource Include="../Services/S3/UnitTests/Custom/TestData/property-aliases.json">
93+
<Link>Custom/TestData/property-aliases.json</Link>
94+
</EmbeddedResource>
8795
</ItemGroup>
8896

89-
</Project>
97+
</Project>

0 commit comments

Comments
 (0)