Minor refactoring; coverage improved

master
Inga 🏳‍🌈 4 years ago
parent 2c9e6e72b7
commit cfc7a0d315
  1. 6
      Source/TargetBinaryStorage/InMemoryBinaryStorage/BinaryStorage.cs
  2. 21
      Source/TargetBinaryStorage/InMemoryBinaryStorage/BlockInfo.cs
  3. 22
      Tests/ContentTransformer/ClearText/DataWithSignatureTests.cs
  4. 3
      Tests/ContentTransformer/ClearText/EncryptorAndHasherTests.cs

@ -9,7 +9,7 @@
{ {
private Dictionary<string, IBlobInfo> Blobs { get; } = new Dictionary<string, IBlobInfo>(); private Dictionary<string, IBlobInfo> Blobs { get; } = new Dictionary<string, IBlobInfo>();
private Dictionary<BlockId, BlockInfo> Blocks { get; } = new Dictionary<BlockId, BlockInfo>(); private Dictionary<BlockId, byte[]> Blocks { get; } = new Dictionary<BlockId, byte[]>();
public Task<IBlobInfo> GetBlobIfExists(string blobId) public Task<IBlobInfo> GetBlobIfExists(string blobId)
{ {
@ -33,13 +33,13 @@
{ {
return Task.Run(() => return Task.Run(() =>
{ {
this.Blocks[new BlockId(blobId, blockKey)] = new BlockInfo(blobId, partNumber, blockKey, block); this.Blocks[new BlockId(blobId, blockKey)] = block;
}); });
} }
public Task<byte[]> RetrieveBlock(string blobId, string blockKey) public Task<byte[]> RetrieveBlock(string blobId, string blockKey)
{ {
return Task.Run(() => this.Blocks[new BlockId(blobId, blockKey)].BlockData); return Task.Run(() => this.Blocks[new BlockId(blobId, blockKey)]);
} }
} }
} }

@ -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; }
}
}

@ -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<ArgumentException>(() => new DataWithSignature(null, new byte[0]));
Assert.ThrowsAny<ArgumentException>(() => new DataWithSignature(new byte[0], null));
Assert.ThrowsAny<ArgumentException>(() => new DataWithSignature(new byte[0], new byte[65536]));
Assert.ThrowsAny<ArgumentException>(() => 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]);
}
}
}

@ -1,5 +1,6 @@
namespace EternalArrowBackup.ContentTransformer.ClearText.Tests namespace EternalArrowBackup.ContentTransformer.ClearText.Tests
{ {
using System;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using EternalArrowBackup.Hasher.Sha256; using EternalArrowBackup.Hasher.Sha256;
@ -26,11 +27,13 @@
encrypted[0]++; encrypted[0]++;
decryptionResult = await encryptor.GetOriginalData(encrypted); decryptionResult = await encryptor.GetOriginalData(encrypted);
Assert.False(decryptionResult.IsSuccessful); Assert.False(decryptionResult.IsSuccessful);
Assert.Throws<NotImplementedException>(() => decryptionResult.Data);
encrypted[0]--; encrypted[0]--;
encrypted[encrypted.Length - 1]--; encrypted[encrypted.Length - 1]--;
decryptionResult = await encryptor.GetOriginalData(encrypted); decryptionResult = await encryptor.GetOriginalData(encrypted);
Assert.False(decryptionResult.IsSuccessful); Assert.False(decryptionResult.IsSuccessful);
Assert.Throws<NotImplementedException>(() => decryptionResult.Data);
} }
} }
} }

Loading…
Cancel
Save