Beispiel #1
0
            public void ShouldRetryOnError()
            {
                // Arrange
                using var arena = new TestArena();
                var options     = Substitute.For <IOptions>();

                options.Retries.Returns(3);

                using var resetter = new AutoResetter <int>(() =>
                {
                    var original           = StreamSource.MaxBuffer;
                    StreamSource.MaxBuffer = 1;
                    return(original);
                },
                                                            original => StreamSource.MaxBuffer = original);
                var haveErrored      = false;
                var errorPassThrough = new GenericPassThrough(
                    (data, size) =>
                {
                    if (!haveErrored)
                    {
                        haveErrored = true;
                        throw new DirectoryNotFoundException("foo");
                    }
                },
                    () =>
                {
                }
                    );
                // keep the size small since we're forcing a flush at every byte
                var sourceFile = arena.CreateSourceFile(data: GetRandomBytes(10, 20));
                var expected   = arena.TargetPathFor(sourceFile);
                var sut        = Create(
                    intermediatePipes: new IPassThrough[] { errorPassThrough },
                    options: options);

                // Act
                sut.Synchronize(arena.SourceFileSystem, arena.TargetFileSystem);
                // Assert
                Expect(expected)
                .To.Exist();
                Expect(File.ReadAllBytes(expected))
                .To.Equal(sourceFile.Data);
            }
            public void ShouldArchiveOnlyThoseFiles()
            {
                using var arena = new TestArena();
                // Arrange
                var toArchive    = $"{GetRandomFileName()}";
                var archiveData  = GetRandomBytes();
                var sourceFile   = arena.CreateSourceFile(toArchive, archiveData);
                var targetFile   = arena.CreateTargetFile(toArchive, archiveData);
                var targetMarker = arena.CreateTargetFile($"{sourceFile.Name}.t", new byte[0]);
                var archive      = arena.ArchiveFileSystem;
                var target       = arena.TargetFileSystem;
                var source       = arena.SourceFileSystem;

                var sut = Create();

                // Act
                sut.RunArchiveOperations(
                    target,
                    archive,
                    source);
                // Assert
                // archive target should have archived file
                // -> should not be at target
                Expect(arena.TargetFileSystem.Exists(toArchive))
                .To.Be.False("Target file should not exist any more");
                // -> should not be at source either
                Expect(arena.SourceFileSystem.Exists(toArchive))
                .To.Be.False("Source file should not exist any more");
                // archive marker should no longer exist
                Expect(arena.TargetFileSystem.Exists($"{toArchive}.t"))
                .To.Be.False("Target file marker should not exist any more");
                // resource file _should_ exist at archive
                Expect(arena.ArchiveFileSystem.Exists(toArchive))
                .To.Be.True("Resource should be archived");
                // marker file _should not_ exist at archive
                Expect(arena.ArchiveFileSystem.Exists($"{toArchive}.t"))
                .To.Be.False("Marker should not be present in archive");
            }