< Summary

Line coverage
10%
Covered lines: 3
Uncovered lines: 27
Coverable lines: 30
Total lines: 165
Line coverage: 10%
Branch coverage
8%
Covered branches: 2
Total branches: 24
Branch coverage: 8.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
File 1: Create(...)0%40%
File 1: Create(...)0%60%
File 1: Create(...)0%20%
File 2: Create(...)50%460%
File 2: Create(...)0%60%
File 2: Create(...)0%20%

File(s)

C:\projects\jeremyansel-io-locator\JeremyAnsel.IO.Locator\JeremyAnsel.IO.Locator\FileLocatorFactory.cs

#LineLine coverage
 1// <copyright file="FileLocatorFactory.cs" company="Jérémy Ansel">
 2// Copyright (c) 2015, 2019 Jérémy Ansel
 3// </copyright>
 4// <license>
 5// Licensed under the MIT license. See LICENSE.txt
 6// </license>
 7
 8namespace JeremyAnsel.IO.Locator
 9{
 10    using System;
 11    using System.IO;
 12
 13    /// <summary>
 14    /// A factory to create a file locator.
 15    /// </summary>
 16    /// <remarks>
 17    /// The supported formats are: file system, Zip, Rar, Tar, 7Zip, GZip.
 18    /// </remarks>
 19    public static class FileLocatorFactory
 20    {
 21        /// <summary>
 22        /// Creates a file locator.
 23        /// </summary>
 24        /// <param name="root">The root path.</param>
 25        /// <returns>A file locator.</returns>
 26        public static IFileLocator Create(string root)
 27        {
 028            if (string.IsNullOrEmpty(root))
 29            {
 030                throw new ArgumentNullException(nameof(root));
 31            }
 32
 033            if (Path.HasExtension(root))
 34            {
 035                return new ArchiveFileLocator(root);
 36            }
 37
 038            return new SystemFileLocator(root);
 39        }
 40
 41        /// <summary>
 42        /// Creates a file locator from a file locator.
 43        /// </summary>
 44        /// <param name="locator">The source file locator.</param>
 45        /// <param name="root">The root path.</param>
 46        /// <returns>A file locator.</returns>
 47        public static IFileLocator Create(IFileLocator locator, string root)
 48        {
 049            if (locator == null)
 50            {
 051                throw new ArgumentNullException(nameof(locator));
 52            }
 53
 054            if (root == null)
 55            {
 056                throw new ArgumentNullException(nameof(root));
 57            }
 58
 059            if (Path.HasExtension(root))
 60            {
 061                return new ArchiveFileLocator(locator, root);
 62            }
 63
 064            return new SystemFileLocator(locator, root);
 65        }
 66
 67        /// <summary>
 68        /// Creates a file locator from a stream.
 69        /// </summary>
 70        /// <param name="root">A stream.</param>
 71        /// <returns>A file locator.</returns>
 72        public static IFileLocator Create(Stream root)
 73        {
 074            if (root == null)
 75            {
 076                throw new ArgumentNullException(nameof(root));
 77            }
 78
 079            return new ArchiveFileLocator(root);
 80        }
 81    }
 82}

https://raw.githubusercontent.com/JeremyAnsel/JeremyAnsel.IO.Locator/16c8f4344390c6376cd2208cc1ae63a39862df37/JeremyAnsel.IO.Locator/JeremyAnsel.IO.Locator/FileLocatorFactory.cs

#LineLine coverage
 1// <copyright file="FileLocatorFactory.cs" company="Jérémy Ansel">
 2// Copyright (c) 2015, 2019 Jérémy Ansel
 3// </copyright>
 4// <license>
 5// Licensed under the MIT license. See LICENSE.txt
 6// </license>
 7
 8namespace JeremyAnsel.IO.Locator
 9{
 10    using System;
 11    using System.IO;
 12
 13    /// <summary>
 14    /// A factory to create a file locator.
 15    /// </summary>
 16    /// <remarks>
 17    /// The supported formats are: file system, Zip, Rar, Tar, 7Zip, GZip.
 18    /// </remarks>
 19    public static class FileLocatorFactory
 20    {
 21        /// <summary>
 22        /// Creates a file locator.
 23        /// </summary>
 24        /// <param name="root">The root path.</param>
 25        /// <returns>A file locator.</returns>
 26        public static IFileLocator Create(string root)
 27        {
 428            if (string.IsNullOrEmpty(root))
 29            {
 030                throw new ArgumentNullException(nameof(root));
 31            }
 32
 433            if (Path.HasExtension(root))
 34            {
 435                return new ArchiveFileLocator(root);
 36            }
 37
 038            return new SystemFileLocator(root);
 39        }
 40
 41        /// <summary>
 42        /// Creates a file locator from a file locator.
 43        /// </summary>
 44        /// <param name="locator">The source file locator.</param>
 45        /// <param name="root">The root path.</param>
 46        /// <returns>A file locator.</returns>
 47        public static IFileLocator Create(IFileLocator locator, string root)
 48        {
 049            if (locator == null)
 50            {
 051                throw new ArgumentNullException(nameof(locator));
 52            }
 53
 054            if (root == null)
 55            {
 056                throw new ArgumentNullException(nameof(root));
 57            }
 58
 059            if (Path.HasExtension(root))
 60            {
 061                return new ArchiveFileLocator(locator, root);
 62            }
 63
 064            return new SystemFileLocator(locator, root);
 65        }
 66
 67        /// <summary>
 68        /// Creates a file locator from a stream.
 69        /// </summary>
 70        /// <param name="root">A stream.</param>
 71        /// <returns>A file locator.</returns>
 72        public static IFileLocator Create(Stream root)
 73        {
 074            if (root == null)
 75            {
 076                throw new ArgumentNullException(nameof(root));
 77            }
 78
 079            return new ArchiveFileLocator(root);
 80        }
 81    }
 82}
 83