예제 #1
0
        public void SaveNode_RootHasNoChildren_SavesRootNodeDetails()
        {
            // Arrange
            var rootWithNoChildren = new Directory {
                Name = "Root"
            };
            var fileSystemSerializer = new FileSystemSerializer();

            // Act
            var result = fileSystemSerializer.Serialize(rootWithNoChildren);

            // Assert
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("1,\"Root\",0", result.ElementAt(0));
        }
예제 #2
0
        public void SaveNode_RootWithOneChild_SavesRootAndChildNodeDetails()
        {
            // Arrange
            var rootWithSimpleChild = new Directory {
                Name = "Root"
            };

            rootWithSimpleChild.AddChild(new File {
                Name = "Test"
            });
            var fileSystemSerializer = new FileSystemSerializer();

            // Act
            var result = fileSystemSerializer.Serialize(rootWithSimpleChild);

            // Assert
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("1,\"Root\",1", result.ElementAt(0));
            Assert.AreEqual("0,\"Test\"", result.ElementAt(1));
        }
예제 #3
0
        public static void Main(string[] _args)
        {
            Console.Write(@"Enter path save : ");
            string path = Console.ReadLine();

            if (path != null)
            {
                var fileInfo = new FileInfo(path);
                if (fileInfo.Directory == null || !fileInfo.Directory.Exists)
                {
                    Console.WriteLine($@"Error path {path}");
                    return;
                }
            }


            Console.Write(@"Enter name clusterFile system : ");
            string name = Console.ReadLine();

            if (name == null)
            {
                Console.WriteLine(@"Error name");
                return;
            }

            Console.Write(@"Enter sectors name (separate with ; ) : ");
            string sectorsStr = Console.ReadLine();

            if (sectorsStr == null)
            {
                Console.WriteLine(@"Error sectors name");
                return;
            }

            string[] sectors = null;
            if (sectorsStr.Contains(";"))
            {
                sectors = sectorsStr.Split(';');
            }
            else if (!sectorsStr.Contains(";"))
            {
                sectors = new[] { sectorsStr };
            }
            if (sectors == null)
            {
                Console.WriteLine(@"Error sectors name (empty)!");
                return;
            }
            var listSectors = sectors.Select(_sector => new StructureBloc {
                Name = _sector
            }).ToList();
            var structure = new Structure
            {
                Sectors = new ObservableCollection <StructureBloc>(listSectors)
            };
            var fileSystem = new FileSystem
            {
                Name      = name,
                Structure = structure
            };
            var result = FileSystemSerializer.Serialize(fileSystem, path);

            Console.WriteLine(result ? @"Serialize success" : @"Error serialize");
        }