Skip to content

Commit 733ceec

Browse files
committed
Now when you call the overloaded version of the ExecuteResource method, that takes the type, need to pass the resource name without the namespace
1 parent a6c3eb1 commit 733ceec

File tree

5 files changed

+25
-115
lines changed

5 files changed

+25
-115
lines changed

src/JavaScriptEngineSwitcher.Core/IJsEngine.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@ bool SupportsGarbageCollection
6565
/// <summary>
6666
/// Executes a code from embedded JS-resource
6767
/// </summary>
68-
/// <param name="resourceName">JS-resource name</param>
69-
/// <param name="type">Type from assembly that containing an embedded resource</param>
68+
/// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param>
69+
/// <param name="type">The type, that determines the assembly and whose namespace is used to scope
70+
/// the resource name</param>
7071
void ExecuteResource(string resourceName, Type type);
7172

7273
/// <summary>
7374
/// Executes a code from embedded JS-resource
7475
/// </summary>
75-
/// <param name="resourceName">JS-resource name</param>
76-
/// <param name="assembly">Assembly that containing an embedded resource</param>
76+
/// <param name="resourceName">The case-sensitive resource name</param>
77+
/// <param name="assembly">The assembly, which contains the embedded resource</param>
7778
void ExecuteResource(string resourceName, Assembly assembly);
7879

7980
/// <summary>

src/JavaScriptEngineSwitcher.Core/Utilities/AssemblyExtensions.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/JavaScriptEngineSwitcher.Core/Utilities/Utils.cs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public static bool Is64BitProcess()
6464
/// <summary>
6565
/// Gets a content of the embedded resource as string
6666
/// </summary>
67-
/// <param name="resourceName">Resource name</param>
68-
/// <param name="type">Type from assembly that containing an embedded resource</param>
67+
/// <param name="resourceName">The case-sensitive resource name without the namespace of the specified type</param>
68+
/// <param name="type">The type, that determines the assembly and whose namespace is used to scope
69+
/// the resource name</param>
6970
/// <returns>Сontent of the embedded resource as string</returns>
7071
public static string GetResourceAsString(string resourceName, Type type)
7172
{
@@ -89,26 +90,16 @@ public static string GetResourceAsString(string resourceName, Type type)
8990

9091
Assembly assembly = type.GetTypeInfo().Assembly;
9192
string nameSpace = type.Namespace;
93+
string resourceFullName = nameSpace != null ? nameSpace + "." + resourceName : resourceName;
9294

93-
if (nameSpace != null && resourceName.StartsWith(nameSpace, StringComparison.Ordinal))
94-
{
95-
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
96-
{
97-
return ReadResourceAsString(resourceName, stream);
98-
}
99-
}
100-
101-
using (Stream stream = assembly.GetManifestResourceStream(type, resourceName))
102-
{
103-
return ReadResourceAsString(resourceName, stream);
104-
}
95+
return InnerGetResourceAsString(resourceFullName, assembly);
10596
}
10697

10798
/// <summary>
10899
/// Gets a content of the embedded resource as string
109100
/// </summary>
110-
/// <param name="resourceName">Resource name</param>
111-
/// <param name="assembly">Assembly that containing an embedded resource</param>
101+
/// <param name="resourceName">The case-sensitive resource name</param>
102+
/// <param name="assembly">The assembly, which contains the embedded resource</param>
112103
/// <returns>Сontent of the embedded resource as string</returns>
113104
public static string GetResourceAsString(string resourceName, Assembly assembly)
114105
{
@@ -130,23 +121,23 @@ public static string GetResourceAsString(string resourceName, Assembly assembly)
130121
string.Format(Strings.Common_ArgumentIsEmpty, "resourceName"), "resourceName");
131122
}
132123

133-
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
134-
{
135-
return ReadResourceAsString(resourceName, stream);
136-
}
124+
return InnerGetResourceAsString(resourceName, assembly);
137125
}
138126

139-
private static string ReadResourceAsString(string resourceName, Stream stream)
127+
private static string InnerGetResourceAsString(string resourceName, Assembly assembly)
140128
{
141-
if (stream == null)
129+
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
142130
{
143-
throw new NullReferenceException(
144-
string.Format(Strings.Resources_ResourceIsNull, resourceName));
145-
}
131+
if (stream == null)
132+
{
133+
throw new NullReferenceException(
134+
string.Format(Strings.Resources_ResourceIsNull, resourceName));
135+
}
146136

147-
using (var reader = new StreamReader(stream))
148-
{
149-
return reader.ReadToEnd();
137+
using (var reader = new StreamReader(stream))
138+
{
139+
return reader.ReadToEnd();
140+
}
150141
}
151142
}
152143

src/JavaScriptEngineSwitcher.Core/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"buildOptions": {
3434
"compile": {
3535
"exclude": [
36-
"Utilities/AssemblyExtensions.cs",
3736
"Utilities/TypeInfoExtensions.cs"
3837
]
3938
}

test/JavaScriptEngineSwitcher.Tests/CommonTestsBase.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,7 @@ public virtual void ExecutionOfResourceByNameAndTypeIsCorrect()
221221
}
222222

223223
[Fact]
224-
public virtual void ExecutionOfResourceByFullNameAndTypeIsCorrect()
225-
{
226-
// Arrange
227-
const string resourceName = "JavaScriptEngineSwitcher.Tests.Resources.cube.js";
228-
const string input = "cube(5);";
229-
const int targetOutput = 125;
230-
231-
// Act
232-
int output;
233-
234-
using (var jsEngine = CreateJsEngine())
235-
{
236-
jsEngine.ExecuteResource(resourceName, typeof(CommonTestsBase));
237-
output = jsEngine.Evaluate<int>(input);
238-
}
239-
240-
// Assert
241-
Assert.Equal(targetOutput, output);
242-
}
243-
244-
[Fact]
245-
public virtual void ExecutionOfResourceByFullNameAndAssemblyIsCorrect()
224+
public virtual void ExecutionOfResourceByNameAndAssemblyIsCorrect()
246225
{
247226
// Arrange
248227
const string resourceName = "JavaScriptEngineSwitcher.Tests.Resources.power.js";

0 commit comments

Comments
 (0)