From cfc7a0d31552b88cd562a55dc661de4db6df6ac8 Mon Sep 17 00:00:00 2001 From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Thu, 30 Jul 2020 23:52:18 +0300 Subject: [PATCH] Minor refactoring; coverage improved --- .../InMemoryBinaryStorage/BinaryStorage.cs | 6 ++--- .../InMemoryBinaryStorage/BlockInfo.cs | 21 ------------------ .../ClearText/DataWithSignatureTests.cs | 22 +++++++++++++++++++ .../ClearText/EncryptorAndHasherTests.cs | 3 +++ 4 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 Source/TargetBinaryStorage/InMemoryBinaryStorage/BlockInfo.cs create mode 100644 Tests/ContentTransformer/ClearText/DataWithSignatureTests.cs diff --git a/Source/TargetBinaryStorage/InMemoryBinaryStorage/BinaryStorage.cs b/Source/TargetBinaryStorage/InMemoryBinaryStorage/BinaryStorage.cs index af87e87..868ae04 100644 --- a/Source/TargetBinaryStorage/InMemoryBinaryStorage/BinaryStorage.cs +++ b/Source/TargetBinaryStorage/InMemoryBinaryStorage/BinaryStorage.cs @@ -9,7 +9,7 @@ { private Dictionary Blobs { get; } = new Dictionary(); - private Dictionary Blocks { get; } = new Dictionary(); + private Dictionary Blocks { get; } = new Dictionary(); public Task GetBlobIfExists(string blobId) { @@ -33,13 +33,13 @@ { return Task.Run(() => { - this.Blocks[new BlockId(blobId, blockKey)] = new BlockInfo(blobId, partNumber, blockKey, block); + this.Blocks[new BlockId(blobId, blockKey)] = block; }); } public Task RetrieveBlock(string blobId, string blockKey) { - return Task.Run(() => this.Blocks[new BlockId(blobId, blockKey)].BlockData); + return Task.Run(() => this.Blocks[new BlockId(blobId, blockKey)]); } } } diff --git a/Source/TargetBinaryStorage/InMemoryBinaryStorage/BlockInfo.cs b/Source/TargetBinaryStorage/InMemoryBinaryStorage/BlockInfo.cs deleted file mode 100644 index 068e769..0000000 --- a/Source/TargetBinaryStorage/InMemoryBinaryStorage/BlockInfo.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace EternalArrowBackup.TargetBinaryStorage.InMemoryBinaryStorage -{ - internal class BlockInfo - { - public BlockInfo(string blobId, int partNumber, string blockKey, byte[] blockData) - { - this.BlobId = blobId; - this.PartNumber = partNumber; - this.BlockKey = blockKey; - this.BlockData = blockData; - } - - public string BlobId { get; } - - public int PartNumber { get; } - - public string BlockKey { get; } - - public byte[] BlockData { get; } - } -} diff --git a/Tests/ContentTransformer/ClearText/DataWithSignatureTests.cs b/Tests/ContentTransformer/ClearText/DataWithSignatureTests.cs new file mode 100644 index 0000000..dd249b8 --- /dev/null +++ b/Tests/ContentTransformer/ClearText/DataWithSignatureTests.cs @@ -0,0 +1,22 @@ +namespace EternalArrowBackup.ContentTransformer.ClearText.Tests +{ + using System; + using Xunit; + + public static class DataWithSignatureTests + { + [Fact] + [Trait("Category", "Simple")] + public static void TestDataWithSignatureConstructor() + { + Assert.ThrowsAny(() => new DataWithSignature(null, new byte[0])); + Assert.ThrowsAny(() => new DataWithSignature(new byte[0], null)); + Assert.ThrowsAny(() => new DataWithSignature(new byte[0], new byte[65536])); + Assert.ThrowsAny(() => new DataWithSignature(new byte[0], new byte[100000])); + new DataWithSignature(new byte[0], new byte[0]); + new DataWithSignature(new byte[100], new byte[100]); + new DataWithSignature(new byte[1000], new byte[65535]); + new DataWithSignature(new byte[100000], new byte[65535]); + } + } +} diff --git a/Tests/ContentTransformer/ClearText/EncryptorAndHasherTests.cs b/Tests/ContentTransformer/ClearText/EncryptorAndHasherTests.cs index b479d49..1eee6bc 100644 --- a/Tests/ContentTransformer/ClearText/EncryptorAndHasherTests.cs +++ b/Tests/ContentTransformer/ClearText/EncryptorAndHasherTests.cs @@ -1,5 +1,6 @@ namespace EternalArrowBackup.ContentTransformer.ClearText.Tests { + using System; using System.Text; using System.Threading.Tasks; using EternalArrowBackup.Hasher.Sha256; @@ -26,11 +27,13 @@ encrypted[0]++; decryptionResult = await encryptor.GetOriginalData(encrypted); Assert.False(decryptionResult.IsSuccessful); + Assert.Throws(() => decryptionResult.Data); encrypted[0]--; encrypted[encrypted.Length - 1]--; decryptionResult = await encryptor.GetOriginalData(encrypted); Assert.False(decryptionResult.IsSuccessful); + Assert.Throws(() => decryptionResult.Data); } } }