Esempio n. 1
0
 public IFile GetFile(FilePath path)
 {
     if (!Files.ContainsKey(path))
     {
         Files.Add(path, new FakeFile(this, path));
     }
     return Files[path];
 }
Esempio n. 2
0
            public void Can_See_If_A_Path_Has_An_Extension(string fullPath, bool expected)
            {
                // Given, When
                var path = new FilePath(fullPath);

                // Then
                Assert.Equal(expected, path.HasExtension);
            }
Esempio n. 3
0
 public void Copy(FilePath destination, bool overwrite)
 {
     var file = _fileSystem.GetCreatedFile(destination) as FakeFile;
     if (file != null)
     {
         file.Content = Content;
         file.ContentLength = ContentLength;
     }
 }
Esempio n. 4
0
            public void Can_Get_Extension(string fullPath, string expected)
            {
                // Given, When
                var result = new FilePath(fullPath);
                var extension = result.GetExtension();

                // Then
                Assert.Equal(expected, extension);
            }
Esempio n. 5
0
            public void Same_Asset_Instances_Is_Considered_Equal(bool isCaseSensitive)
            {
                // Given, When
                var comparer = new PathComparer(isCaseSensitive);
                var path = new FilePath("shaders/basic.vert");

                // Then
                Assert.True(comparer.Equals(path, path));
            }
Esempio n. 6
0
            public void Can_Get_Directory_For_File_Path()
            {
                // Given, When
                var path = new FilePath("temp/hello.txt");
                var directory = path.GetDirectory();

                // Then
                Assert.Equal("temp", directory.FullPath);
            }
Esempio n. 7
0
            public void Can_Get_Directory_For_File_Path_In_Root()
            {
                // Given, When
                var path = new FilePath("hello.txt");
                var directory = path.GetDirectory();

                // Then
                Assert.Equal(string.Empty, directory.FullPath);
            }
Esempio n. 8
0
 public IFile GetCreatedFile(FilePath path, string content)
 {
     var file = GetFile(path);
     var stream = file.Open(FileMode.Create, FileAccess.Write, FileShare.None);
     var writer = new StreamWriter(stream);
     writer.Write(content);
     writer.Close();
     stream.Close();
     return file;
 }
Esempio n. 9
0
            public void Can_Change_Extension_Of_Path()
            {
                // Given
                var path = new FilePath("temp/hello.txt");

                // When
                path = path.ChangeExtension(".dat");

                // Then
                Assert.Equal("temp/hello.dat", path.ToString());
            }
Esempio n. 10
0
            public void Different_Paths_Are_Not_Considered_Equal(bool isCaseSensitive)
            {
                // Given, When
                var comparer = new PathComparer(isCaseSensitive);
                var first = new FilePath("shaders/basic.vert");
                var second = new FilePath("shaders/basic.frag");

                // Then
                Assert.False(comparer.Equals(first, second));
                Assert.False(comparer.Equals(second, first));
            }
Esempio n. 11
0
 /// <summary>
 /// Combines the current path with a <see cref="FilePath"/>.
 /// The provided <see cref="FilePath"/> must be absolute.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <returns>A combination of the current path and the provided <see cref="FilePath"/>.</returns>
 public FilePath CombineWithFilePath(FilePath path)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     if (!path.IsRelative)
     {
         throw new InvalidOperationException("Cannot combine a directory path with an absolute file path.");
     }
     var combinedPath = System.IO.Path.Combine(FullPath, path.FullPath);
     return new FilePath(combinedPath);
 }
Esempio n. 12
0
 public void Move(FilePath destination)
 {
     _file.MoveTo(destination.FullPath);
 }
Esempio n. 13
0
            public void Can_Get_Filename_From_Path()
            {
                // Given
                var path = new FilePath("/input/test.txt");

                // When
                var result = path.GetFilename();

                // Then
                Assert.Equal("test.txt", result.FullPath);
            }
Esempio n. 14
0
 public File(FilePath path)
 {
     _path = path;
     _file = new FileInfo(path.FullPath);
 }
Esempio n. 15
0
 public IFile GetCreatedFile(FilePath path)
 {
     var file = GetFile(path);
     file.Open(FileMode.Create, FileAccess.Write, FileShare.None).Close();
     return file;
 }
Esempio n. 16
0
            public void Same_Paths_But_Different_Casing_Are_Considered_Equal_Depending_On_Case_Sensitivity(bool isCaseSensitive, bool expected)
            {
                // Given, When
                var comparer = new PathComparer(isCaseSensitive);
                var first = new FilePath("shaders/basic.vert");
                var second = new FilePath("SHADERS/BASIC.VERT");

                // Then
                Assert.Equal(expected, comparer.Equals(first, second));
                Assert.Equal(expected, comparer.Equals(second, first));
            }
Esempio n. 17
0
            public void Same_Paths_But_Different_Casing_Get_Same_Hash_Code_Depending_On_Case_Sensitivity(bool isCaseSensitive, bool expected)
            {
                // Given, When
                var comparer = new PathComparer(isCaseSensitive);
                var first = new FilePath("shaders/basic.vert");
                var second = new FilePath("SHADERS/BASIC.VERT");

                // Then
                Assert.Equal(expected, comparer.GetHashCode(first) == comparer.GetHashCode(second));
            }
Esempio n. 18
0
        public string GetTextContent(FilePath path)
        {
            var file = GetFile(path) as FakeFile;
            if (file == null)
            {
                throw new InvalidOperationException();
            }

            try
            {
                if (file.Deleted)
                {
                    Files[path].Exists = true;
                }

                using (var stream = file.OpenRead())
                using (var reader = new StreamReader(stream))
                {
                    return reader.ReadToEnd();
                }
            }
            finally
            {
                if (file.Deleted)
                {
                    Files[path].Exists = false;
                }
            }
        }
Esempio n. 19
0
            public void Different_Paths_Get_Different_Hash_Codes(bool isCaseSensitive)
            {
                // Given, When
                var comparer = new PathComparer(isCaseSensitive);
                var first = new FilePath("shaders/basic.vert");
                var second = new FilePath("shaders/basic.frag");

                // Then
                Assert.NotEqual(comparer.GetHashCode(first), comparer.GetHashCode(second));
            }
Esempio n. 20
0
 public void Copy(FilePath destination, bool overwrite)
 {
     _file.CopyTo(destination.FullPath, overwrite);
 }
Esempio n. 21
0
 public FakeFile(FakeFileSystem fileSystem, FilePath path)
 {
     _fileSystem = fileSystem;
     _path = path;
     _exists = false;
 }
Esempio n. 22
0
 public void Move(FilePath destination)
 {
     throw new NotImplementedException();
 }
        public static void LoadExtensions(this IContainer container, DirectoryPath path)
        {
            var fileSystem = container.Resolve<IFileSystem>();
            var finder = container.Resolve<IAssemblyNameFinder>();
            var logger = container.Resolve<ILogger<HadoukenService>>();
            
            var files = fileSystem.GetDirectory(path)
                .GetFiles("*.dll", SearchScope.Current)
                .Select(f => f.Path.FullPath);

            // Search through the path for assemblies to register
            var assemblyNames = finder.GetAssemblyNames<IExtension>(files);

            // The container builder which later updates the provided container
            var builder = new ContainerBuilder();

            foreach (var assemblyName in assemblyNames)
            {
                var filePath = new FilePath(assemblyName.CodeBase);
                logger.Info("Loading extension {FileName}.", filePath.GetFilename());

                var assembly = Assembly.Load(assemblyName);

                // Find extensions, services and custom components
                var extensions = assembly.GetTypesAssignableFrom<IExtension>();
                var services = assembly.GetTypesAssignableFrom<IJsonRpcService>();
                var components = (from type in assembly.GetTypes()
                    where !type.IsAbstract
                    let cattr = type.GetCustomAttribute<ComponentAttribute>()
                    where cattr != null
                    select type);

                // Register extensions
                foreach (var extension in extensions)
                {
                    var attr = extension.GetCustomAttribute<ExtensionAttribute>();
                    if (attr == null) continue;

                    builder.RegisterType(extension)
                        .AsImplementedInterfaces()
                        .SingleInstance();
                }

                // Register JSONRPC services
                foreach (var service in services)
                {
                    builder.RegisterType(service)
                        .As<IJsonRpcService>()
                        .SingleInstance();
                }

                // Register custom components
                foreach (var component in components)
                {
                    var attr = component.GetCustomAttribute<ComponentAttribute>();
                    var registration = builder.RegisterType(component).AsImplementedInterfaces();

                    switch (attr.Lifestyle)
                    {
                        case ComponentLifestyle.Singleton:
                            registration.SingleInstance();
                            break;
                        case ComponentLifestyle.Transient:
                            registration.InstancePerDependency();
                            break;
                    }
                }
            }

            // Update the container
            builder.Update(container);
        }
Esempio n. 24
0
            public void Can_Append_Extension_To_Path(string extension, string expected)
            {
                // Given
                var path = new FilePath("temp/hello.txt");

                // When
                path = path.AppendExtension(extension);

                // Then
                Assert.Equal(expected, path.ToString());
            }
Esempio n. 25
0
 /// <summary>
 /// Combines the current path with the file name of a <see cref="FilePath"/>.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <returns>A combination of the current path and the file name of the provided <see cref="FilePath"/>.</returns>
 public FilePath GetFilePath(FilePath path)
 {
     var combinedPath = System.IO.Path.Combine(FullPath, path.GetFilename().FullPath);
     return new FilePath(combinedPath);
 }