-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenUrlRespectingBaseTests.cs
More file actions
87 lines (74 loc) · 3.81 KB
/
Copy pathOpenUrlRespectingBaseTests.cs
File metadata and controls
87 lines (74 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using CSF.Extensions.WebDriver;
using CSF.Extensions.WebDriver.Factories;
using CSF.Screenplay.Actors;
using CSF.Screenplay.Reporting;
using CSF.Screenplay.Selenium.Actions;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using OpenQA.Selenium;
namespace CSF.Screenplay.Selenium.Tasks;
[TestFixture, Parallelizable]
public class OpenUrlRespectingBaseTests
{
[Test, AutoMoqData]
public async Task TheActionCreatedByThisTaskShouldContainTheCorrectReport(IWebDriver driver, DriverOptions options)
{
var actor = new Actor("Anthony", Guid.NewGuid());
IPerformable? performable = null;
void OnPerform(object? sender, PerformableEventArgs ev) => performable = (IPerformable)ev.Performable;
var namedUri = new NamedUri("test.html", "the test page");
var baseUri = "https://example.com";
actor.IsAbleTo(new UseABaseUri(new Uri(baseUri, UriKind.Absolute)));
actor.IsAbleTo(new BrowseTheWeb(Mock.Of<IGetsWebDriver>(x => x.GetDefaultWebDriver(It.IsAny<Action<DriverOptions>>()) == new WebDriverAndOptions(driver, options))));
var sut = new OpenUrlRespectingBase(namedUri);
var valueFormatterProvider = new ValueFormatterProvider(new ServiceCollection().AddTransient<ToStringFormatter>().BuildServiceProvider(),
new ValueFormatterRegistry { typeof(ToStringFormatter) });
var formatter = new ReportFragmentFormatter(new ReportFormatCreator(), valueFormatterProvider);
actor.EndPerformable += OnPerform;
try
{
await sut.PerformAsAsync(actor);
Assert.Multiple(() =>
{
Assert.That(performable, Is.InstanceOf<OpenUrl>(), "Performable is correct type");
Assert.That(((OpenUrl) performable!).GetReportFragment(actor, formatter).ToString(),
Is.EqualTo("Anthony opens their browser at the test page: https://example.com/test.html"),
"The report is correct");
});
}
finally
{
actor.EndPerformable -= OnPerform;
}
}
[Test, AutoMoqData]
public async Task TheActionCreatedByThisTaskShouldContainTheCorrectReportWhenTheActorDoesNotHaveABaseUrl(IWebDriver driver, DriverOptions options)
{
var actor = new Actor("Anthony", Guid.NewGuid());
IPerformable? performable = null;
void OnPerform(object? sender, PerformableEventArgs ev) => performable = (IPerformable)ev.Performable;
var namedUri = new NamedUri("test.html", "the test page");
actor.IsAbleTo(new BrowseTheWeb(Mock.Of<IGetsWebDriver>(x => x.GetDefaultWebDriver(It.IsAny<Action<DriverOptions>>()) == new WebDriverAndOptions(driver, options))));
var sut = new OpenUrlRespectingBase(namedUri);
var valueFormatterProvider = new ValueFormatterProvider(new ServiceCollection().AddTransient<ToStringFormatter>().BuildServiceProvider(),
new ValueFormatterRegistry { typeof(ToStringFormatter) });
var formatter = new ReportFragmentFormatter(new ReportFormatCreator(), valueFormatterProvider);
actor.EndPerformable += OnPerform;
try
{
await sut.PerformAsAsync(actor);
Assert.Multiple(() =>
{
Assert.That(performable, Is.InstanceOf<OpenUrl>(), "Performable is correct type");
Assert.That(((OpenUrl) performable!).GetReportFragment(actor, formatter).ToString(),
Is.EqualTo("Anthony opens their browser at the test page: test.html"),
"The report is correct");
});
}
finally
{
actor.EndPerformable -= OnPerform;
}
}
}