Skip to content

Commit

Permalink
Add support for .net standard 2.0 (#121)
Browse files Browse the repository at this point in the history
Closes #120
  • Loading branch information
Galad authored May 23, 2019
1 parent a71eebc commit eb5deac
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 13 deletions.
60 changes: 60 additions & 0 deletions src/Tranquire.Selenium.Tests/HighlightTargetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Moq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using Tranquire;
using Tranquire.Selenium;
using Xunit;

namespace Tranquire.Selenium.Tests
{
public class HighlightTargetTests
{
public static IEnumerable<object[]> SystemColors
{
get
{
return typeof(Color).GetProperties(BindingFlags.Public | BindingFlags.Static)
.Where(p => p.PropertyType == typeof(Color))
.Select(p => new object[] { p.GetValue(null), p.Name == "LightGray" ? "LightGrey" : p.Name.ToString() });
}
}

[Theory, MemberData(nameof(SystemColors))]
public void ToHtml_NamedColor_ShouldReturnCorrectValue(Color color, string expected)
{
// act
var actual = HighlightTarget.ToHtml(color);
// assert
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(131, 67, 140, "#83438C")]
[InlineData(129, 131, 201, "#8183C9")]
[InlineData(178, 217, 158, "#B2D99E")]
public void ToHtml_Other_ShouldReturnCorrectValue(int r, int g, int b, string expected)
{
// arrange
var color = Color.FromArgb(r, g, b);
// act
var actual = HighlightTarget.ToHtml(color);
// assert
Assert.Equal(expected, actual);
}

[Fact]
public void ToHtml_EmptyColor_ShouldReturnCorrectValue()
{
// arrange
var color = Color.Empty;
// act
var actual = HighlightTarget.ToHtml(color);
// assert
Assert.Equal(string.Empty, actual);
}
}
}
2 changes: 2 additions & 0 deletions src/Tranquire.Selenium/Extensions/SeleniumReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ public SeleniumReporter(XmlDocumentObserver xmlDocumentObserver, IObserver<Scree
ScreenshotInfoObserver = screenshotInfoObserver ?? throw new ArgumentNullException(nameof(screenshotInfoObserver));
}

#if NET45 || NETSTANDARD2_0
/// <inheritdoc />
public string GetHtmlDocument()
{
return XmlDocumentObserver.GetHtmlDocument();
}
#endif

/// <inheritdoc />
public XDocument GetXmlDocument()
Expand Down
30 changes: 29 additions & 1 deletion src/Tranquire.Selenium/HighlightTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,38 @@ public HighlightTarget(IActor actor) : this(actor, Color.Purple, Color.LightGree

private static string SetBorderJsAction(Color color)
{
var htmlColor = ColorTranslator.ToHtml(color);
var htmlColor = ToHtml(color);
return $"arguments[0].style.border = 'thick solid {htmlColor}';";
}

/// <summary>
/// Gets the HTML color code from a <see cref="Color"/> value
/// </summary>
/// <param name="color">The color</param>
/// <returns>The HTML encoded color (Ex: #DF0101)</returns>
public static string ToHtml(Color color)
{
if (color.IsEmpty)
{
return string.Empty;
}

if (color.IsNamedColor)
{
if (color == Color.LightGray)
{
// special case due to mismatch between Html and enum spelling
return "LightGrey";
}
return color.Name;
}
var colorString = "#" + color.R.ToString("X2", null) +
color.G.ToString("X2", null) +
color.B.ToString("X2", null);

return colorString;
}

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public string Name => Actor.Name;

Expand Down
2 changes: 2 additions & 0 deletions src/Tranquire.Selenium/ISeleniumReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public interface ISeleniumReporter
/// </summary>
/// <returns></returns>
XDocument GetXmlDocument();
#if NET45 || NETSTANDARD2_0
/// <summary>
/// Returns a report in an HTML format
/// </summary>
/// <returns></returns>
string GetHtmlDocument();
#endif
/// <summary>
/// Save the screenshots taken during the run to the disk
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Tranquire.Selenium/Tranquire.Selenium.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<PackageId>Tranquire.Selenium</PackageId>
<Authors>Lucas Loegel</Authors>
<Company />
Expand Down
2 changes: 2 additions & 0 deletions src/Tranquire.Tests/Reporting/ConsoleObserverTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NET462 || NETSTANDARD2_0
using System;
using System.IO;
using System.Text;
Expand Down Expand Up @@ -26,3 +27,4 @@ public override void Dispose()
}
}
}
#endif
2 changes: 1 addition & 1 deletion src/Tranquire.Tests/Reporting/DebugObserverTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if DEBUG
#if DEBUG && NET462
using System.Diagnostics;
using System.IO;
using System.Text;
Expand Down
2 changes: 1 addition & 1 deletion src/Tranquire.Tests/Reporting/TraceObserverTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET462
#if NET462 || NETSTANDARD2_0
using System.Diagnostics;
using System.IO;
using System.Text;
Expand Down
8 changes: 5 additions & 3 deletions src/Tranquire.Tests/Reporting/XmlDocumentObserverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public void GetXmlDocument_WhenNotificationsDidNotEnd_ShouldThrow(
// arrange
sut.OnNext(new ActionNotification(action, 1, new BeforeActionNotificationContent(DateTimeOffset.MinValue, CommandType.Action)));
// act and assert
new Action(() => sut.GetHtmlDocument()).Should().ThrowExactly<InvalidOperationException>();
new Action(() => sut.GetXmlDocument()).Should().ThrowExactly<InvalidOperationException>();
}

[Theory, DomainAutoData]
Expand Down Expand Up @@ -536,6 +536,7 @@ public static void AssertRootAreEqual(XmlReportRoot expected, XmlReportRoot actu
#endregion

#region GetHtmlDocument
#if NET462 || NETSTANDARD2_0
[Theory, DomainAutoData]
public void GetHtmlDocument_ShouldReturnCorrectValue(
XmlDocumentObserver sut,
Expand Down Expand Up @@ -721,11 +722,12 @@ public void GetHtmlDocument_WithGivenWhen_ShouldReturnCorrectValue(
titleCount.Should().Be(1);

}
#endregion
#endif
#endregion

private static int CountStringOccurences(string input, string value)
{
return input.Split(new[] { value }, StringSplitOptions.None).Length - 1;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Tranquire.Tests/Tranquire.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<TargetFrameworks>net462;netcoreapp2.0;netstandard2.0</TargetFrameworks>
<SonarQubeTestProject>true</SonarQubeTestProject>
<CodeAnalysisRuleSet>..\SonarQube\DisableSonarRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Tranquire/Reporting/ConsoleObserver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET45
#if NET45 || NETSTANDARD2_0
using System;

namespace Tranquire.Reporting
Expand Down
2 changes: 1 addition & 1 deletion src/Tranquire/Reporting/TraceObserver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET45
#if NET45 || NETSTANDARD2_0
using System;
using System.Diagnostics;

Expand Down
2 changes: 1 addition & 1 deletion src/Tranquire/Reporting/XmlDocumentObserver.Net45.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET45
#if NET45 || NETSTANDARD2_0
using System;
using System.Collections.Generic;
using System.Reflection;
Expand Down
4 changes: 2 additions & 2 deletions src/Tranquire/Tranquire.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.0;net45</TargetFrameworks>
<TargetFrameworks>netstandard1.0;net45;netstandard2.0</TargetFrameworks>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>http://galad.github.io/tranquire/?utm_source=nuget&amp;utm_medium=referral</PackageProjectUrl>
Expand Down Expand Up @@ -44,6 +44,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Collections.Immutable" version="1.5.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Condition="'$(TargetFramework)'!='netstandard2.0'" Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>

0 comments on commit eb5deac

Please sign in to comment.