@@ -4,6 +4,60 @@ namespace AltaSoft.Simpra.Tests;
44
55public class SimpraExpressionTests
66{
7+
8+ [ Fact ]
9+ public void DictionaryIndexer_MissingKey_ReturnsDefaultValueForProperty ( )
10+ {
11+ const string expressionCode =
12+ """
13+ return DictionaryOfObjects['test'].Id
14+ """ ;
15+
16+ var simpra = new Simpra ( ) ;
17+ var model = GetTestModel ( ) ;
18+ model . DictionaryOfObjects = new Dictionary < string , Customer > { { "Georgia" , new Customer
19+ {
20+ Id = 1 ,
21+ Status = 10
22+ } } } ;
23+
24+ var result = simpra . Execute < int , TestModel , IFunctions > ( model , new TestFunctions ( ) , expressionCode ) ;
25+ Assert . Equal ( 0 , result ) ;
26+
27+ }
28+
29+ [ Fact ]
30+ public void CallGetValueFromDictionaryWhenKeyDoesNotExist_ShouldReturnDefault ( )
31+ {
32+ const string expressionCode =
33+ """
34+ return Countries['test'] is 'Test'
35+ """ ;
36+
37+ var simpra = new Simpra ( ) ;
38+ var model = GetTestModel ( ) ;
39+ model . Countries = new Dictionary < string , string > { { "Georgia" , "Test" } } ;
40+ var result = simpra . Execute < bool , TestModel , IFunctions > ( model , new TestFunctions ( ) , expressionCode ) ;
41+ Assert . False ( result ) ;
42+
43+ }
44+
45+ [ Fact ]
46+ public void CallGetValueFromDictionaryWhenKeyExist_ShouldReturnValue ( )
47+ {
48+ const string expressionCode =
49+ """
50+ return Countries['Georgia'] is 'Test'
51+ """ ;
52+
53+ var simpra = new Simpra ( ) ;
54+ var model = GetTestModel ( ) ;
55+ model . Countries = new Dictionary < string , string > { { "Georgia" , "Test" } } ;
56+ var result = simpra . Execute < bool , TestModel , IFunctions > ( model , new TestFunctions ( ) , expressionCode ) ;
57+ Assert . True ( result ) ;
58+
59+ }
60+
761 [ Fact ]
862 public void CallInterfaceFunctionFromSimpra_ShouldReturnCorrectValue ( )
963 {
0 commit comments