@@ -59,6 +59,31 @@ public virtual void EmbeddingOfInstanceOfCustomValueTypeWithFields()
5959 Assert . Equal ( targetOutput3 , output3 ) ;
6060 }
6161
62+ [ Fact ]
63+ public virtual void EmbeddingOfInstanceOfCustomValueTypeWithReadonlyField ( )
64+ {
65+ // Arrange
66+ var age = new Age ( 1979 ) ;
67+ const string updateCode = "age.Year = 1982;" ;
68+
69+ const string input = "age.Year" ;
70+ const int targetOutput = 1979 ;
71+
72+ // Act
73+ int output ;
74+
75+ using ( var jsEngine = CreateJsEngine ( ) )
76+ {
77+ jsEngine . EmbedHostObject ( "age" , age ) ;
78+ jsEngine . Execute ( updateCode ) ;
79+
80+ output = jsEngine . Evaluate < int > ( input ) ;
81+ }
82+
83+ // Assert
84+ Assert . Equal ( targetOutput , output ) ;
85+ }
86+
6287 [ Fact ]
6388 public virtual void EmbeddingOfInstanceOfCustomReferenceTypeWithFields ( )
6489 {
@@ -1174,6 +1199,47 @@ public virtual void EmbeddingOfCustomReferenceTypeWithField()
11741199 Assert . Equal ( targetOutput , output ) ;
11751200 }
11761201
1202+ [ Fact ]
1203+ public virtual void EmbeddingOfCustomReferenceTypeWithReadonlyFields ( )
1204+ {
1205+ // Arrange
1206+ Type runtimeConstantsType = typeof ( RuntimeConstants ) ;
1207+ const string updateCode = @"var oldMinValue = RuntimeConstants.MinValue;
1208+ var oldMaxValue = RuntimeConstants.MaxValue;
1209+
1210+ RuntimeConstants.MinValue = 1;
1211+ RuntimeConstants.MaxValue = 100;" ;
1212+ const string rollbackCode = @"RuntimeConstants.MinValue = oldMinValue;
1213+ RuntimeConstants.MaxValue = oldMaxValue;" ;
1214+
1215+ const string input1 = "RuntimeConstants.MinValue" ;
1216+ const int targetOutput1 = 0 ;
1217+
1218+ const string input2 = "RuntimeConstants.MaxValue" ;
1219+ const int targetOutput2 = 999 ;
1220+
1221+ // Act
1222+ int output1 ;
1223+ int output2 ;
1224+
1225+ using ( var jsEngine = CreateJsEngine ( ) )
1226+ {
1227+ jsEngine . EmbedHostType ( "RuntimeConstants" , runtimeConstantsType ) ;
1228+
1229+ lock ( RuntimeConstants . SyncRoot )
1230+ {
1231+ jsEngine . Execute ( updateCode ) ;
1232+ output1 = jsEngine . Evaluate < int > ( input1 ) ;
1233+ output2 = jsEngine . Evaluate < int > ( input2 ) ;
1234+ jsEngine . Execute ( rollbackCode ) ;
1235+ }
1236+ }
1237+
1238+ // Assert
1239+ Assert . Equal ( targetOutput1 , output1 ) ;
1240+ Assert . Equal ( targetOutput2 , output2 ) ;
1241+ }
1242+
11771243 #endregion
11781244
11791245 #region Types with properties
0 commit comments