@@ -222,5 +222,127 @@ public void TestChangingCommentBlockPosition()
222222 Assert . AreEqual ( newLocation , block . Location ) ;
223223 } ) ;
224224 }
225+
226+ [ TestMethod ]
227+ public void TestCommentBlockHeaderDefaultsToEmpty ( )
228+ {
229+ TestHelper . RunInModelSystemContext ( "TestCommentBlockHeaderDefaultsToEmpty" , ( user , pSession , msSession ) =>
230+ {
231+ CommandError error = null ;
232+ var ms = msSession . ModelSystem ;
233+ Assert . IsTrue ( msSession . AddCommentBlock ( user , ms . GlobalBoundary , "My Comment" , new Rectangle ( 100 , 100 ) ,
234+ out CommentBlock block , out error ) , error ? . Message ) ;
235+ Assert . AreEqual ( string . Empty , block . Header , "New comment block header should default to empty string." ) ;
236+ } ) ;
237+ }
238+
239+ [ TestMethod ]
240+ public void TestSettingCommentBlockHeader ( )
241+ {
242+ TestHelper . RunInModelSystemContext ( "TestSettingCommentBlockHeader" , ( user , pSession , msSession ) =>
243+ {
244+ CommandError error = null ;
245+ var ms = msSession . ModelSystem ;
246+ Assert . IsTrue ( msSession . AddCommentBlock ( user , ms . GlobalBoundary , "My Comment" , new Rectangle ( 100 , 100 ) ,
247+ out CommentBlock block , out error ) , error ? . Message ) ;
248+ const string header = "My Header" ;
249+ Assert . IsTrue ( msSession . SetCommentBlockHeader ( user , block , header , out error ) , error ? . Message ) ;
250+ Assert . AreEqual ( header , block . Header , "The comment block header was not set." ) ;
251+ } ) ;
252+ }
253+
254+ [ TestMethod ]
255+ public void TestSettingCommentBlockHeaderWithBadUser ( )
256+ {
257+ TestHelper . RunInModelSystemContext ( "TestSettingCommentBlockHeaderWithBadUser" , ( user , unauthorizedUser , pSession , msSession ) =>
258+ {
259+ CommandError error = null ;
260+ var ms = msSession . ModelSystem ;
261+ Assert . IsTrue ( msSession . AddCommentBlock ( user , ms . GlobalBoundary , "My Comment" , new Rectangle ( 100 , 100 ) ,
262+ out CommentBlock block , out error ) , error ? . Message ) ;
263+ Assert . IsFalse ( msSession . SetCommentBlockHeader ( unauthorizedUser , block , "Should Fail" , out error ) ) ;
264+ Assert . AreEqual ( string . Empty , block . Header , "Header should remain empty after unauthorized set." ) ;
265+ } ) ;
266+ }
267+
268+ [ TestMethod ]
269+ public void TestSettingCommentBlockHeaderUndoRedo ( )
270+ {
271+ TestHelper . RunInModelSystemContext ( "TestSettingCommentBlockHeaderUndoRedo" , ( user , pSession , msSession ) =>
272+ {
273+ CommandError error = null ;
274+ var ms = msSession . ModelSystem ;
275+ Assert . IsTrue ( msSession . AddCommentBlock ( user , ms . GlobalBoundary , "My Comment" , new Rectangle ( 100 , 100 ) ,
276+ out CommentBlock block , out error ) , error ? . Message ) ;
277+ const string header = "Important Header" ;
278+ Assert . IsTrue ( msSession . SetCommentBlockHeader ( user , block , header , out error ) , error ? . Message ) ;
279+ Assert . AreEqual ( header , block . Header ) ;
280+ Assert . IsTrue ( msSession . Undo ( user , out error ) , error ? . Message ) ;
281+ Assert . AreEqual ( string . Empty , block . Header , "Header should be empty after undo." ) ;
282+ Assert . IsTrue ( msSession . Redo ( user , out error ) , error ? . Message ) ;
283+ Assert . AreEqual ( header , block . Header , "Header should be restored after redo." ) ;
284+ } ) ;
285+ }
286+
287+ [ TestMethod ]
288+ public void TestSettingCommentBlockHeaderAllowsEmpty ( )
289+ {
290+ TestHelper . RunInModelSystemContext ( "TestSettingCommentBlockHeaderAllowsEmpty" , ( user , pSession , msSession ) =>
291+ {
292+ CommandError error = null ;
293+ var ms = msSession . ModelSystem ;
294+ Assert . IsTrue ( msSession . AddCommentBlock ( user , ms . GlobalBoundary , "My Comment" , new Rectangle ( 100 , 100 ) ,
295+ out CommentBlock block , out error ) , error ? . Message ) ;
296+ Assert . IsTrue ( msSession . SetCommentBlockHeader ( user , block , "Has Header" , out error ) , error ? . Message ) ;
297+ Assert . IsTrue ( msSession . SetCommentBlockHeader ( user , block , string . Empty , out error ) , error ? . Message ) ;
298+ Assert . AreEqual ( string . Empty , block . Header , "Empty header should be accepted." ) ;
299+ } ) ;
300+ }
301+
302+ [ TestMethod ]
303+ public void TestCommentBlockHeaderPersistence ( )
304+ {
305+ const string comment = "My Comment" ;
306+ const string header = "My Header" ;
307+ var location = new Rectangle ( 100 , 100 ) ;
308+ TestHelper . RunInModelSystemContext ( "TestCommentBlockHeaderPersistence" , ( user , pSession , msSession ) =>
309+ {
310+ CommandError error = null ;
311+ var ms = msSession . ModelSystem ;
312+ Assert . IsTrue ( msSession . AddCommentBlock ( user , ms . GlobalBoundary , comment , location ,
313+ out CommentBlock block , out error ) , error ? . Message ) ;
314+ Assert . IsTrue ( msSession . SetCommentBlockHeader ( user , block , header , out error ) , error ? . Message ) ;
315+ Assert . IsTrue ( msSession . Save ( out error ) , error ? . Message ) ;
316+ } , ( user , pSession , msSession ) =>
317+ {
318+ var comBlocks = msSession . ModelSystem . GlobalBoundary . CommentBlocks ;
319+ Assert . HasCount ( 1 , comBlocks ) ;
320+ Assert . AreEqual ( comment , comBlocks [ 0 ] . Comment , "Comment should survive save/load." ) ;
321+ Assert . AreEqual ( header , comBlocks [ 0 ] . Header , "Header should survive save/load." ) ;
322+ } ) ;
323+ }
324+
325+ [ TestMethod ]
326+ public void TestCommentBlockHeaderDefaultsToEmptyOnLoad ( )
327+ {
328+ // A model system saved before headers were introduced should load with an empty header.
329+ const string comment = "Legacy Comment" ;
330+ var location = new Rectangle ( 50 , 50 ) ;
331+ TestHelper . RunInModelSystemContext ( "TestCommentBlockHeaderDefaultsToEmptyOnLoad" , ( user , pSession , msSession ) =>
332+ {
333+ CommandError error = null ;
334+ var ms = msSession . ModelSystem ;
335+ Assert . IsTrue ( msSession . AddCommentBlock ( user , ms . GlobalBoundary , comment , location ,
336+ out CommentBlock block , out error ) , error ? . Message ) ;
337+ // Leave the header at the default (empty) and save.
338+ Assert . IsTrue ( msSession . Save ( out error ) , error ? . Message ) ;
339+ } , ( user , pSession , msSession ) =>
340+ {
341+ var comBlocks = msSession . ModelSystem . GlobalBoundary . CommentBlocks ;
342+ Assert . HasCount ( 1 , comBlocks ) ;
343+ Assert . AreEqual ( comment , comBlocks [ 0 ] . Comment ) ;
344+ Assert . AreEqual ( string . Empty , comBlocks [ 0 ] . Header , "Header should default to empty string when absent from file." ) ;
345+ } ) ;
346+ }
225347 }
226348}
0 commit comments