Skip to content

Commit 831c985

Browse files
spahnkeoliverbock
authored andcommitted
Add tests for method calls
1 parent cb7d2de commit 831c985

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

Tests/Noesis.Javascript.Tests/ConvertFromJavascriptTests.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@ private class TypedPropertiesClass
1515
{
1616
public Decimal decimalValue { get; set; }
1717
public float? nullableFloat { get; set; }
18+
19+
public int MethodWithoutParameters()
20+
{
21+
return 1;
22+
}
23+
24+
public int MethodWithOneParameter(int i)
25+
{
26+
return i + 1;
27+
}
28+
29+
public string MethodWithMultipleMixedParameters(int i, string s, bool b)
30+
{
31+
return String.Format("i: {0}, s: {1}, b: {2}", i, s, b);
32+
}
33+
34+
public string MethodWithDefaultParameter(string s = "")
35+
{
36+
return s;
37+
}
1838
}
1939

2040
[TestInitialize]
@@ -165,5 +185,66 @@ public void SelfReferentialArrayDoesNotCauseStackOverflow()
165185
{
166186
_context.Run("a = []; a.push(a)");
167187
}
188+
189+
[TestMethod]
190+
public void MethodCallWithoutParameters()
191+
{
192+
var obj = new TypedPropertiesClass();
193+
_context.SetParameter("obj", obj);
194+
var result = _context.Run("obj.MethodWithoutParameters()");
195+
196+
result.Should().Be(1);
197+
}
198+
199+
[TestMethod]
200+
public void MethodCallWithParameter()
201+
{
202+
var obj = new TypedPropertiesClass();
203+
_context.SetParameter("obj", obj);
204+
var result = _context.Run("obj.MethodWithOneParameter(1)");
205+
206+
result.Should().Be(2);
207+
}
208+
209+
[TestMethod]
210+
public void MethodCallWithMixedParameter()
211+
{
212+
var obj = new TypedPropertiesClass();
213+
_context.SetParameter("obj", obj);
214+
var result = _context.Run("obj.MethodWithMultipleMixedParameters(1, 'test', false)");
215+
216+
result.Should().Be("i: 1, s: test, b: False");
217+
}
218+
219+
[TestMethod]
220+
[Ignore]
221+
public void MethodCallWithDefaultParameter_PassingNoActualParameter()
222+
{
223+
var obj = new TypedPropertiesClass();
224+
_context.SetParameter("obj", obj);
225+
var result = _context.Run("obj.MethodWithDefaultParameter()");
226+
227+
result.Should().Be("");
228+
}
229+
230+
[TestMethod]
231+
public void MethodCallWithDefaultParameter_PassingActualParameter()
232+
{
233+
var obj = new TypedPropertiesClass();
234+
_context.SetParameter("obj", obj);
235+
var result = _context.Run("obj.MethodWithDefaultParameter('foo')");
236+
237+
result.Should().Be("foo");
238+
}
239+
240+
[TestMethod]
241+
public void MethodCallWithDefaultParameter_PassingExcplicitNullAsActualParameter()
242+
{
243+
var obj = new TypedPropertiesClass();
244+
_context.SetParameter("obj", obj);
245+
var result = _context.Run("obj.MethodWithDefaultParameter(null)");
246+
247+
result.Should().Be(null);
248+
}
168249
}
169250
}

0 commit comments

Comments
 (0)