Skip to content

Commit 0bcddaf

Browse files
committed
Added a unit test to verify the correctness of embedding of anonymous type instance
1 parent 7c49bdb commit 0bcddaf

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

test/MsieJavaScriptEngine.Test.Common/InteropTestsBase.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,70 @@ public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithPropertiesIsCorr
243243
Assert.AreEqual(targetOutput2, output2);
244244
}
245245

246+
[Test]
247+
public virtual void EmbeddingOfInstanceOfAnonymousTypeWithPropertiesIsCorrect()
248+
{
249+
// Arrange
250+
var person = new
251+
{
252+
FirstName = "John",
253+
LastName = "Doe",
254+
Address = new
255+
{
256+
StreetAddress = "103 Elm Street",
257+
City = "Atlanta",
258+
State = "GA",
259+
PostalCode = 30339
260+
}
261+
};
262+
263+
const string input1 = "person.FirstName";
264+
const string targetOutput1 = "John";
265+
266+
const string input2 = "person.LastName";
267+
const string targetOutput2 = "Doe";
268+
269+
const string input3 = "person.Address.StreetAddress";
270+
const string targetOutput3 = "103 Elm Street";
271+
272+
const string input4 = "person.Address.City";
273+
const string targetOutput4 = "Atlanta";
274+
275+
const string input5 = "person.Address.State";
276+
const string targetOutput5 = "GA";
277+
278+
const string input6 = "person.Address.PostalCode";
279+
const int targetOutput6 = 30339;
280+
281+
// Act
282+
string output1;
283+
string output2;
284+
string output3;
285+
string output4;
286+
string output5;
287+
int output6;
288+
289+
using (var jsEngine = CreateJsEngine())
290+
{
291+
jsEngine.EmbedHostObject("person", person);
292+
293+
output1 = jsEngine.Evaluate<string>(input1);
294+
output2 = jsEngine.Evaluate<string>(input2);
295+
output3 = jsEngine.Evaluate<string>(input3);
296+
output4 = jsEngine.Evaluate<string>(input4);
297+
output5 = jsEngine.Evaluate<string>(input5);
298+
output6 = jsEngine.Evaluate<int>(input6);
299+
}
300+
301+
// Assert
302+
Assert.AreEqual(targetOutput1, output1);
303+
Assert.AreEqual(targetOutput2, output2);
304+
Assert.AreEqual(targetOutput3, output3);
305+
Assert.AreEqual(targetOutput4, output4);
306+
Assert.AreEqual(targetOutput5, output5);
307+
Assert.AreEqual(targetOutput6, output6);
308+
}
309+
246310
#endregion
247311

248312
#region Objects with methods

0 commit comments

Comments
 (0)