Skip to content

Commit a97bdfa

Browse files
committed
Continous Integration Pipeline
1 parent 0a27948 commit a97bdfa

File tree

4 files changed

+167
-10
lines changed

4 files changed

+167
-10
lines changed

.github/workflows/dotnet.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: 'dotnet.yml'
5+
6+
on:
7+
push:
8+
branches: [ "dev" ]
9+
paths-ignore:
10+
- 'docs/**'
11+
- '**/*.md'
12+
pull_request:
13+
branches: [ "dev" ]
14+
15+
jobs:
16+
net8:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Setup .NET 8.
21+
uses: actions/setup-dotnet@v4
22+
with:
23+
dotnet-version: '8.0.x'
24+
- name: Restore dependencies
25+
run: dotnet restore
26+
- name: Build
27+
run: dotnet build --configuration Release --no-restore
28+
- name: Run tests
29+
run: dotnet test --framework net8.0 --configuration Release --no-build --verbosity normal
30+
31+
net462:
32+
runs-on: windows-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Setup .NET Framework
36+
uses: microsoft/setup-msbuild@v2
37+
- name: Build
38+
run: msbuild test/HtmlToOpenXml.Tests/HtmlToOpenXml.Tests.csproj /p:Configuration=Release /p:TargetFramework=net462 /restore
39+
- name: Setup VSTest
40+
uses: darenm/Setup-VSTest@v1.2
41+
- name: Run tests (NET Framework)
42+
run: vstest.console.exe test\HtmlToOpenXml.Tests\bin\Release\net462\HtmlToOpenXml.Tests.dll /parallel

.travis.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/HtmlToOpenXml.Tests/HtmlToOpenXml.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFrameworks>net462;net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
6+
<LangVersion>latest</LangVersion>
67
<IsPackable>false</IsPackable>
78
<IsTestProject>true</IsTestProject>
89
<SignAssembly>true</SignAssembly>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.Linq;
5+
6+
#if NET462
7+
8+
/// <summary>
9+
/// Helper class that provide some extension methods to <see cref="IEnumerable{T}"/> API.
10+
/// </summary>
11+
static class CollectionExtensions
12+
{
13+
/// <summary>
14+
/// Attempts to add the specified key and value to the dictionary.
15+
/// </summary>
16+
/// <param name="dictionary">The dictionary in which to insert the item.</param>
17+
/// <param name="key">The key of the element to add.</param>
18+
/// <param name="value">The value of the element to add. It can be <see langword="null"/>.</param>
19+
/// <returns><see langword="true"/> if the key/value pair was added to the dictionary successfully; otherwise, <see langword="false"/>.</returns>
20+
/// <summary>Returns the maximum value in a generic sequence according to a specified key selector function.</summary>
21+
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
22+
/// <typeparam name="TKey">The type of key to compare elements by.</typeparam>
23+
/// <param name="source">A sequence of values to determine the maximum value of.</param>
24+
/// <param name="keySelector">A function to extract the key for each element.</param>
25+
/// <param name="comparer">The <see cref="IComparer{TKey}" /> to compare keys.</param>
26+
/// <returns>The value with the maximum key in the sequence.</returns>
27+
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
28+
/// <exception cref="ArgumentException">No key extracted from <paramref name="source" /> implements the <see cref="IComparable" /> or <see cref="IComparable{TKey}" /> interface.</exception>
29+
/// <remarks>
30+
/// <para>If <typeparamref name="TKey" /> is a reference type and the source sequence is empty or contains only values that are <see langword="null" />, this method returns <see langword="null" />.</para>
31+
/// </remarks>
32+
public static TSource MaxBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
33+
{
34+
if (source == null)
35+
throw new ArgumentNullException(nameof(source));
36+
37+
if (keySelector == null)
38+
throw new ArgumentNullException(nameof(keySelector));
39+
40+
var comparer = Comparer<TKey>.Default;
41+
42+
using IEnumerator<TSource> e = source.GetEnumerator();
43+
44+
if (!e.MoveNext())
45+
{
46+
if (default(TSource) is null)
47+
{
48+
return default;
49+
}
50+
else
51+
{
52+
throw new InvalidOperationException("Sequence contains no elements");
53+
}
54+
}
55+
56+
TSource value = e.Current;
57+
TKey key = keySelector(value);
58+
59+
if (default(TKey) is null)
60+
{
61+
if (key == null)
62+
{
63+
TSource firstValue = value;
64+
65+
do
66+
{
67+
if (!e.MoveNext())
68+
{
69+
// All keys are null, surface the first element.
70+
return firstValue;
71+
}
72+
73+
value = e.Current;
74+
key = keySelector(value);
75+
}
76+
while (key == null);
77+
}
78+
79+
while (e.MoveNext())
80+
{
81+
TSource nextValue = e.Current;
82+
TKey nextKey = keySelector(nextValue);
83+
if (nextKey != null && comparer.Compare(nextKey, key) > 0)
84+
{
85+
key = nextKey;
86+
value = nextValue;
87+
}
88+
}
89+
}
90+
else
91+
{
92+
if (comparer == Comparer<TKey>.Default)
93+
{
94+
while (e.MoveNext())
95+
{
96+
TSource nextValue = e.Current;
97+
TKey nextKey = keySelector(nextValue);
98+
if (Comparer<TKey>.Default.Compare(nextKey, key) > 0)
99+
{
100+
key = nextKey;
101+
value = nextValue;
102+
}
103+
}
104+
}
105+
else
106+
{
107+
while (e.MoveNext())
108+
{
109+
TSource nextValue = e.Current;
110+
TKey nextKey = keySelector(nextValue);
111+
if (comparer.Compare(nextKey, key) > 0)
112+
{
113+
key = nextKey;
114+
value = nextValue;
115+
}
116+
}
117+
}
118+
}
119+
120+
return value;
121+
}
122+
}
123+
#endif

0 commit comments

Comments
 (0)