1010using DotVVM . Framework . ViewModel ;
1111using Microsoft . VisualStudio . TestTools . UnitTesting ;
1212using DotVVM . Framework . Testing ;
13- using System . Security . Claims ;
13+ using DotVVM . Framework . Compilation . Styles ;
1414
1515namespace DotVVM . Framework . Tests . ControlTests
1616{
1717 [ TestClass ]
1818 public class ResourceDataContextTests
1919 {
2020 static readonly ControlTestHelper cth = new ControlTestHelper ( config : config => {
21+ _ = Controls . Repeater . RenderAsNamedTemplateProperty ;
22+ config . Styles . Register < Repeater > ( ) . SetProperty ( r => r . RenderAsNamedTemplate , false , StyleOverrideOptions . Ignore ) ;
2123 } ) ;
2224 OutputChecker check = new OutputChecker ( "testoutputs" ) ;
2325
@@ -82,8 +84,6 @@ public async Task Repeater()
8284 <span class=name data-id={resource: Id}>{{resource: Name}}</span>
8385
8486 <span>{{value: _parent.CommandData}}</span>
85-
86- <dot:Button Click={command: _root.TestMethod(Name)} />
8787 </dot:Repeater>
8888
8989 <!-- with wrapper tag -->
@@ -95,13 +95,22 @@ public async Task Repeater()
9595 <span class=name data-id={resource: Id}>{{resource: Name}}</span>
9696
9797 <span>{{value: _parent.CommandData}}</span>
98-
99- <dot:Button Click={command: _root.TestMethod(Name)} />
10098 </dot:Repeater>
10199 "
102100 ) ;
103101
104102 check . CheckString ( r . FormattedHtml , fileExtension : "html" ) ;
103+ }
104+
105+ [ TestMethod ]
106+ public async Task RepeaterWithCommand ( )
107+ {
108+ var r = await cth . RunPage ( typeof ( TestViewModel ) , @"
109+ <dot:Repeater DataSource={resource: Customers.Items}>
110+ <dot:Button Click={command: _root.TestMethod(Name)} />
111+ </dot:Repeater>
112+ "
113+ ) ;
105114
106115 await r . RunCommand ( "_root.TestMethod(Name)" , x => x is TestViewModel . CustomerData { Id : 1 } ) ;
107116 Assert . AreEqual ( ( string ) r . ViewModel . CommandData , "One" ) ;
@@ -110,6 +119,25 @@ public async Task Repeater()
110119 Assert . AreEqual ( ( string ) r . ViewModel . CommandData , "Two" ) ;
111120 }
112121
122+ [ TestMethod ]
123+ public async Task DataContextRevert ( )
124+ {
125+ // revert client-side data context by DataContext={value: _root...}
126+ var r = await cth . RunPage ( typeof ( TestViewModel ) , @"
127+
128+ <dot:Repeater DataSource={resource: Customers.Items} RenderWrapperTag=false>
129+ <span class=name data-id={resource: Id}>{{resource: Name}}</span>
130+
131+ <dot:Repeater DataSource={value: _root.FewStrings}>
132+ {{value: _root.StringPrefix + _this}}
133+ </dot:Repeater>
134+ </dot:Repeater>
135+ "
136+ ) ;
137+
138+ check . CheckString ( r . FormattedHtml , fileExtension : "html" ) ;
139+ }
140+
113141 public class TestViewModel : DotvvmViewModelBase
114142 {
115143 public string NullableString { get ; } = null ;
@@ -129,6 +157,10 @@ public class TestViewModel: DotvvmViewModelBase
129157 }
130158 } ;
131159
160+ public List < string > FewStrings { get ; set ; } = new List < string > ( ) { "Hi!" , "Ahoj!" } ;
161+
162+ public string StringPrefix { get ; set ; } = "..." ;
163+
132164 public UploadedFilesCollection Files { get ; set ; } = new UploadedFilesCollection ( ) ;
133165
134166 public record CustomerData (
0 commit comments