Ejemplo n.º 1
0
        public async Task SavesSourceToDataDir(int diffId, SourceSide side)
        {
            var content = new SourceContent
            {
                Data       = new byte[] { 1, 2, 3 },
                SourceSide = side
            };
            var expectedFileName = Path.Combine(_DataDir, string.Concat(
                                                    diffId.ToString(), ".", side.ToString().ToLowerInvariant()));

            File.Delete(expectedFileName);

            var storage = new DiskStorage(_Options);
            await storage.SaveSourceAsync(content.InDiffBag(diffId));

            File.ReadAllBytes(expectedFileName)
            .Should().Equal(new byte[] { 1, 2, 3 });
        }
Ejemplo n.º 2
0
        public async Task ReturnsNotReadyForDiffThatDoesntExistsInDataDirButHasSource(SourceSide side)
        {
            var data           = new byte[] { 3, 4, 5 };
            var sourceFileName = Path.Combine(_DataDir, string.Concat(
                                                  "11.", side.ToString().ToLowerInvariant()));

            File.WriteAllBytes(sourceFileName, data);
            try
            {
                var storage = new DiskStorage(_Options);
                var(_, readiness) = await storage.LoadDiffAsync(11);

                readiness.Should().Be(DifferenceReadiness.NotReady);
            }
            finally
            {
                File.Delete(sourceFileName);
            }
        }
Ejemplo n.º 3
0
        public async Task LoadsSourceFromDataDir(int diffId, SourceSide side)
        {
            var data             = new byte[] { 3, 4, 5 };
            var expectedFileName = Path.Combine(_DataDir, string.Concat(
                                                    diffId.ToString(), ".", side.ToString().ToLowerInvariant()));

            File.WriteAllBytes(expectedFileName, data);
            try
            {
                var storage = new DiskStorage(_Options);
                var(source, exists) = await storage.LoadSourceAsync(diffId, side);

                source.SourceSide.Should().Be(side);
                source.Data.Should().Equal(data);
                exists.Should().BeTrue();
            }
            finally
            {
                File.Delete(expectedFileName);
            }
        }
Ejemplo n.º 4
0
        private string GetSourceFileName(int diffId, SourceSide side)
        {
            var fileName = string.Concat(diffId.ToString(), ".", side.ToString().ToLowerInvariant());

            return(Path.Combine(_dataDir, fileName));
        }