예제 #1
0
            public void ShouldSupplyRelativePathOnDemand()
            {
                // Arrange
                using var tempFolder = new AutoTempFolder();
                var file1     = tempFolder.CreateRandomFile();
                var sub       = tempFolder.CreateRandomFolder();
                var file2     = Path.Combine(sub, CreateRandomFileIn(sub));
                var expected1 = Path.GetRelativePath(tempFolder.Path, file1);
                var expected2 = Path.GetRelativePath(tempFolder.Path, file2);
                var sut       = Create(tempFolder);
                // Act
                var results = sut.ListResourcesRecursive();

                // Assert
                Expect(results)
                .To.Contain.Only(2)
                .Items();
                Expect(results)
                .To.Contain.Exactly(1)
                .Matched.By(o => o.RelativePath == expected1 &&
                            o.Path == file1);
                Expect(results)
                .To.Contain.Exactly(1)
                .Matched.By(o => o.RelativePath == expected2 &&
                            o.Path == file2);
            }
예제 #2
0
            public void ShouldReturnSingleFileUnderBasePath()
            {
                // Arrange
                using var tempFolder = new AutoTempFolder();
                var filePath = tempFolder.CreateRandomFile();
                var sut      = Create(tempFolder);
                // Act
                var results = sut.ListResourcesRecursive();

                // Assert
                Expect(results)
                .To.Contain.Exactly(1)
                .Matched.By(r => r.Path == filePath);
            }
예제 #3
0
            public void FirstLevelResultsShouldHaveCorrectRelativePath()
            {
                // Arrange
                using var tempFolder = new AutoTempFolder();
                var path     = tempFolder.CreateRandomFile();
                var expected = Path.GetFileName(path);
                var sut      = Create(tempFolder);
                // Act
                var results = sut.ListResourcesRecursive();

                // Assert
                Expect(results)
                .To.Contain.Exactly(1)
                .Matched.By(r => r.RelativePath == expected);
            }
예제 #4
0
            public void ShouldSupplyMinusOneForSizeIfUnableToStat()
            {
                // Arrange
                using var tempFolder = new AutoTempFolder();
                var file = tempFolder.CreateRandomFile();
                var stat = new FileInfo(file);
                var sut  = Create(tempFolder);
                // Act
                var results = sut.ListResourcesRecursive();

                File.Delete(file);
                // Assert
                Expect(results.Single()
                       .Size)
                .To.Equal(-1);
            }
예제 #5
0
            public void ShouldSupplySizeOnDemand()
            {
                // Arrange
                using var tempFolder = new AutoTempFolder();
                var file    = tempFolder.CreateRandomFile();
                var stat    = new FileInfo(file);
                var newData = GetRandomBytes((int)stat.Length + 1, (int)stat.Length + 100);
                var sut     = Create(tempFolder);
                // Act
                var results = sut.ListResourcesRecursive();

                File.WriteAllBytes(file, newData);
                // Assert
                Expect(results.Single()
                       .Size)
                .To.Equal(newData.Length);
            }
예제 #6
0
            public void ShouldListResourcesUnderFolders()
            {
                // Arrange
                using var tempFolder = new AutoTempFolder();
                var file1 = tempFolder.CreateRandomFile();
                var sub1  = tempFolder.CreateRandomFolder();
                var file2 = Path.Combine(sub1, CreateRandomFileIn(sub1));
                var file3 = Path.Combine(sub1, CreateRandomFileIn(sub1));
                var sub2  = Path.Combine(sub1, CreateRandomFolderIn(sub1));
                var file4 = Path.Combine(sub2, CreateRandomFileIn(sub2));

                new[]
                {
                    file1,
                    sub1,
                    file2,
                    file3,
                    sub2,
                    file4
                }.ForEach(o => Expect(o)
                          .To.Exist());
                var sut = Create(tempFolder);
                // Act
                var result = sut.ListResourcesRecursive();

                // Assert
                Expect(result)
                .To.Contain.Only(4)
                .Items();
                Expect(result)
                .To.Contain.Exactly(1)
                .Matched.By(o => o.Path == file1);
                Expect(result)
                .To.Contain.Exactly(1)
                .Matched.By(o => o.Path == file2);
                Expect(result)
                .To.Contain.Exactly(1)
                .Matched.By(o => o.Path == file3);
                Expect(result)
                .To.Contain.Exactly(1)
                .Matched.By(o => o.Path == file4);
            }