You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/Assets.html
+57-1Lines changed: 57 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,63 @@ <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
87
87
<articledata-uid="AssetsArticle">
88
88
<h1id="report-assets">Report assets</h1>
89
89
90
-
<p>TODO: Write this docco page; #301</p>
90
+
<p><ahref="GettingReports.html">Screenplay reports</a> provide a deep record of how each <aclass="xref" href="../api/CSF.Screenplay.IPerformance.html">performance</a> has progressed.
91
+
Sometimes, though, a performance creates our generates things.
92
+
Imagine a (fictitious) performance which exports a spreadsheet of sales figures into a PDF file with graphs and charts.
93
+
Wouldn't it be useful to be able to retrieve/access that PDF file from the report?
94
+
<em>This is the use-case facilitated by assets.</em></p>
95
+
<h2id="saving-assets">Saving assets</h2>
96
+
<p>Assets are <strong>files</strong> which are saved to the file system, alongside the report.
97
+
There are four steps to doing this:</p>
98
+
<ol>
99
+
<li>Grant the actor the <aclass="xref" href="../api/CSF.Screenplay.Abilities.GetAssetFilePaths.html"><code>GetAssetFilePaths</code></a> ability</li>
100
+
<li>In the performable class which is to save the asset, use the ability (above) to get the file path</li>
101
+
<li>Save (or copy) the file to the path retrieved above</li>
102
+
<li>Use the <aclass="xref" href="../api/CSF.Screenplay.ICanPerform.html#CSF_Screenplay_ICanPerform_RecordAsset_System_Object_System_String_System_String_"><code>RecordAsset</code></a> actor method to associate the asset file with the report and the current performable</li>
103
+
</ol>
104
+
<h2id="example">Example</h2>
105
+
<p>This example shows how to get an asset file and save it alongside the report.
106
+
Note that this example is compressed; these three classes should be in separate source files and some implementations are omitted.</p>
Copy file name to clipboardExpand all lines: docs/index.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1427,7 +1427,7 @@
1427
1427
"docs/Assets.html": {
1428
1428
"href": "docs/Assets.html",
1429
1429
"title": "Report assets | Screenplay",
1430
-
"summary": "Report assets TODO: Write this docco page; #301"
1430
+
"summary": "Report assets Screenplay reports provide a deep record of how each performance has progressed. Sometimes, though, a performance creates our generates things. Imagine a (fictitious) performance which exports a spreadsheet of sales figures into a PDF file with graphs and charts. Wouldn't it be useful to be able to retrieve/access that PDF file from the report? This is the use-case facilitated by assets. Saving assets Assets are files which are saved to the file system, alongside the report. There are four steps to doing this: Grant the actor the GetAssetFilePaths ability In the performable class which is to save the asset, use the ability (above) to get the file path Save (or copy) the file to the path retrieved above Use the RecordAsset actor method to associate the asset file with the report and the current performable Example This example shows how to get an asset file and save it alongside the report. Note that this example is compressed; these three classes should be in separate source files and some implementations are omitted. using CSF.Screenplay; using CSF.Screenplay.Abilities; using static CSF.Screenplay.PerformanceStarter; using static AssetBuilder; using NUnit.Framework; [TestFixture] public class AssetTests { [Test, Screenplay] public async Task TheAssetShouldBeRecorded(ICast cast) { var aston = cast.GetActor(\"Aston\"); aston.IsAbleTo<GetAssetFilePaths>(); await When(aston).AttemptsTo(SaveTheText(\"Content for my asset file\").AsAnAssetNamed(\"MyAssetFile.txt\")); // ... assertions etc } } // Implementation of IGetsReport omitted for brevity public class SaveTheTextAsAnAsset(string baseName, string content) : IPerformable { public ValueTask PerformAsAsync(ICanPerform actor, CancellationToken cancellationToken = default) { var pathProvider = aston.GetAbility<GetAssetFilePaths>(); var path = pathProvider.GetAssetFilePath(baseName); System.IO.File.WriteAllText(path, content); actor.RecordAsset(this, path, \"An asset text file\"); } } public class AssetBuilder(string text) { public static AssetBuilder SaveTheText(string text) => new AssetBuilder(text); public IPerformable AsAnAssetNamed(string baseName) => new SaveTheTextAsAnAsset(baseName, text); }"
0 commit comments