Skip to content

Commit 577b78d

Browse files
committed
Refactoring after merge
1 parent 484a718 commit 577b78d

6 files changed

Lines changed: 42 additions & 40 deletions

File tree

FileTypeChecker.Tests/FileTypeValidatorTests.cs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
namespace FileTypeChecker.Tests
1+
using FileTypeChecker.Types;
2+
3+
namespace FileTypeChecker.Tests
24
{
35
using System;
46
using System.IO;
57
using Exceptions;
68
using Types;
79
using NUnit.Framework;
8-
using FileTypeChecker.Abstracts;
9-
using System.Text;
1010
using System.Reflection;
1111

1212
[TestFixture]
@@ -285,24 +285,4 @@ private static byte[] GetFileBytes(string fileName)
285285
}
286286

287287
}
288-
289-
public class ArbitraryCsv1FileType : FileType
290-
{
291-
private static readonly string name = "Arbitrary Csv 1 FileType";
292-
private static readonly string extension = "arbitrarycsv1filetype";
293-
private static readonly byte[] magicBytes1 = Encoding.UTF8.GetBytes("ID;field_1;field_2;field_3;field_4;field_5;field_6;field_7;field_8");
294-
private static readonly MagicSequence[] magicBytesJaggedArray = { new MagicSequence(magicBytes1) };
295-
public ArbitraryCsv1FileType() : base(name, extension, magicBytesJaggedArray) { }
296-
}
297-
298-
public class ArbitraryCsv2FileType : FileType
299-
{
300-
private static readonly string name = "Arbitrary Csv 2 FileType";
301-
private static readonly string extension = "arbitrarycsv2filetype";
302-
private static readonly byte[] magicBytes1 = Encoding.UTF8.GetBytes("ID;field_1;field_2;field_3;field_4;field_5;field_6;field_7;field_8;field_9");
303-
private static readonly MagicSequence[] magicBytesJaggedArray = { new MagicSequence(magicBytes1) };
304-
public ArbitraryCsv2FileType() : base(name, extension, magicBytesJaggedArray) { }
305-
}
306-
307-
308288
}

FileTypeChecker.Tests/Setup.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
using NUnit.Framework;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
52
using System.Reflection;
6-
using System.Text;
7-
using System.Threading.Tasks;
83

94
namespace FileTypeChecker.Tests
105
{
116
[SetUpFixture]
127
public class Setup
138
{
14-
159
[OneTimeSetUp]
1610
public void SetUp()
1711
{
@@ -22,7 +16,5 @@ public void SetUp()
2216
public void TearDown()
2317
{
2418
}
25-
26-
2719
}
28-
}
20+
}

FileTypeChecker.Tests/StreamExtensionsTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace FileTypeChecker.Tests
1+
using FileTypeChecker.Types;
2+
3+
namespace FileTypeChecker.Tests
24
{
35
using Types;
46
using Extensions;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Text;
2+
using FileTypeChecker.Abstracts;
3+
4+
namespace FileTypeChecker.Tests.Types
5+
{
6+
public class ArbitraryCsv1FileType : FileType
7+
{
8+
private const string Name = "Arbitrary Csv 1 FileType";
9+
private const string Extension = "arbitrarycsv1filetype";
10+
private static readonly MagicSequence[] MagicBytesJaggedArray = { new MagicSequence(Encoding.UTF8.GetBytes("ID;field_1;field_2;field_3;field_4;field_5;field_6;field_7;field_8")) };
11+
public ArbitraryCsv1FileType() : base(Name, Extension, MagicBytesJaggedArray) { }
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Text;
2+
using FileTypeChecker.Abstracts;
3+
4+
namespace FileTypeChecker.Tests.Types
5+
{
6+
public class ArbitraryCsv2FileType : FileType
7+
{
8+
private const string Name = "Arbitrary Csv 2 FileType";
9+
private const string Extension = "arbitrarycsv2filetype";
10+
private static readonly byte[] MagicBytes = Encoding.UTF8.GetBytes("ID;field_1;field_2;field_3;field_4;field_5;field_6;field_7;field_8;field_9");
11+
private static readonly MagicSequence[] MagicBytesJaggedArray = { new MagicSequence(MagicBytes) };
12+
public ArbitraryCsv2FileType() : base(Name, Extension, MagicBytesJaggedArray) { }
13+
}
14+
}

FileTypeChecker/Abstracts/FileType.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010

1111
public abstract class FileType : IFileType
1212
{
13-
14-
private int BufferSize => Math.Max( MaxMagicSequenceLength, 20);
13+
private int BufferSize => Math.Max(MaxMagicSequenceLength, 20);
1514
private string _name;
1615
private string _extension;
1716
private MagicSequence[] _bytes;
1817

19-
protected FileType(string name, string extension, byte[] magicBytes) : this(name, extension, new MagicSequence(magicBytes))
18+
protected FileType(string name, string extension, byte[] magicBytes) : this(name, extension,
19+
new MagicSequence(magicBytes))
2020
{
2121
}
2222

23-
protected FileType(string name, string extension, byte[][] magicBytes) : this(name, extension, magicBytes.Select(x => new MagicSequence(x)).ToArray())
23+
protected FileType(string name, string extension, byte[][] magicBytes) : this(name, extension,
24+
magicBytes.Select(x => new MagicSequence(x)).ToArray())
2425
{
2526
}
2627

@@ -85,7 +86,7 @@ public bool DoesMatchWith(Stream stream, bool resetPosition = true)
8586
if (!stream.CanRead || (stream.Position != 0 && !stream.CanSeek))
8687
throw new StreamMustBeReadableException();
8788

88-
if (stream.Position != 0 && resetPosition)
89+
if (stream.Position != 0 && resetPosition)
8990
stream.Position = 0;
9091

9192
var buffer = new byte[BufferSize];
@@ -108,7 +109,7 @@ public async Task<bool> DoesMatchWithAsync(Stream stream, bool resetPosition = t
108109
if (!stream.CanRead || (stream.Position != 0 && !stream.CanSeek))
109110
throw new StreamMustBeReadableException();
110111

111-
if (stream.Position != 0 && resetPosition)
112+
if (stream.Position != 0 && resetPosition)
112113
stream.Position = 0;
113114

114115
var buffer = new byte[BufferSize];
@@ -138,4 +139,4 @@ public int GetMatchingNumber(byte[] bytes)
138139

139140
private bool CompareBytes(byte[] bytes) => this.Bytes.Any(byteArray => byteArray.Equals(bytes));
140141
}
141-
}
142+
}

0 commit comments

Comments
 (0)