Skip to content

Commit

Permalink
feat: Remove FluentAssertions
Browse files Browse the repository at this point in the history
  • Loading branch information
cus-dbc-laika committed Jan 16, 2025
1 parent e6152d1 commit 344270d
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 56 deletions.
10 changes: 4 additions & 6 deletions MagicBytesValidator.Tests/Http/FindFileTypeForFormFile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using MagicBytesValidator.Services.Http;

namespace MagicBytesValidator.Tests.Http;
namespace MagicBytesValidator.Tests.Http;

public class FindFileTypeForFormFile
{
Expand All @@ -13,7 +11,7 @@ public async Task Should_find_by_extension()

var result = await sut.FindValidatedTypeAsync(formFile, null, CancellationToken.None);

result.Should().BeOfType<Gif>();
Assert.IsType<Gif>(result);
}

[Fact]
Expand All @@ -25,7 +23,7 @@ public async Task Should_find_by_content_type()

var result = await sut.FindValidatedTypeAsync(formFile, null, CancellationToken.None);

result.Should().BeOfType<Gif>();
Assert.IsType<Gif>(result);
}

[Fact]
Expand All @@ -37,7 +35,7 @@ public async Task Should_return_null_on_not_found()

var result = await sut.FindValidatedTypeAsync(formFile, null, CancellationToken.None);

result.Should().BeNull();
Assert.Null(result);
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions MagicBytesValidator.Tests/Http/FindValidatedTypeAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task Should_find_by_extension()
CancellationToken.None
);

result.Should().BeOfType<Gif>();
Assert.IsType<Gif>(result);
}

[Fact]
Expand All @@ -31,7 +31,7 @@ public async Task Should_find_by_content_type()
CancellationToken.None
);

result.Should().BeOfType<Gif>();
Assert.IsType<Gif>(result);
}

[Fact]
Expand All @@ -47,7 +47,7 @@ public async Task Should_return_null_on_not_found()
CancellationToken.None
);

result.Should().BeNull();
Assert.Null(result);
}

[Fact]
Expand Down
1 change: 0 additions & 1 deletion MagicBytesValidator.Tests/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
global using FluentAssertions;
global using MagicBytesValidator.Exceptions.Http;
global using MagicBytesValidator.Formats;
global using MagicBytesValidator.Models;
Expand Down
1 change: 0 additions & 1 deletion MagicBytesValidator.Tests/MagicBytesValidator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
Expand Down
13 changes: 7 additions & 6 deletions MagicBytesValidator.Tests/MappingRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public class MappingRegister
public void Should_register_single_filetype()
{
_mapping.Register(_trpFileType);
_mapping.FileTypes.Should().Contain(_trpFileType);
Assert.Contains(_trpFileType, _mapping.FileTypes);
}

[Fact]
public void Should_register_list_filetype()
{
var neonJsFileType = new FileByteFilter(
["traperto/niklasschmidt"],
var cusDbcLaikaFileType = new FileByteFilter(
["traperto/laikaschmidt"],
["nms"]
).StartsWith([0x6e, 0x69, 0x6b, 0x6c, 0x61, 0x73, 0x73, 0x63, 0x68, 0x6d, 0x69, 0x64, 0x74]);

Expand All @@ -29,8 +29,9 @@ public void Should_register_list_filetype()
["tjn"]
).StartsWith([0x74, 0x6f, 0x62, 0x69, 0x61, 0x73, 0x6a, 0x61, 0x6e, 0x73, 0x73, 0x65, 0x6e]);

_mapping.Register(new[] { neonJsFileType, kryptobiFileType });
_mapping.FileTypes.Should().Contain(neonJsFileType).And.Contain(kryptobiFileType);
_mapping.Register(new[] { cusDbcLaikaFileType, kryptobiFileType });
Assert.Contains(kryptobiFileType, _mapping.FileTypes);
Assert.Contains(cusDbcLaikaFileType, _mapping.FileTypes);
}

[Fact]
Expand All @@ -39,7 +40,7 @@ public void Should_register_assembly_fileTypes()
var assembly = typeof(AssemblyFacade).Assembly;
_mapping.Register(assembly);

_mapping.FileTypes.Should().Contain(f => f.MimeTypes.Contains("facade/trp"));
Assert.Contains(_mapping.FileTypes, f => f.MimeTypes.Contains("facade/trp"));
}
}

Expand Down
16 changes: 8 additions & 8 deletions MagicBytesValidator.Tests/Models/FileByteFilterMatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void Should_match_pdf()

var pdfTestData = "%PDF-\n%%EOF\n"u8.ToArray();

pdf.Matches(pdfTestData).Should().BeTrue();
Assert.True(pdf.Matches(pdfTestData));
}

[Fact]
Expand All @@ -19,7 +19,7 @@ public void Should_not_match_pdf()

var pdfTestData = "%PDDF-\n%%EEOF\n"u8.ToArray();

pdf.Matches(pdfTestData).Should().BeFalse();
Assert.False(pdf.Matches(pdfTestData));
}

[Fact]
Expand All @@ -44,7 +44,7 @@ public void Should_match_ppt()
pdfTestData[endIndex + 512] = offsetData[endIndex];
}

pdf.Matches(pdfTestData).Should().BeTrue();
Assert.True(pdf.Matches(pdfTestData));
}

[Fact]
Expand All @@ -70,7 +70,7 @@ public void Should_not_match_offset_ppt()
pdfTestData[endIndex + 512] = offsetData[endIndex];
}

pdf.Matches(pdfTestData).Should().BeFalse("Starting data correct but data at offset 512 invalid");
Assert.False(pdf.Matches(pdfTestData), "Starting data correct but data at offset 512 invalid");
}

[Fact]
Expand All @@ -95,7 +95,7 @@ public void Should_not_match_start_ppt()
pdfTestData[endIndex + 512] = offsetData[endIndex];
}

pdf.Matches(pdfTestData).Should().BeFalse("Offset data valid but incorrect starting data");
Assert.False(pdf.Matches(pdfTestData), "Offset data valid but incorrect starting data");
}

[Fact]
Expand All @@ -114,7 +114,7 @@ public void Should_match_xlsx()
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00
};

xlsx.Matches(xlsxTestData).Should().BeTrue();
Assert.True(xlsx.Matches(xlsxTestData));
}

[Fact]
Expand All @@ -129,7 +129,7 @@ public void Should_not_match_xlsx()
0x6f, 0x6b, 0x2e, 0x78, 0xFF, 0xFF, 0xFF, 0x72, 0x65, 0x6c, 0x73, 0xFF, 0xFF
};

xlsx.Matches(xlsxTestData).Should().BeFalse("specific byte array has invalid bytes");
Assert.False(xlsx.Matches(xlsxTestData), "specific byte array has invalid bytes");
}

[Fact]
Expand All @@ -142,6 +142,6 @@ public void Should_match_heic()
0x00,0x00,0x00,0x18, 0x66, 0x74, 0x79, 0x70, 0x68, 0x65, 0x69, 0x63
};

heic.Matches(testStream).Should().BeTrue();
Assert.True(heic.Matches(testStream));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public void Should_match_valid_file()
var testDataOne = new byte[] { 0x46, 0x4F, 0x52, 0x4D, 0x11, 0x12, 0x19, 0x98, 0x41, 0x49, 0x46, 0x46, 0x11 };
var testDataTwo = new byte[] { 0x46, 0x4F, 0x52, 0x4D, 0x00, 0x01, 0x02, 0x03, 0x41, 0x49, 0x46, 0x46, 0x11 };

sut.Matches(testDataOne).Should().BeTrue();
sut.Matches(testDataTwo).Should().BeTrue();
Assert.True(sut.Matches(testDataOne));
Assert.True(sut.Matches(testDataTwo));
}

[Fact]
Expand All @@ -21,6 +21,6 @@ public void Should_not_match_invalid_file()

var testData = new byte[] { 0x00, 0x4F, 0x52, 0x4D, 0x00, 0x12, 0x19, 0x98, 0x41, 0x49, 0x46, 0x46, 0x11 };

sut.Matches(testData).Should().BeFalse();
Assert.False(sut.Matches(testData));
}
}
2 changes: 1 addition & 1 deletion MagicBytesValidator.Tests/Models/ZipMatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public void Should_match_valid_zip()
{
var sut = new Zip();

sut.Matches(EmptyZipFileContent).Should().BeTrue();
Assert.True(sut.Matches(EmptyZipFileContent));
}
}
12 changes: 6 additions & 6 deletions MagicBytesValidator.Tests/Streams/FindAllMatchesAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public async Task Should_find_all_by_magic_byte_sequence()
var result = (await sut.FindAllMatchesAsync(stream, CancellationToken.None))
.ToList();

result.Should().HaveCount(2);
result.Should().Contain(matchingFileType1);
result.Should().Contain(matchingFileType2);
Assert.Equal(2, result.Count);
Assert.Contains(matchingFileType1, result);
Assert.Contains(matchingFileType2, result);
}

[Fact]
Expand Down Expand Up @@ -65,7 +65,7 @@ public async Task Should_reset_stream_position()

_ = await sut.FindAllMatchesAsync(stream, CancellationToken.None);

stream.Position.Should().Be(1);
Assert.Equal(1, stream.Position);
}

[Fact]
Expand All @@ -90,7 +90,7 @@ public async Task Should_handle_unknown_file_type()

var result = await sut.FindAllMatchesAsync(stream, CancellationToken.None);

result.Should().BeEmpty();
Assert.Empty(result);
}

[Fact]
Expand All @@ -107,7 +107,7 @@ public async Task Should_handle_empty_mapping()

var result = await sut.FindAllMatchesAsync(stream, CancellationToken.None);

result.Should().BeEmpty();
Assert.Empty(result);
}

[Fact]
Expand Down
20 changes: 10 additions & 10 deletions MagicBytesValidator.Tests/Streams/FindByMagicByteSequenceAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public async Task Should_find_by_magic_byte_sequence()

var result = await sut.FindByMagicByteSequenceAsync(stream, CancellationToken.None);

result.Should().Be(matchingFileType);
result.Should().NotBe(mismatchingFileType);
Assert.Same(matchingFileType, result);
Assert.NotSame(mismatchingFileType, result);
}

[Fact]
Expand Down Expand Up @@ -65,8 +65,8 @@ public async Task Should_reset_stream_position()

var result = await sut.FindByMagicByteSequenceAsync(stream, CancellationToken.None);

result.Should().Be(matchingFileType);
stream.Position.Should().Be(1);
Assert.Same(matchingFileType, result);
Assert.Equal(1, stream.Position);
}

[Fact]
Expand All @@ -91,7 +91,7 @@ public async Task Should_handle_unknown_file_type()

var result = await sut.FindByMagicByteSequenceAsync(stream, CancellationToken.None);

result.Should().BeNull();
Assert.Null(result);
}

[Fact]
Expand All @@ -108,7 +108,7 @@ public async Task Should_handle_empty_mapping()

var result = await sut.FindByMagicByteSequenceAsync(stream, CancellationToken.None);

result.Should().BeNull();
Assert.Null(result);
}

[Fact]
Expand Down Expand Up @@ -153,8 +153,8 @@ public async Task Should_find_by_magic_byte_sequence_with_offset()

var result = await sut.FindByMagicByteSequenceAsync(stream, CancellationToken.None);

result.Should().Be(matchingFileType);
result.Should().NotBe(mismatchingFileType);
Assert.Same(matchingFileType, result);
Assert.NotSame(mismatchingFileType, result);
}

[Fact]
Expand All @@ -178,7 +178,7 @@ public async Task Should_handle_unknown_file_type_by_offset_in_type()

var result = await sut.FindByMagicByteSequenceAsync(stream, CancellationToken.None);

result.Should().BeNull();
Assert.Null(result);
}

[Fact]
Expand All @@ -203,7 +203,7 @@ public async Task Should_handle_unknown_file_type_by_offset_in_stream()

var result = await sut.FindByMagicByteSequenceAsync(stream, CancellationToken.None);

result.Should().BeNull();
Assert.Null(result);
}
}
#pragma warning restore CS0618 // Type or member is obsolete
12 changes: 6 additions & 6 deletions MagicBytesValidator.Tests/Streams/TryFindUnambiguousAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public async Task Should_find_by_magic_byte_sequence()

var result = await sut.TryFindUnambiguousAsync(stream, CancellationToken.None);

result.Should().Be(matchingFileType);
result.Should().NotBe(mismatchingFileType);
Assert.Same(matchingFileType, result);
Assert.NotSame(mismatchingFileType, result);
}

[Fact]
Expand Down Expand Up @@ -63,8 +63,8 @@ public async Task Should_reset_stream_position()

var result = await sut.TryFindUnambiguousAsync(stream, CancellationToken.None);

result.Should().Be(matchingFileType);
stream.Position.Should().Be(1);
Assert.Same(matchingFileType, result);
Assert.Equal(1, stream.Position);
}

[Fact]
Expand All @@ -89,7 +89,7 @@ public async Task Should_handle_unknown_file_type()

var result = await sut.TryFindUnambiguousAsync(stream, CancellationToken.None);

result.Should().BeNull();
Assert.Null(result);
}

[Fact]
Expand All @@ -106,7 +106,7 @@ public async Task Should_handle_empty_mapping()

var result = await sut.TryFindUnambiguousAsync(stream, CancellationToken.None);

result.Should().BeNull();
Assert.Null(result);
}

[Fact]
Expand Down
Loading

0 comments on commit 344270d

Please sign in to comment.