Skip to content

Commit 4905985

Browse files
craigfowlerGithub Actions Workflow (bot)
authored andcommitted
Publish updated documentation website
1 parent 3e165a1 commit 4905985

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

docs/docs/Assets.html

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,63 @@ <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
8787
<article data-uid="AssetsArticle">
8888
<h1 id="report-assets">Report assets</h1>
8989

90-
<p>TODO: Write this docco page; #301</p>
90+
<p><a href="GettingReports.html">Screenplay reports</a> provide a deep record of how each <a class="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+
<h2 id="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 <a class="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 <a class="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+
<h2 id="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>
107+
<pre><code class="lang-csharp">using CSF.Screenplay;
108+
using CSF.Screenplay.Abilities;
109+
using static CSF.Screenplay.PerformanceStarter;
110+
using static AssetBuilder;
111+
using NUnit.Framework;
112+
113+
[TestFixture]
114+
public class AssetTests
115+
{
116+
[Test, Screenplay]
117+
public async Task TheAssetShouldBeRecorded(ICast cast)
118+
{
119+
var aston = cast.GetActor(&quot;Aston&quot;);
120+
aston.IsAbleTo&lt;GetAssetFilePaths&gt;();
121+
122+
await When(aston).AttemptsTo(SaveTheText(&quot;Content for my asset file&quot;).AsAnAssetNamed(&quot;MyAssetFile.txt&quot;));
123+
124+
// ... assertions etc
125+
}
126+
}
127+
128+
// Implementation of IGetsReport omitted for brevity
129+
public class SaveTheTextAsAnAsset(string baseName, string content) : IPerformable
130+
{
131+
public ValueTask PerformAsAsync(ICanPerform actor, CancellationToken cancellationToken = default)
132+
{
133+
var pathProvider = aston.GetAbility&lt;GetAssetFilePaths&gt;();
134+
var path = pathProvider.GetAssetFilePath(baseName);
135+
System.IO.File.WriteAllText(path, content);
136+
actor.RecordAsset(this, path, &quot;An asset text file&quot;);
137+
}
138+
}
139+
140+
public class AssetBuilder(string text)
141+
{
142+
public static AssetBuilder SaveTheText(string text) =&gt; new AssetBuilder(text);
143+
144+
public IPerformable AsAnAssetNamed(string baseName) =&gt; new SaveTheTextAsAnAsset(baseName, text);
145+
}
146+
</code></pre>
91147

92148
</article>
93149

docs/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@
14271427
"docs/Assets.html": {
14281428
"href": "docs/Assets.html",
14291429
"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); }"
14311431
},
14321432
"docs/Capabilities.html": {
14331433
"href": "docs/Capabilities.html",

0 commit comments

Comments
 (0)