forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to .NET ExecuteJavaScript extension method for converting result
Now validates that the ExecuteJavaScript extension method will correctly detect if the script result is convertable to the generic type. Signed-off-by: Jim Evans <[email protected]>
- Loading branch information
1 parent
dfb5446
commit a591496
Showing
3 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
dotnet/test/support/Extensions/ExecuteJavaScriptTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
|
||
using NMock2; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace OpenQA.Selenium.Support.Extensions | ||
{ | ||
public interface IJavaScriptExecutingWebDriver : IWebDriver, IJavaScriptExecutor | ||
{ | ||
} | ||
|
||
public class SubClassOfReadOnlyCollectionOfObject : ReadOnlyCollection<object> | ||
{ | ||
public SubClassOfReadOnlyCollectionOfObject(IList<object> list) : base(list) | ||
{ | ||
} | ||
} | ||
|
||
[TestFixture] | ||
public class ExecuteJavaScriptTest | ||
{ | ||
private const string JavaScript = "Hello, World"; | ||
private static readonly object[] JavaScriptParameters = new object[0]; | ||
|
||
private Mockery mocks; | ||
private IJavaScriptExecutingWebDriver driver; | ||
|
||
[SetUp] | ||
public void TestSetUp() | ||
{ | ||
mocks = new Mockery(); | ||
|
||
driver = mocks.NewMock<IJavaScriptExecutingWebDriver>(); | ||
} | ||
|
||
[Test] | ||
public void ShouldConvertToIEnumerable() | ||
{ | ||
var expected = new ReadOnlyCollection<object>(new List<object>()); | ||
|
||
Expect.Once.On(driver) | ||
.Method("ExecuteScript") | ||
.With(JavaScript, JavaScriptParameters) | ||
.Will(Return.Value(expected)); | ||
|
||
Assert.That(() => driver.ExecuteJavaScript<IEnumerable>(JavaScript, JavaScriptParameters), Throws.Nothing); | ||
} | ||
|
||
[Test] | ||
public void ShouldConvertToIEnumerableOfObject() | ||
{ | ||
var expected = new ReadOnlyCollection<object>(new List<object>()); | ||
|
||
Expect.Once.On(driver) | ||
.Method("ExecuteScript") | ||
.With(JavaScript, JavaScriptParameters) | ||
.Will(Return.Value(expected)); | ||
|
||
Assert.That(() => driver.ExecuteJavaScript<IEnumerable<object>>(JavaScript, JavaScriptParameters), Throws.Nothing); | ||
} | ||
|
||
[Test] | ||
public void ShouldNotConvertToIEnumerableOfInteger() | ||
{ | ||
var expected = new ReadOnlyCollection<object>(new List<object>()); | ||
|
||
Expect.Once.On(driver) | ||
.Method("ExecuteScript") | ||
.With(JavaScript, JavaScriptParameters) | ||
.Will(Return.Value(expected)); | ||
|
||
Assert.That(() => driver.ExecuteJavaScript<IEnumerable<int>>(JavaScript, JavaScriptParameters), Throws.InstanceOf<WebDriverException>()); | ||
} | ||
|
||
[Test] | ||
public void ShouldConvertToReadOnlyCollectionOfObject() | ||
{ | ||
var expected = new ReadOnlyCollection<object>(new List<object>()); | ||
|
||
Expect.Once.On(driver) | ||
.Method("ExecuteScript") | ||
.With(JavaScript, JavaScriptParameters) | ||
.Will(Return.Value(expected)); | ||
|
||
Assert.That(() => driver.ExecuteJavaScript<ReadOnlyCollection<object>>(JavaScript, JavaScriptParameters), Throws.Nothing); | ||
} | ||
|
||
[Test] | ||
public void ShouldNotConvertToSubClassOfReadOnlyCollectionOfObject() | ||
{ | ||
var expected = new ReadOnlyCollection<object>(new List<object>()); | ||
|
||
Expect.Once.On(driver) | ||
.Method("ExecuteScript") | ||
.With(JavaScript, JavaScriptParameters) | ||
.Will(Return.Value(expected)); | ||
|
||
Assert.That(() => driver.ExecuteJavaScript<SubClassOfReadOnlyCollectionOfObject>(JavaScript, JavaScriptParameters), Throws.InstanceOf<WebDriverException>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters