Пример #1
0
        public void MemoryFileSystemProvider_GetLastWriteTimeUtc_ReturnsTimeOfLastModification()
        {
            var provider = new MemoryFileSystemProvider();

            provider.CreateFile("input.dat", "12345");
            Assert.True((provider.GetLastWriteTimeUtc("input.dat") - DateTime.UtcNow) < TimeSpan.FromSeconds(1));
        }
Пример #2
0
        public void MemoryFileSystemProvider_GetFileSize_ReturnsSizeOfFile()
        {
            var provider = new MemoryFileSystemProvider();

            provider.CreateFile("input.dat", "1234567890");
            Assert.Equal(10, provider.GetFileSize("input.dat"));
        }
Пример #3
0
        public void MemoryFileSystemProvider_GetFolderPath_AlwaysReturnsRoot()
        {
            var provider = new MemoryFileSystemProvider();

            Assert.Equal("/", provider.GetFolderPath(Environment.SpecialFolder.ApplicationData));
            Assert.Equal("/", provider.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            Assert.Equal("/", provider.GetFolderPath(Environment.SpecialFolder.Personal));
        }
Пример #4
0
        public void MemoryFileSystemProvider_AppendAllText_CreatesANewFile()
        {
            var provider = new MemoryFileSystemProvider();

            provider.AppendAllText("input.dat", "test-content");

            Assert.True(provider.FileExists("input.dat"));
            Assert.Equal("test-content", provider.OpenText("input.dat").ReadToEnd());
        }
Пример #5
0
        public void MemoryFileSystemProvider_FileExists_ChecksWhetherFileExists()
        {
            var provider = new MemoryFileSystemProvider();

            Assert.False(provider.FileExists("input.dat"));
            Assert.False(provider.FileExists("/input.dat"));
            provider.CreateFile("input.dat");
            Assert.True(provider.FileExists("input.dat"));
            Assert.True(provider.FileExists("/input.dat"));
        }
Пример #6
0
        public void MemoryFileSystemProvider_GetFileName_ReturnsNamePartOfPath()
        {
            var provider = new MemoryFileSystemProvider();

            Assert.Equal("input.dat", provider.GetFileName("input.dat"));
            Assert.Equal("input.dat", provider.GetFileName("/input.dat"));
            Assert.Equal("input.dat", provider.GetFileName("./input.dat"));
            Assert.Equal("input.dat", provider.GetFileName("/home/input.dat"));
            Assert.Equal("input.dat", provider.GetFileName("home/input.dat"));
        }
Пример #7
0
        public void MemoryFileSystemProvider_GetCurrentDirectory_ReturnsCurrentFolder()
        {
            var provider = new MemoryFileSystemProvider();

            Assert.Equal("/", provider.GetCurrentDirectory());

            provider.CreateFolder("home");
            provider.SetCurrentDirectory("home");

            Assert.Equal("/home", provider.GetCurrentDirectory());
        }
Пример #8
0
        public void MemoryFileSystemProvider_DirectoryExists_ChecksWhetherDirectoryExists()
        {
            var provider = new MemoryFileSystemProvider();

            Assert.True(provider.DirectoryExists("/"));

            Assert.False(provider.DirectoryExists("home"));
            Assert.False(provider.DirectoryExists("/home"));
            provider.CreateFolder("home");
            Assert.True(provider.DirectoryExists("home"));
            Assert.True(provider.DirectoryExists("/home"));
        }
Пример #9
0
        public void MemoryFileSystemProvider_PathCombine_CombinesTwoPaths()
        {
            var provider = new MemoryFileSystemProvider();

            Assert.Equal("/absolutepath", provider.PathCombine("something-that-will-be-ignored", "/absolutepath"));
            Assert.Equal("path1/path2", provider.PathCombine("path1", "path2"));
            Assert.Equal("path1/path2", provider.PathCombine("./path1", "./path2"));
            Assert.Equal("/path1/path2", provider.PathCombine("/path1", "path2"));
            Assert.Equal("/path1/path2", provider.PathCombine("/path1", "./path2"));
            Assert.Equal("path1/path2", provider.PathCombine("path1/subpath", "../path2"));
            Assert.Equal("/path1/path2", provider.PathCombine("/path1/subpath/..", "./path2"));
        }
Пример #10
0
        public void MemoryFileSystemProvider_OpenText_ReturnsStreamReader()
        {
            var provider = new MemoryFileSystemProvider();

            provider.CreateFile("input.dat", "12345");

            using (var reader = provider.OpenText("input.dat"))
            {
                string text = reader.ReadToEnd();
                Assert.Equal("12345", text);
            }
        }
Пример #11
0
        public void MemoryFileSystemProvider_CreateText_CreatesNewFileAndTextWriter()
        {
            var provider = new MemoryFileSystemProvider();

            using (var textWriter = provider.CreateText("input.dat"))
            {
                textWriter.Write("test-content");
                textWriter.Close();
            }

            Assert.True(provider.FileExists("input.dat"));
            Assert.Equal("test-content", provider.OpenText("input.dat").ReadToEnd());
        }
Пример #12
0
        public void MemoryFileSystemProvider_GetFullPath_ReturnsAbolutePath()
        {
            var provider = new MemoryFileSystemProvider();

            Assert.Equal("/input.dat", provider.GetFullPath("input.dat"));
            Assert.Equal("/input.dat", provider.GetFullPath("./input.dat"));
            Assert.Equal("/input.dat", provider.GetFullPath("/input.dat"));

            provider.CreateFolder("home");
            provider.SetCurrentDirectory("home");

            Assert.Equal("/home/input.dat", provider.GetFullPath("input.dat"));
            Assert.Equal("/home/input.dat", provider.GetFullPath("./input.dat"));
            Assert.Equal("/home/input.dat", provider.GetFullPath("../home/input.dat"));
            Assert.Equal("/home/input.dat", provider.GetFullPath("/home/input.dat"));
        }
Пример #13
0
        public void MemoryFileSystemProvider_GetFiles_ReturnsCollectionOfFiles()
        {
            var provider = new MemoryFileSystemProvider();

            Assert.False(provider.GetFiles("/").Any());

            provider.CreateFile("input.dat");
            Assert.Single(provider.GetFiles("/"));
            Assert.Equal("/input.dat", provider.GetFiles("/").First());

            provider.CreateFolder("home");
            provider.CreateFile("/home/input1.dat");
            provider.CreateFile("/home/input2.dat");
            Assert.Equal(2, provider.GetFiles("/home").Count());
            Assert.Equal("/home/input1.dat", provider.GetFiles("/home").First());
            Assert.Equal("/home/input2.dat", provider.GetFiles("/home").Last());
        }
Пример #14
0
        public void MemoryFileSystemProvider_CreateFile_CreatesNewFolder()
        {
            var provider = new MemoryFileSystemProvider();

            provider.CreateFolder("home");
            provider.CreateFolder("home/user1");
            provider.CreateFolder("/home/user2");

            provider.SetCurrentDirectory("home");
            provider.CreateFolder("user3");
            provider.CreateFolder("user3/data");

            Assert.True(provider.DirectoryExists("/home"));
            Assert.True(provider.DirectoryExists("/home/user1"));
            Assert.True(provider.DirectoryExists("/home/user2"));
            Assert.True(provider.DirectoryExists("/home/user3"));
            Assert.True(provider.DirectoryExists("/home/user3/data"));
        }
Пример #15
0
        public void MemoryFileSystemProvider_CreateFile_CreatesNewFile()
        {
            var provider = new MemoryFileSystemProvider();

            provider.CreateFile("input1.dat");
            provider.CreateFile("/input2.dat");

            provider.CreateFolder("home");
            provider.CreateFile("/home/input3.dat");

            provider.SetCurrentDirectory("home");
            provider.CreateFile("input4.dat");
            provider.CreateFile("/home/input5.dat");

            Assert.True(provider.FileExists("/input1.dat"));
            Assert.True(provider.FileExists("/input2.dat"));
            Assert.True(provider.FileExists("/home/input3.dat"));
            Assert.True(provider.FileExists("/home/input4.dat"));
            Assert.True(provider.FileExists("/home/input5.dat"));
        }
Пример #16
0
        public void ServiceAPI_IntegrationTests_6()
        {
            var fs = new MemoryFileSystemProvider();

            fs.CreateFile("input.dat", InputText);

            var engine = new ServiceEngine(
                createCustomProvider: mem =>
            {
                return(new ApplicationServiceProvider(
                           fileSystemProviderFactory: () => fs,
                           virtualConsoleProviderFactory: () => new VirtualConsoleProvider(mem.ConsoleInput, mem.ConsoleOutput, mem.ConsoleError)));
            });

            var session  = engine.CreateSession("-f input.dat");
            var response = session.ExecuteCommand("bal checking --account=code");

            Assert.False(response.HasErrors);
            Assert.Equal(BalCheckingOutputText.Replace("\r", "").Trim(), response.OutputText.Trim());
        }
        public async Task <MemoryFileSystemProvider> GetProvider()
        {
            var provider = new MemoryFileSystemProvider();
            var items    = await FileSystemRepository.GetDirectory();

            foreach (var item in items.OrderBy(i => i.Path))
            {
                if (item.Kind == Abstracts.FileSystemItemKind.Folder)
                {
                    provider.CreateFolder(item.Path);
                }
                else if (item.Kind == Abstracts.FileSystemItemKind.File)
                {
                    var content = await FileSystemRepository.GetFileContent(item.Key);

                    provider.AppendAllText(item.Path, content);
                }
            }

            return(provider);
        }