@@ -201,6 +201,45 @@ public void LoadRejectsOversizedNativeCommentText() {
201201 Assert . Contains ( VisioDocument . MaxCommentTextCharacters . ToString ( ) , exception . Message ) ;
202202 }
203203
204+ [ Fact ]
205+ public void SaveRejectsTooManyNativeComments ( ) {
206+ string filePath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) + ".vsdx" ) ;
207+ VisioDocument document = VisioDocument . Create ( filePath ) ;
208+ VisioPage page = document . AddPage ( "Review" , 11 , 8.5 ) ;
209+ for ( int index = 0 ; index <= VisioDocument . MaxLoadedComments ; index ++ ) {
210+ page . Comments . Add ( new VisioComment ( "Comment " + index . ToString ( ) ) {
211+ AuthorName = "Operations" ,
212+ AuthorInitials = "OP"
213+ } ) ;
214+ }
215+
216+ InvalidDataException exception = Assert . Throws < InvalidDataException > ( ( ) => document . Save ( ) ) ;
217+ Assert . Contains ( VisioDocument . MaxLoadedComments . ToString ( ) , exception . Message ) ;
218+ }
219+
220+ [ Fact ]
221+ public void SaveRejectsOversizedNativeCommentText ( ) {
222+ string filePath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) + ".vsdx" ) ;
223+ VisioDocument document = VisioDocument . Create ( filePath ) ;
224+ VisioPage page = document . AddPage ( "Review" , 11 , 8.5 ) ;
225+ page . AddComment ( new string ( 'x' , VisioDocument . MaxCommentTextCharacters + 1 ) , "Operations" , "OP" ) ;
226+
227+ InvalidDataException exception = Assert . Throws < InvalidDataException > ( ( ) => document . Save ( ) ) ;
228+ Assert . Contains ( VisioDocument . MaxCommentTextCharacters . ToString ( ) , exception . Message ) ;
229+ }
230+
231+ [ Fact ]
232+ public void SaveRejectsCommentsPartThatExceedsUtf8ByteLimit ( ) {
233+ string filePath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) + ".vsdx" ) ;
234+ VisioDocument document = VisioDocument . Create ( filePath ) ;
235+ VisioPage page = document . AddPage ( "Review" , 11 , 8.5 ) ;
236+ VisioComment comment = page . AddComment ( "Byte budget" , "Operations" , "OP" ) ;
237+ comment . AuthorName = new string ( '\u20ac ' , checked ( ( int ) ( VisioDocument . MaxCommentsPartBytes / 3L + 1024L ) ) ) ;
238+
239+ InvalidDataException exception = Assert . Throws < InvalidDataException > ( ( ) => document . Save ( ) ) ;
240+ Assert . Contains ( VisioDocument . MaxCommentsPartBytes . ToString ( ) , exception . Message ) ;
241+ }
242+
204243 private static void AssertNativeCommentPackage (
205244 string filePath ,
206245 string expectedText ,
0 commit comments