Skip to content

Commit 3b3548c

Browse files
committed
Merge branch 'release/0.3.2' into production
2 parents 53469c2 + 06b0420 commit 3b3548c

9 files changed

Lines changed: 261 additions & 6 deletions

CSF.WebDriverExtras.Tests/CSF.WebDriverExtras.Tests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RootNamespace>CSF.WebDriverExtras.Tests</RootNamespace>
99
<AssemblyName>CSF.WebDriverExtras.Tests</AssemblyName>
1010
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11-
<ReleaseVersion>0.3.1-beta</ReleaseVersion>
11+
<ReleaseVersion>0.3.2-beta</ReleaseVersion>
1212
</PropertyGroup>
1313
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1414
<DebugSymbols>true</DebugSymbols>
@@ -76,6 +76,8 @@
7676
<Compile Include="Flags\BrowserFlagsProviderTests.cs" />
7777
<Compile Include="FactoryBuilders\WebDriverFactorySourceIntegrationTests.cs" />
7878
<Compile Include="ConnectToGoogleIntegrationTest.cs" />
79+
<Compile Include="Flags\VersionFactoryTests.cs" />
80+
<Compile Include="Flags\BrowserIdentificationFactoryTests.cs" />
7981
</ItemGroup>
8082
<ItemGroup>
8183
<None Include="packages.config" />
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System;
2+
using CSF.WebDriverExtras.Flags;
3+
using NUnit.Framework;
4+
using OpenQA.Selenium;
5+
using Moq;
6+
7+
namespace CSF.WebDriverExtras.Tests.Flags
8+
{
9+
[TestFixture,Parallelizable(ParallelScope.All)]
10+
public class BrowserIdentificationFactoryTests
11+
{
12+
[Test,AutoMoqData]
13+
public void GetIdentification_integration_test_can_create_identification_for_a_browser(IHasCapabilities driver,
14+
ICapabilities caps)
15+
{
16+
// Arrange
17+
var versionString = "FlamboyantBannana";
18+
var platformType = PlatformType.Android;
19+
var browserName = "FooBrowser";
20+
21+
var sut = new BrowserIdentificationFactory();
22+
Mock.Get(driver).SetupGet(x => x.Capabilities).Returns(caps);
23+
Mock.Get(caps).SetupGet(x => x.BrowserName).Returns(browserName);
24+
Mock.Get(caps).SetupGet(x => x.Version).Returns(versionString);
25+
Mock.Get(caps).SetupGet(x => x.Platform).Returns(new Platform(platformType));
26+
27+
// Act
28+
var result = sut.GetIdentification(driver);
29+
30+
// Assert
31+
Assert.That(result, Is.Not.Null);
32+
}
33+
34+
[Test,AutoMoqData]
35+
public void GetIdentification_integration_test_gets_correct_browser_name(IHasCapabilities driver,
36+
ICapabilities caps)
37+
{
38+
// Arrange
39+
var versionString = "FlamboyantBannana";
40+
var platformType = PlatformType.Android;
41+
var browserName = "FooBrowser";
42+
43+
var sut = new BrowserIdentificationFactory();
44+
Mock.Get(driver).SetupGet(x => x.Capabilities).Returns(caps);
45+
Mock.Get(caps).SetupGet(x => x.BrowserName).Returns(browserName);
46+
Mock.Get(caps).SetupGet(x => x.Version).Returns(versionString);
47+
Mock.Get(caps).SetupGet(x => x.Platform).Returns(new Platform(platformType));
48+
49+
// Act
50+
var result = sut.GetIdentification(driver);
51+
52+
// Assert
53+
Assert.That(result.Name, Is.EqualTo(browserName));
54+
}
55+
56+
[Test,AutoMoqData]
57+
public void GetIdentification_integration_test_gets_correct_unrecognised_version(IHasCapabilities driver,
58+
ICapabilities caps)
59+
{
60+
// Arrange
61+
var versionString = "FlamboyantBannana";
62+
var platformType = PlatformType.Android;
63+
var browserName = "FooBrowser";
64+
65+
var sut = new BrowserIdentificationFactory();
66+
Mock.Get(driver).SetupGet(x => x.Capabilities).Returns(caps);
67+
Mock.Get(caps).SetupGet(x => x.BrowserName).Returns(browserName);
68+
Mock.Get(caps).SetupGet(x => x.Version).Returns(versionString);
69+
Mock.Get(caps).SetupGet(x => x.Platform).Returns(new Platform(platformType));
70+
71+
// Act
72+
var result = sut.GetIdentification(driver);
73+
74+
// Assert
75+
Assert.That(result.Version, Is.EqualTo(new UnrecognisedVersion(versionString)));
76+
}
77+
78+
[Test,AutoMoqData]
79+
public void GetIdentification_integration_test_gets_correct_semantic_version(IHasCapabilities driver,
80+
ICapabilities caps)
81+
{
82+
// Arrange
83+
var versionString = "v1.2.3";
84+
var platformType = PlatformType.Android;
85+
var browserName = "FooBrowser";
86+
87+
var sut = new BrowserIdentificationFactory();
88+
Mock.Get(driver).SetupGet(x => x.Capabilities).Returns(caps);
89+
Mock.Get(caps).SetupGet(x => x.BrowserName).Returns(browserName);
90+
Mock.Get(caps).SetupGet(x => x.Version).Returns(versionString);
91+
Mock.Get(caps).SetupGet(x => x.Platform).Returns(new Platform(platformType));
92+
93+
// Act
94+
var result = sut.GetIdentification(driver);
95+
96+
// Assert
97+
Assert.That(result.Version, Is.EqualTo(SemanticVersion.Parse(versionString)));
98+
}
99+
100+
[Test,AutoMoqData]
101+
public void GetIdentification_integration_test_gets_correct_platform_name(IHasCapabilities driver,
102+
ICapabilities caps)
103+
{
104+
// Arrange
105+
var versionString = "FlamboyantBannana";
106+
var platformType = PlatformType.Android;
107+
var browserName = "FooBrowser";
108+
109+
var sut = new BrowserIdentificationFactory();
110+
Mock.Get(driver).SetupGet(x => x.Capabilities).Returns(caps);
111+
Mock.Get(caps).SetupGet(x => x.BrowserName).Returns(browserName);
112+
Mock.Get(caps).SetupGet(x => x.Version).Returns(versionString);
113+
Mock.Get(caps).SetupGet(x => x.Platform).Returns(new Platform(platformType));
114+
115+
// Act
116+
var result = sut.GetIdentification(driver);
117+
118+
// Assert
119+
Assert.That(result.Platform, Is.EqualTo(platformType.ToString()));
120+
}
121+
}
122+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using CSF.WebDriverExtras.Flags;
3+
using NUnit.Framework;
4+
5+
namespace CSF.WebDriverExtras.Tests.Flags
6+
{
7+
[TestFixture,Parallelizable(ParallelScope.All)]
8+
public class VersionFactoryTests
9+
{
10+
[Test,AutoMoqData]
11+
public void CreateVersion_can_create_a_semantic_version(VersionFactory sut)
12+
{
13+
// Arrange
14+
var versionString = "v1.2.3";
15+
16+
// Act
17+
var result = sut.CreateVersion(versionString);
18+
19+
// Assert
20+
Assert.That(result, Is.EqualTo(SemanticVersion.Parse(versionString)));
21+
}
22+
23+
[Test,AutoMoqData]
24+
public void CreateVersion_can_create_an_unrecognised_version(VersionFactory sut)
25+
{
26+
// Arrange
27+
var versionString = "55.20";
28+
29+
// Act
30+
var result = sut.CreateVersion(versionString);
31+
32+
// Assert
33+
Assert.That(result, Is.EqualTo(new UnrecognisedVersion(versionString)));
34+
}
35+
}
36+
}

CSF.WebDriverExtras.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ Global
2323
GlobalSection(NestedProjects) = preSolution
2424
EndGlobalSection
2525
GlobalSection(MonoDevelopProperties) = preSolution
26-
version = 0.3.1-beta
26+
version = 0.3.2-beta
2727
EndGlobalSection
2828
EndGlobal

CSF.WebDriverExtras/CSF.WebDriverExtras.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RootNamespace>CSF.WebDriverExtras</RootNamespace>
99
<AssemblyName>CSF.WebDriverExtras</AssemblyName>
1010
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11-
<ReleaseVersion>0.3.1-beta</ReleaseVersion>
11+
<ReleaseVersion>0.3.2-beta</ReleaseVersion>
1212
</PropertyGroup>
1313
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1414
<DebugSymbols>true</DebugSymbols>
@@ -101,6 +101,7 @@
101101
<Compile Include="Flags\IGetsBrowserIdentification.cs" />
102102
<Compile Include="Flags\BrowserIdentificationFactory.cs" />
103103
<Compile Include="Config\FactoryOption.cs" />
104+
<Compile Include="Flags\UnrecognisedVersion.cs" />
104105
</ItemGroup>
105106
<ItemGroup>
106107
<None Include="packages.config" />

CSF.WebDriverExtras/CSF.WebDriverExtras.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>CSF.WebDriverExtras</id>
5-
<version>0.3.1-beta</version>
5+
<version>0.3.2-beta</version>
66
<title>CSF.WebDriverExtras</title>
77
<authors>CSF Software Ltd</authors>
88
<licenseUrl>https://opensource.org/licenses/MIT</licenseUrl>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
namespace CSF.WebDriverExtras.Flags
3+
{
4+
/// <summary>
5+
/// Implementation of <see cref="BrowserVersion"/> which works for any version string.
6+
/// It is a fall-back position, because it uses simple string comparison for equality and (worse) for greater-than
7+
/// and less-than comparison.
8+
/// </summary>
9+
public class UnrecognisedVersion : BrowserVersion, IComparable<UnrecognisedVersion>, IEquatable<UnrecognisedVersion>
10+
{
11+
readonly string versionString;
12+
13+
/// <summary>
14+
/// Gets the version string.
15+
/// </summary>
16+
/// <value>The version string.</value>
17+
public string VersionString => versionString;
18+
19+
/// <summary>
20+
/// Compares the current instance to another <see cref="BrowserVersion" /> instance, returning eiher
21+
/// minus one, zero or one.
22+
/// </summary>
23+
/// <param name="other">The browser version to compare with.</param>
24+
public override int CompareTo(BrowserVersion other) => CompareTo(other as UnrecognisedVersion);
25+
26+
/// <summary>
27+
/// Determines whether the specified <see cref="BrowserVersion"/> is equal to the current <see cref="UnrecognisedVersion"/>.
28+
/// </summary>
29+
/// <param name="other">The <see cref="BrowserVersion"/> to compare with the current <see cref="UnrecognisedVersion"/>.</param>
30+
/// <returns><c>true</c> if the specified <see cref="BrowserVersion"/> is equal to the current
31+
/// <see cref="UnrecognisedVersion"/>; otherwise, <c>false</c>.</returns>
32+
public override bool Equals(BrowserVersion other) => Equals(other as UnrecognisedVersion);
33+
34+
/// <summary>
35+
/// Compares the current instance to another <see cref="UnrecognisedVersion" /> instance, returning eiher
36+
/// minus one, zero or one.
37+
/// </summary>
38+
/// <param name="other">The browser version to compare with.</param>
39+
public virtual int CompareTo(UnrecognisedVersion other)
40+
{
41+
if(ReferenceEquals(other, null))
42+
return -1;
43+
44+
return StringComparer.InvariantCulture.Compare(VersionString, other.VersionString);
45+
}
46+
47+
/// <summary>
48+
/// Determines whether the specified <see cref="UnrecognisedVersion"/> is equal to the current <see cref="UnrecognisedVersion"/>.
49+
/// </summary>
50+
/// <param name="other">The <see cref="UnrecognisedVersion"/> to compare with the current <see cref="UnrecognisedVersion"/>.</param>
51+
/// <returns><c>true</c> if the specified <see cref="BrowserVersion"/> is equal to the current
52+
/// <see cref="UnrecognisedVersion"/>; otherwise, <c>false</c>.</returns>
53+
public virtual bool Equals(UnrecognisedVersion other)
54+
{
55+
if(ReferenceEquals(other, null))
56+
return false;
57+
58+
return StringComparer.InvariantCulture.Equals(VersionString, other.VersionString);
59+
}
60+
61+
/// <summary>
62+
/// Serves as a hash function for a <see cref="UnrecognisedVersion"/> object.
63+
/// </summary>
64+
/// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.</returns>
65+
public override int GetHashCode()
66+
{
67+
var str = VersionString ?? String.Empty;
68+
return str.GetHashCode();
69+
}
70+
71+
/// <summary>
72+
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="UnrecognisedVersion"/>.
73+
/// </summary>
74+
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="UnrecognisedVersion"/>.</returns>
75+
public override string ToString() => $"Unrecognised version:{VersionString ?? "<null>"}";
76+
77+
/// <summary>
78+
/// Initializes a new instance of the <see cref="UnrecognisedVersion"/> class.
79+
/// </summary>
80+
/// <param name="versionString">Version string.</param>
81+
public UnrecognisedVersion(string versionString)
82+
{
83+
this.versionString = versionString;
84+
}
85+
}
86+
}

CSF.WebDriverExtras/Flags/VersionFactory.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ public class VersionFactory : ICreatesBrowserVersions
1111
/// </summary>
1212
/// <returns>The version.</returns>
1313
/// <param name="versionString">The string to parse.</param>
14-
public BrowserVersion CreateVersion(string versionString) => SemanticVersion.Parse(versionString);
14+
public BrowserVersion CreateVersion(string versionString)
15+
{
16+
var output = SemanticVersion.Parse(versionString);
17+
18+
if(output != null)
19+
return output;
20+
21+
return new UnrecognisedVersion(versionString);
22+
}
1523
}
1624
}

CSF.WebDriverExtras/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1818
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1919

20-
[assembly: AssemblyVersion("0.3.1.0")]
20+
[assembly: AssemblyVersion("0.3.2.0")]
2121

2222
// The following attributes are used to specify the signing key for the assembly,
2323
// if desired. See the Mono documentation for more information about signing.

0 commit comments

Comments
 (0)