@@ -108,6 +108,101 @@ public static void AppendTestDump(
108108 _ => Task . FromResult ( image . ToStream ( ) ) ,
109109 messageIfExists : messageIfExists ) ;
110110
111+ /// <summary>
112+ /// Appends a local file's content to be collected in the test dump. Suffixes the file name with an index in case of
113+ /// duplicates.
114+ /// </summary>
115+ /// <param name="filePath">The full file system path of the file.</param>
116+ public static void AppendTestDumpKeepingDuplicates (
117+ this UITestContext context ,
118+ string filePath ) =>
119+ context . AppendTestDumpKeepingDuplicatesInternal (
120+ Path . GetFileName ( filePath ) ,
121+ new TestDumpItem ( ( ) => Task . FromResult ( ( Stream ) File . OpenRead ( filePath ) ) ) ) ;
122+
123+ /// <summary>
124+ /// Appends stream as file content to be collected in the test dump. Suffixes the file name with an index in case of
125+ /// duplicates.
126+ /// </summary>
127+ /// <param name="fileName">The name of the file.</param>
128+ /// <param name="action">Gets called in test dump collection.</param>
129+ public static void AppendTestDumpKeepingDuplicates (
130+ this UITestContext context ,
131+ string fileName ,
132+ Func < UITestContext , Task < Stream > > action ) =>
133+ context . AppendTestDumpKeepingDuplicatesInternal (
134+ fileName ,
135+ new TestDumpItem ( ( ) => action ( context ) ) ) ;
136+
137+ /// <summary>
138+ /// Appends string as file content to be collected in the test dump. Suffixes the file name with an index in case of
139+ /// duplicates.
140+ /// </summary>
141+ /// <param name="fileName">The name of the file.</param>
142+ /// <param name="content">File content.</param>
143+ public static void AppendTestDumpKeepingDuplicates (
144+ this UITestContext context ,
145+ string fileName ,
146+ string content ) =>
147+ context . AppendTestDumpKeepingDuplicatesInternal (
148+ fileName ,
149+ new TestDumpItem (
150+ ( ) => Task . FromResult (
151+ new MemoryStream (
152+ Encoding . UTF8 . GetBytes ( content ) ) as Stream ) ) ) ;
153+
154+ /// <summary>
155+ /// Appends generic content as file content to be collected in the test dump. Suffixes the file name with an index
156+ /// in case of duplicates.
157+ /// </summary>
158+ /// <param name="fileName">The name of the file.</param>
159+ /// <param name="content">File content.</param>
160+ /// <param name="getStream">Function to get a new <see cref="Stream"/> from content.</param>
161+ /// <param name="dispose">Action to dispose the content, if required. Can be null.</param>
162+ public static void AppendTestDumpKeepingDuplicates < TContent > (
163+ this UITestContext context ,
164+ string fileName ,
165+ TContent content ,
166+ Func < TContent , Task < Stream > > getStream ,
167+ Action < TContent > dispose = null ) =>
168+ context . AppendTestDumpKeepingDuplicatesInternal (
169+ fileName ,
170+ new TestDumpItemGeneric < TContent > ( content , getStream , dispose ) ) ;
171+
172+ /// <summary>
173+ /// Appends <see cref="Image"/> as file content to be collected in the test dump. Suffixes the file name with an
174+ /// index in case of duplicates. The <see cref="Image"/> will be disposed at the end.
175+ /// </summary>
176+ /// <param name="fileName">The name of the file.</param>
177+ /// <param name="image">File content. The <see cref="Image"/> will be disposed at the end.</param>
178+ public static void AppendTestDumpKeepingDuplicates (
179+ this UITestContext context ,
180+ string fileName ,
181+ Image image ) => context
182+ . AppendTestDumpKeepingDuplicates (
183+ fileName ,
184+ image ,
185+ _ => Task . FromResult ( image . ToStream ( ) ) ) ;
186+
187+ private static void AppendTestDumpKeepingDuplicatesInternal (
188+ this UITestContext context ,
189+ string fileName ,
190+ ITestDumpItem item )
191+ {
192+ var fileNameWithoutExtension = Path . GetFileNameWithoutExtension ( fileName ) ;
193+ var extension = Path . GetExtension ( fileName ) ;
194+ var uniqueFileName = fileName ;
195+ var i = 0 ;
196+
197+ while ( context . TestDumpContainer . ContainsKey ( uniqueFileName ) )
198+ {
199+ i ++ ;
200+ uniqueFileName = $ "{ fileNameWithoutExtension } _{ i . ToTechnicalString ( ) } .{ extension } ";
201+ }
202+
203+ context . AppendTestDumpInternal ( uniqueFileName , item ) ;
204+ }
205+
111206 private static void AppendTestDumpInternal (
112207 this UITestContext context ,
113208 string fileName ,
0 commit comments