Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernise for newer target frameworks #44

Merged
merged 7 commits into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: DotNet

on:
pull_request:
branches:
- $default-branch
push:
branches:
- $default-branch
release:
types: [published]

jobs:
test:
runs-on: ubuntu-latest
name: Build
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-

- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1'

- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0'
Comment on lines +30 to +38
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI these lines can be removed once this lands: actions/runner-images#1891


- name: Install GitVersion
run: dotnet tool install -g GitVersion.Tool

- name: GitVersion
run: dotnet gitversion /l console /output buildserver

- name: DotNet Build
shell: pwsh
run: |
dotnet restore
dotnet build --no-restore
dotnet build --configuration Release --no-restore
dotnet pack --configuration Release --no-restore --no-build

- name: DotNet Test
shell: pwsh
run: |
dotnet test --no-build --no-restore

- name: Push NuGet
if: |
github.event.action == 'published'
shell: pwsh
run: dotnet nuget push **/*.nupkg --source $Env:SOURCE --api-key $Env:TOKEN
env:
SOURCE: 'https://api.nuget.org/v3/index.json'
TOKEN: ${{ secrets.NUGET_API_KEY }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# use glob syntax
syntax: glob

.vs/
.idea/
*.userprefs
*.obj
*.pdb
Expand Down
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

19 changes: 11 additions & 8 deletions src/ByteSizeLib.sln → ByteSizeLib.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.30709.64
MinimumVisualStudioVersion = 15.0.26124.0
Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") = "ByteSizeLib", "ByteSizeLib\ByteSizeLib.csproj", "{7B49A533-D1CE-4826-926B-10187E7C45F6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ByteSizeLib", "src\ByteSizeLib\ByteSizeLib.csproj", "{7B49A533-D1CE-4826-926B-10187E7C45F6}"
EndProject
Project("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC") = "ByteSizeLib.Tests", "ByteSizeLib.Tests\ByteSizeLib.Tests.csproj", "{C676A686-F1B5-48CB-90B3-B1F78FA42691}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ByteSizeLib.Tests", "src\ByteSizeLib.Tests\ByteSizeLib.Tests.csproj", "{C676A686-F1B5-48CB-90B3-B1F78FA42691}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,9 +15,6 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B49A533-D1CE-4826-926B-10187E7C45F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B49A533-D1CE-4826-926B-10187E7C45F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -44,4 +41,10 @@ Global
{C676A686-F1B5-48CB-90B3-B1F78FA42691}.Release|x86.ActiveCfg = Release|Any CPU
{C676A686-F1B5-48CB-90B3-B1F78FA42691}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E3DAEEF5-8A32-45AA-B3FA-DCE6A079997E}
EndGlobalSection
EndGlobal
27 changes: 0 additions & 27 deletions Dockerfile

This file was deleted.

28 changes: 0 additions & 28 deletions Makefile

This file was deleted.

8 changes: 0 additions & 8 deletions global.json

This file was deleted.

17 changes: 16 additions & 1 deletion src/ByteSizeLib.Tests/Binary/ToBinaryStringMethod.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using Xunit;

namespace ByteSizeLib.Tests.BinaryByteSizeTests
Expand All @@ -12,10 +13,24 @@ public void ReturnsDefaultRepresenation()
var b = ByteSize.FromKiloBytes(10);

// Act
var result = b.ToBinaryString();
var result = b.ToBinaryString(CultureInfo.InvariantCulture);

// Assert
Assert.Equal("9.77 KiB", result);
}

[Fact]
public void ReturnsDefaultRepresenationCurrentCulture()
{
// Arrange
var b = ByteSize.FromKiloBytes(10);
var s = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;

// Act
var result = b.ToBinaryString(CultureInfo.CurrentCulture);

// Assert
Assert.Equal($"9{s}77 KiB", result);
}
}
}
9 changes: 4 additions & 5 deletions src/ByteSizeLib.Tests/ByteSizeLib.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -11,10 +11,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>

</Project>
18 changes: 15 additions & 3 deletions src/ByteSizeLib.Tests/ParsingMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,22 @@ public void ParsePartialBits()

Assert.Throws<FormatException>(() =>
{
ByteSize.Parse(val);
ByteSize.Parse(val, CultureInfo.InvariantCulture);
});
}

[Fact]
public void ParsePartialBitsCurrentCulture()
{
var s = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
string val = $"10{s}5b";

Assert.Throws<FormatException>(() =>
{
ByteSize.Parse(val, CultureInfo.CurrentCulture);
});
}

// Parse method throws exceptions
[Fact]
public void ParseThrowsOnInvalid()
Expand Down Expand Up @@ -130,7 +142,7 @@ public void ParseBits()
{
string val = "1b";
var expected = ByteSize.FromBits(1);

var result = ByteSize.Parse(val);

Assert.Equal(expected, result);
Expand All @@ -157,7 +169,7 @@ public void ParseCultureNumberSeparator()
var result = ByteSize.Parse(val);

Assert.Equal(expected, result);

CultureInfo.CurrentCulture = new CultureInfo("en-US");
}

Expand Down
5 changes: 5 additions & 0 deletions src/ByteSizeLib/BinaryByteSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@ public string ToBinaryString()
{
return this.ToString("0.##", CultureInfo.CurrentCulture, useBinaryByte: true);
}

public string ToBinaryString(IFormatProvider formatProvider)
{
return this.ToString("0.##", formatProvider, useBinaryByte: true);
}
}
}
42 changes: 33 additions & 9 deletions src/ByteSizeLib/ByteSizeLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
<Description>ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time.</Description>
<Copyright>Copyright © Omar Khudeira 2013-2020</Copyright>
<AssemblyTitle>ByteSize</AssemblyTitle>
<Version>2.0.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<Authors>Omar Khudeira</Authors>
<TargetFrameworks>netstandard1.0;net45</TargetFrameworks>
<TargetFrameworks>netstandard1.0;netstandard2.1;netstandard2.0;net45;net5.0;</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>portable</DebugType>
<AssemblyName>ByteSize</AssemblyName>
<PackageId>ByteSize</PackageId>
<PackageTags>bytes</PackageTags>
<PackageReleaseNotes>
**HUGE BREAKING CHANGE**:

By default `ByteSize` now assumes `1 KB == 1000 B` and `1 KiB == 1024 B` to
adhere to the IEC and NIST standards (https://en.wikipedia.org/wiki/Binary_prefix).
By default `ByteSize` now assumes `1 KB == 1000 B` and `1 KiB == 1024 B` to
adhere to the IEC and NIST standards (https://en.wikipedia.org/wiki/Binary_prefix).
In the past `ByteSize` assumed `1 KB == 1024 B`, that means if you're upgrading
from v1, you'll see differences in values.

Expand All @@ -35,14 +32,41 @@ New Features:

View all release notes at https://github.com/omar/ByteSize/releases.</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/omar/ByteSize</PackageProjectUrl>
<LicenseUrl>https://raw.githubusercontent.com/omar/ByteSize/master/LICENSE</LicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/omar/ByteSize</RepositoryUrl>
<NeutralLanguage>en</NeutralLanguage>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(MONO_REFERENCE_ASSEMBLIES)' != ''">
<FrameworkPathOverride Condition="'$(TargetFramework)' == 'net45'">$(MONO_REFERENCE_ASSEMBLIES)/4.5-api</FrameworkPathOverride>
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0" />
</ItemGroup>

<!-- Workaround for https://github.com/GitTools/GitVersion/issues/1031 -->
<PropertyGroup Condition="'$(GitVersion_SemVer)' != ''">
<GetVersion>false</GetVersion>
<WriteVersionInfoToBuildLog>false</WriteVersionInfoToBuildLog>
<UpdateAssemblyInfo>false</UpdateAssemblyInfo>

<Version>$(GitVersion_FullSemVer)</Version>
<VersionPrefix>$(GitVersion_MajorMinorPatch)</VersionPrefix>
<VersionSuffix Condition="'$(UseFullSemVerForNuGet)' == 'false'">$(GitVersion_NuGetPreReleaseTag)</VersionSuffix>
<VersionSuffix Condition="'$(UseFullSemVerForNuGet)' == 'true'">$(GitVersion_PreReleaseTag)</VersionSuffix>
<PackageVersion Condition="'$(UseFullSemVerForNuGet)' == 'false'">$(GitVersion_NuGetVersion)</PackageVersion>
<PackageVersion Condition="'$(UseFullSemVerForNuGet)' == 'true'">$(GitVersion_FullSemVer)</PackageVersion>
<InformationalVersion Condition="'$(InformationalVersion)' == ''">$(GitVersion_InformationalVersion)</InformationalVersion>
<AssemblyVersion Condition="'$(AssemblyVersion)' == ''">$(GitVersion_AssemblySemVer)</AssemblyVersion>
<FileVersion Condition="'$(FileVersion)' == ''">$(GitVersion_AssemblySemFileVer)</FileVersion>
<RepositoryBranch Condition="'$(RepositoryBranch)' == ''">$(GitVersion_BranchName)</RepositoryBranch>
<RepositoryCommit Condition="'$(RepositoryCommit)' == ''">$(GitVersion_Sha)</RepositoryCommit>
</PropertyGroup>
</Project>