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

remove fluent assertions #53

Merged
merged 1 commit into from
Jan 14, 2025
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
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ dotnet_code_quality_unused_parameters = all:suggestion
#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = true:silent
dotnet_style_var_for_built_in_types = false:error
dotnet_style_var_when_type_is_apparent = false:error
dotnet_style_var_elsewhere = false:error

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
Expand Down
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="FluentAssertions" Version="7.0.0-alpha.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.console" Version="2.9.2">
Expand Down Expand Up @@ -48,4 +47,4 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageVersion>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using System;
using Microsoft.Extensions.DependencyInjection;
using MyCSharp.HttpUserAgentParser.DependencyInjection;
using MyCSharp.HttpUserAgentParser.Providers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection;
using MyCSharp.HttpUserAgentParser.DependencyInjection;
Expand All @@ -18,10 +17,10 @@ public void AddHttpUserAgentParserAccessor()

options.AddHttpUserAgentParserAccessor();

services.Count.Should().Be(1);
Assert.Single(services);

services[0].ServiceType.Should().Be<IHttpUserAgentParserAccessor>();
services[0].ImplementationType.Should().Be<HttpUserAgentParserAccessor>();
services[0].Lifetime.Should().Be(ServiceLifetime.Singleton);
Assert.Equal(typeof(IHttpUserAgentParserAccessor), services[0].ServiceType);
Assert.Equal(typeof(HttpUserAgentParserAccessor), services[0].ImplementationType);
Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using FluentAssertions;
using Microsoft.AspNetCore.Http;
using MyCSharp.HttpUserAgentParser.Providers;
using NSubstitute;
Expand All @@ -27,8 +26,8 @@ public void Get(string userAgent)
HttpUserAgentInformation? info = accessor.Get(httpContext);

// assert
info.Should().NotBeNull();
info.Should().Be(userAgentInformation);
Assert.NotNull(info);
Assert.Equal(userAgentInformation, info);

// verify
_parserMock.Received(1).Parse(userAgent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change?

Copy link
Member Author

@BenjaminAbt BenjaminAbt Jan 14, 2025

Choose a reason for hiding this comment

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

I will transfer the Common Definitions like Roslyn etc into the Build Props... then I have to separate them here anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, OK. But a separate PR for this would be welcomed 😉 That change is unrelated to "remove fluent assertions".

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, thats the plan

</ItemGroup>

<ItemGroup Label="NuGet Roslyn">
<PackageReference Include="Roslynator.Analyzers">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -20,9 +24,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />

<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="xunit" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection;
using MyCSharp.HttpUserAgentParser.Providers;
Expand All @@ -17,13 +16,13 @@ public void AddHttpUserAgentMemoryCachedParser()

services.AddHttpUserAgentMemoryCachedParser();

services.Count.Should().Be(2);
Assert.Equal(2, services.Count);

services[0].ImplementationInstance.Should().BeOfType<HttpUserAgentParserMemoryCachedProviderOptions>();
services[0].Lifetime.Should().Be(ServiceLifetime.Singleton);
Assert.IsType<HttpUserAgentParserMemoryCachedProviderOptions>(services[0].ImplementationInstance);
Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime);

services[1].ServiceType.Should().Be<IHttpUserAgentParserProvider>();
services[1].ImplementationType.Should().Be<HttpUserAgentParserMemoryCachedProvider>();
services[1].Lifetime.Should().Be(ServiceLifetime.Singleton);
Assert.Equal(typeof(IHttpUserAgentParserProvider), services[1].ServiceType);
Assert.Equal(typeof(HttpUserAgentParserMemoryCachedProvider), services[1].ImplementationType);
Assert.Equal(ServiceLifetime.Singleton, services[1].Lifetime);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using FluentAssertions;
using Microsoft.Extensions.Caching.Memory;
using Xunit;

Expand All @@ -16,8 +15,8 @@ public void Ctor()

HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheOptions, cacheEntryOptions);

options.CacheOptions.Should().Be(cacheOptions);
options.CacheEntryOptions.Should().Be(cacheEntryOptions);
Assert.Equal(cacheOptions, options.CacheOptions);
Assert.Equal(cacheEntryOptions, options.CacheEntryOptions);
}

[Fact]
Expand All @@ -27,8 +26,8 @@ public void Ctor_MemoryCacheOptions()

HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheOptions);

options.CacheOptions.Should().Be(cacheOptions);
options.CacheEntryOptions.Should().NotBeNull();
Assert.Equal(cacheOptions, options.CacheOptions);
Assert.NotNull(options.CacheEntryOptions);
}

[Fact]
Expand All @@ -38,16 +37,16 @@ public void Ctor_MemoryCacheEntryOptions()

HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheEntryOptions);

options.CacheOptions.Should().NotBeNull();
options.CacheEntryOptions.Should().Be(cacheEntryOptions);
Assert.NotNull(options.CacheOptions);
Assert.Equal(cacheEntryOptions, options.CacheEntryOptions);
}

[Fact]
public void Ctor_Empty()
{
HttpUserAgentParserMemoryCachedProviderOptions options = new();

options.CacheOptions.Should().NotBeNull();
options.CacheEntryOptions.Should().NotBeNull();
Assert.NotNull(options.CacheOptions);
Assert.NotNull(options.CacheEntryOptions);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using FluentAssertions;
using Xunit;

namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests;
Expand All @@ -14,28 +13,28 @@ public void Parse()
HttpUserAgentParserMemoryCachedProvider provider = new(cachedProviderOptions);

// create first
string userAgentOne =
const string userAgentOne =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62";

HttpUserAgentInformation infoOne = provider.Parse(userAgentOne);

infoOne.Name.Should().Be("Edge");
infoOne.Version.Should().Be("90.0.818.62");
Assert.Equal("Edge", infoOne.Name);
Assert.Equal("90.0.818.62", infoOne.Version);

// check duplicate

HttpUserAgentInformation infoDuplicate = provider.Parse(userAgentOne);

infoDuplicate.Name.Should().Be("Edge");
infoDuplicate.Version.Should().Be("90.0.818.62");
Assert.Equal("Edge", infoDuplicate.Name);
Assert.Equal("90.0.818.62", infoDuplicate.Version);

// create second

string userAgentTwo = "Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0";
const string userAgentTwo = "Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0";

HttpUserAgentInformation infoTwo = provider.Parse(userAgentTwo);

infoTwo.Name.Should().Be("Firefox");
infoTwo.Version.Should().Be("41.0");
Assert.Equal("Firefox", infoTwo.Name);
Assert.Equal("41.0", infoTwo.Version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
Comment on lines +8 to +9
Copy link
Contributor

Choose a reason for hiding this comment

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

Undo this change and move it back to where it was.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same reason like above

</ItemGroup>

<ItemGroup Label="NuGet Roslyn">
<PackageReference Include="Roslynator.Analyzers">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -20,12 +25,8 @@
</ItemGroup>

<ItemGroup Label="NuGet">
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />

<PackageReference Include="FluentAssertions"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.console">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using MyCSharp.HttpUserAgentParser.DependencyInjection;
using NSubstitute;
Expand All @@ -17,6 +16,6 @@ public void Ctor_Should_Set_Property()
{
HttpUserAgentParserDependencyInjectionOptions options = new(_scMock);

options.Services.Should().BeEquivalentTo(_scMock);
Assert.Equal(_scMock, options.Services);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using MyCSharp.HttpUserAgentParser.DependencyInjection;
using MyCSharp.HttpUserAgentParser.Providers;
Expand All @@ -22,10 +21,10 @@ public void AddHttpUserAgentParser()

services.AddHttpUserAgentParser();

services.Count.Should().Be(1);
services[0].ServiceType.Should().Be<IHttpUserAgentParserProvider>();
services[0].ImplementationType.Should().Be<HttpUserAgentParserDefaultProvider>();
services[0].Lifetime.Should().Be(ServiceLifetime.Singleton);
Assert.Single(services);
Assert.Equal(typeof(IHttpUserAgentParserProvider), services[0].ServiceType);
Assert.Equal(typeof(HttpUserAgentParserDefaultProvider), services[0].ImplementationType);
Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime);
}

[Fact]
Expand All @@ -35,10 +34,10 @@ public void AddHttpUserAgentCachedParser()

services.AddHttpUserAgentCachedParser();

services.Count.Should().Be(1);
services[0].ServiceType.Should().Be<IHttpUserAgentParserProvider>();
services[0].ImplementationType.Should().Be<HttpUserAgentParserCachedProvider>();
services[0].Lifetime.Should().Be(ServiceLifetime.Singleton);
Assert.Single(services);
Assert.Equal(typeof(IHttpUserAgentParserProvider), services[0].ServiceType);
Assert.Equal(typeof(HttpUserAgentParserCachedProvider), services[0].ImplementationType);
Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime);
}

[Fact]
Expand All @@ -48,9 +47,9 @@ public void AddHttpUserAgentParser_With_Generic()

services.AddHttpUserAgentParser<TestHttpUserAgentParserProvider>();

services.Count.Should().Be(1);
services[0].ServiceType.Should().Be<IHttpUserAgentParserProvider>();
services[0].ImplementationType.Should().Be<TestHttpUserAgentParserProvider>();
services[0].Lifetime.Should().Be(ServiceLifetime.Singleton);
Assert.Single(services);
Assert.Equal(typeof(IHttpUserAgentParserProvider), services[0].ServiceType);
Assert.Equal(typeof(TestHttpUserAgentParserProvider), services[0].ImplementationType);
Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © myCSharp.de - all rights reserved

using FluentAssertions;
using Xunit;

namespace MyCSharp.HttpUserAgentParser.UnitTests;
Expand All @@ -22,32 +21,32 @@ public void IsType(string userAgent, HttpUserAgentType expectedType, bool isMobi

if (expectedType == HttpUserAgentType.Browser)
{
info.IsType(HttpUserAgentType.Browser).Should().Be(true);
info.IsType(HttpUserAgentType.Robot).Should().Be(false);
info.IsType(HttpUserAgentType.Unknown).Should().Be(false);
Assert.True(info.IsType(HttpUserAgentType.Browser));
Assert.False(info.IsType(HttpUserAgentType.Robot));
Assert.False(info.IsType(HttpUserAgentType.Unknown));

info.IsBrowser().Should().Be(true);
info.IsRobot().Should().Be(false);
Assert.True(info.IsBrowser());
Assert.False(info.IsRobot());
}
else if (expectedType == HttpUserAgentType.Robot)
{
info.IsType(HttpUserAgentType.Browser).Should().Be(false);
info.IsType(HttpUserAgentType.Robot).Should().Be(true);
info.IsType(HttpUserAgentType.Unknown).Should().Be(false);
Assert.False(info.IsType(HttpUserAgentType.Browser));
Assert.True(info.IsType(HttpUserAgentType.Robot));
Assert.False(info.IsType(HttpUserAgentType.Unknown));

info.IsBrowser().Should().Be(false);
info.IsRobot().Should().Be(true);
Assert.False(info.IsBrowser());
Assert.True(info.IsRobot());
}
else if (expectedType == HttpUserAgentType.Unknown)
{
info.IsType(HttpUserAgentType.Browser).Should().Be(false);
info.IsType(HttpUserAgentType.Robot).Should().Be(false);
info.IsType(HttpUserAgentType.Unknown).Should().Be(true);
Assert.False(info.IsType(HttpUserAgentType.Browser));
Assert.False(info.IsType(HttpUserAgentType.Robot));
Assert.True(info.IsType(HttpUserAgentType.Unknown));

info.IsBrowser().Should().Be(false);
info.IsRobot().Should().Be(false);
Assert.False(info.IsBrowser());
Assert.False(info.IsRobot());
}

info.IsMobile().Should().Be(isMobile);
Assert.Equal(isMobile, info.IsMobile());
}
}
Loading
Loading