Chapter.Net.FileSystems 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Chapter.Net.FileSystems --version 1.1.0                
NuGet\Install-Package Chapter.Net.FileSystems -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Chapter.Net.FileSystems" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chapter.Net.FileSystems --version 1.1.0                
#r "nuget: Chapter.Net.FileSystems, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Chapter.Net.FileSystems as a Cake Addin
#addin nuget:?package=Chapter.Net.FileSystems&version=1.1.0

// Install Chapter.Net.FileSystems as a Cake Tool
#tool nuget:?package=Chapter.Net.FileSystems&version=1.1.0                

<img src="https://raw.githubusercontent.com/dwndland/Chapter.Net.FileSystems/master/Icon.png" alt="logo" width="64"/>

Chapter.Net.FileSystems Library

Overview

Chapter.Net.FileSystems brings wrappers and extensions to work with the local file system.

Features

  • IDirectory: Gives access to all static Directory.* methods.
  • IFile: Gives access to all static File.* methods.
  • IPath: Gives access to all static Path.* methods.
  • IFileSystem: Gives simple access to the IDirectory, IFile and IPath.
  • Directory Extension: Provides extensions to the Directory accessible directly or by using the IDirectory.

Getting Started

  1. Installation:

    • Install the Chapter.Net.FileSystems library via NuGet Package Manager:
    dotnet add package Chapter.Net.FileSystems
    
  2. IDirectory:

    • Usage
    public class ViewModel : ObservableObject
    {
        private readonly IDirectory _directory;
    
        public ViewModel(IDirectory directory)
        {
            _directory = directory;
        }
    
        public string GetLogFolder()
        {
            var directory = @".\Logs";
            if (!_directory.Exists(directory))
                _directory.CreateDirectory(directory);
            return directory;
        }
    }
    
    [TestFixture]
    public class ViewModelTests
    {
        private Mock<IDirectory> _directory;
        privaze ViewModel _target;
    
        [SetUp]
        public void Setup()
        {
            _directory = new Mock<IDirectory>();
    
            _target = new ViewModel(_directory.Object);
        }
    
        [Test]
        public void GetLogFolder_SubFolderDoesNotExists_CreatesIt()
        {
            _directory.Setup(x => x.Exists(Args.Any<string>())).Returns(false);
    
            var result = _target.GetLogFolder();
    
            _directory.Verify(x => x.CreateDirectory(result), Times.Once);
            Assert.That(result, Is.EqualTo(@".\Logs");
        }
    
        [Test]
        public void GetLogFolder_SubFolderExists_DoesNotCreatIt()
        {
            _directory.Setup(x => x.Exists(Args.Any<string>())).Returns(true);
    
            var result = _target.GetLogFolder();
    
            _directory.Verify(x => x.CreateDirectory(result), Times.Never);
            Assert.That(result, Is.EqualTo(@".\Logs");
        }
    }
    
  3. IFile:

    • Usage
    public class ViewModel : ObservableObject
    {
        private readonly IFile _file;
    
        public ViewModel(IFile file)
        {
            _file = file;
        }
    
        public void CopyTo(string destinationPath)
        {
            var file = @".\Settings.xml";
            if (_file.Exists(file))
                _file.Copy(file, destinationPath);
        }
    }
    
    [TestFixture]
    public class ViewModelTests
    {
        private Mock<IFile> _file;
        privaze ViewModel _target;
    
        [SetUp]
        public void Setup()
        {
            _file = new Mock<IFile>();
    
            _target = new ViewModel(_file.Object);
        }
    
        [Test]
        public void CopyTo_FileExists_CopiesIt()
        {
            _file.Setup(x => x.Exists(Args.Any<string>())).Returns(true);
    
            var result = _target.CopyTo("Destination");
    
            _file.Verify(x => x.Copy(Args.Any<string>(), "Destination"), Times.Once);
        }
    
        [Test]
        public void CopyTo_FileDoesNotExist_DoesNotCopyIt()
        {
            _file.Setup(x => x.Exists(Args.Any<string>())).Returns(false);
    
            var result = _target.CopyTo("Destination");
    
            _file.Verify(x => x.Copy(Args.Any<string>(), "Destination"), Times.Never);
        }
    }
    
  4. IPath:

    • Usage
    public class ViewModel : ObservableObject
    {
        private readonly IDirectory _directory;
        private readonly IPath _path;
    
        public ViewModel(IDirectory directory, IPath path)
        {
            _directory = directory;
            _path = path;
        }
    
        public string GetRelativeTo(string path)
        {
            var currentDir = _directory.GetCurrentDirectory();
            return _path.GetRelativePath(currentDir, path);
        }
    }
    
    [TestFixture]
    public class ViewModelTests
    {
        private Mock<IDirectory> _directory;
        private Mock<IPath> _path;
        privaze ViewModel _target;
    
        [SetUp]
        public void Setup()
        {
            _directory = new Mock<IDirectory>();
            _path = new Mock<IPath>();
    
            _target = new ViewModel(_directory.Object, _path.Object);
        }
    
        [Test]
        public void GetRelativeTo_SubFolder_CreatesRelative()
        {
            _directory.Setup(x => x.GetCurrentDirectory()).Returns(@"C:\MyFolder");
            _path.Setup(x => x.GetRelativePath(@"C:\MyFolder", @"C:\SomethingElse")).Returns(@"..\SomethingElse");
    
            var result = _target.GetRelativeTo(@"C:\SomethingElse");
    
            Assert.That(result, Is.EqualTo(@"..\SomethingElse");
        }
    }
    
  5. IFileSystem:

    • Usage
    public class ViewModel : ObservableObject
    {
        private readonly IFileSystem _fileSystem;
    
        public ViewModel(IFileSystem fileSystem)
        {
            _fileSystem = fileSystem;
        }
    
        public string GetRelativeTo(string path)
        {
            var currentDir = _fileSystem.Directory.GetCurrentDirectory();
            return _fileSystem.Path.GetRelativePath(currentDir, path);
        }
    }
    
    [TestFixture]
    public class ViewModelTests
    {
        private Mock<IFileSystem> _fileSystem;
        private Mock<IDirectory> _directory;
        private Mock<IPath> _path;
        privaze ViewModel _target;
    
        [SetUp]
        public void Setup()
        {
            _directory = new Mock<IDirectory>();
            _path = new Mock<IPath>();
            _fileSystem = new Mock<IFileSystem>();
            _fileSystem.Setup(x => x.File).Returns(_directory.Object);
            _fileSystem.Setup(x => x.Path).Returns(_path.Object);
    
            _target = new ViewModel(_fileSystem.Object);
        }
    
        [Test]
        public void GetRelativeTo_SubFolder_CreatesRelative()
        {
            _directory.Setup(x => x.GetCurrentDirectory()).Returns(@"C:\MyFolder");
            _path.Setup(x => x.GetRelativePath(@"C:\MyFolder", @"C:\SomethingElse")).Returns(@"..\SomethingElse");
    
            var result = _target.GetRelativeTo(@"C:\SomethingElse");
    
            Assert.That(result, Is.EqualTo(@"..\SomethingElse");
        }
    }
    
  6. Directory Extension:

    • Usage
    public class ViewModel : ObservableObject
    {
        public void EnsureCopied(string destination)
        {
            if (!Directory.Exists(destination))
                DirectoryEx.Copy(@"C:\MyData", destination);
        }
    }
    

License

Copyright (c) David Wendland. All rights reserved. Licensed under the MIT License. See LICENSE file in the project root for full license information.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 63 6/7/2024
1.1.0 149 4/1/2024
1.0.0 493 12/23/2023