/// <summary> /// Gets the updated chunks. /// </summary> public IEnumerable <DifferenceChunkDto> GetUpdatedChunks(string fileName, IEnumerable <CachedChunkDto> cacheChunks) { string downloadFilePath = Path.Combine(CommonConstants.ServerFilesLocation, $"{fileName}"); List <Chunk> chunks = RabinKarpAlgorithm.Slice(File.ReadAllBytes(downloadFilePath)); return(ChunkDifferentiator.GetUpdatedChunks(cacheChunks.Select(CachedChunkDtoMapper.Map).ToList(), chunks).Select(DifferenceChunkDtoMapper.Map)); }
// cache: [0][1][2][3] // ↓ ↓ // current : [0][1][2] public void TestCase10() { var chunksFromCachedFile = new List <Chunk> { new Chunk(Encode("chunk"), 0), new Chunk(Encode("chunk0"), 1), new Chunk(Encode("chunk"), 2), new Chunk(Encode("chunk2"), 3), }; var chunksFromCurrentFile = new List <Chunk> { new Chunk(Encode("chunk0"), 0), new Chunk(Encode("chunk1"), 1), new Chunk(Encode("chunk2"), 2) }; List <DifferenceChunk> differenceChunks = ChunkDifferentiator.GetUpdatedChunks(chunksFromCachedFile, chunksFromCurrentFile).ToList(); differenceChunks.Count.Should().Be(3); differenceChunks.ElementAt(0).ChunkInformation.Should().BeEmpty(); differenceChunks.ElementAt(0).CurentFileChunkNumber.Should().Be(0); differenceChunks.ElementAt(0).CachedFileChunkNumber.Should().Be(1); differenceChunks.ElementAt(1).ChunkInformation.Should().NotBeEmpty(); differenceChunks.ElementAt(1).CurentFileChunkNumber.Should().Be(1); differenceChunks.ElementAt(1).CachedFileChunkNumber.Should().BeNegative(); differenceChunks.ElementAt(2).ChunkInformation.Should().BeEmpty(); differenceChunks.ElementAt(2).CurentFileChunkNumber.Should().Be(2); differenceChunks.ElementAt(2).CachedFileChunkNumber.Should().Be(3); }
// cache: no chunks // // current: no chunks public void TestCase1() { var chunksFromCurrentFile = new List <Chunk>(); var chunksFromCachedFile = new List <Chunk>(); IEnumerable <DifferenceChunk> differenceChunks = ChunkDifferentiator.GetUpdatedChunks(chunksFromCachedFile, chunksFromCurrentFile); differenceChunks.Count().Should().Be(0); }
// cache: [0] // ↓ // current: [0] public void TestCase2() { var chunksFromCurrentFile = new List <Chunk> { new Chunk(Encode("chunk"), 0) }; var chunksFromCachedFile = new List <Chunk> { new Chunk(Encode("chunk"), 0) }; IEnumerable <DifferenceChunk> differenceChunks = ChunkDifferentiator.GetUpdatedChunks(chunksFromCachedFile, chunksFromCurrentFile); DifferenceChunk chunk = differenceChunks.Single(); chunk.CachedFileChunkNumber.Should().Be(0); chunk.CurentFileChunkNumber.Should().Be(0); chunk.ChunkInformation.Should().BeEmpty(); }