コード例 #1
0
        public void TestWriteInvalidKey()
        {
            var    config = XmlConfig.From(@"TestFile.xml");
            Action act    = () => config.Write("Invalid:Key:Name", "Value");

            act.Should().Throw <InvalidKeyFormatException>();
        }
コード例 #2
0
        public void TestInvalidFormat()
        {
            Action act = () => XmlConfig.From(@"path\to\invalid\format.pdf");

            //act.Should().Throw<InvalidFileFormatException>(); New version allows any file format
            act.Should().NotThrow();
        }
コード例 #3
0
        public void TestDeleteKey()
        {
            var config = XmlConfig.From(@"TestFile.xml");

            // Global key
            config.Write("GlobalKeyToDelete", "ValueToDelete");
            config.Read("GlobalKeyToDelete").Should().Be("ValueToDelete");

            Action act = () => config.DeleteKey("GlobalKeyToDelete");

            act.Should().NotThrow();

            config.Read("GlobalKeyToDelete").Should().Be(null);

            // Local key
            config.Write("Local:KeyToDelete", "ValueToDelete");
            config.Write("Local:KeyToKeep", "ValueToKeep");
            config.Read("Local:KeyToDelete").Should().Be("ValueToDelete");
            config.Read("Local:KeyToKeep").Should().Be("ValueToKeep");

            act = () => config.DeleteKey("Local:KeyToDelete");
            act.Should().NotThrow();

            config.Read("Local:KeyToDelete").Should().Be(null);
            config.Read("Local:KeyToKeep").Should().Be("ValueToKeep");
        }
コード例 #4
0
        public void TestReadType()
        {
            var config = XmlConfig.From("TestFile.xml");

            // Números enteros
            Action act = () => config.Read <int>("Tipos:Entero");

            act.Should().NotThrow();
            config.Read <int>("Tipos:Entero").Should().Be(1);

            // Números largos
            act = () => config.Read <long>("Tipos:Largo");
            act.Should().NotThrow();
            config.Read <long>("Tipos:Largo").Should().Be(1);

            // Números dobles
            act = () => config.Read <double>("Tipos:Doble");
            act.Should().NotThrow();
            config.Read <double>("Tipos:Doble").Should().Be(1.5d);

            // Números flotantes
            act = () => config.Read <float>("Tipos:Flotante");
            act.Should().NotThrow();
            config.Read <float>("Tipos:Flotante").Should().Be(1.5f);

            // Caracteres
            act = () => config.Read <char>("Tipos:Caracter");
            act.Should().NotThrow();
            config.Read <char>("Tipos:Caracter").Should().Be('h');

            // Booleanos
            act = () => config.Read <bool>("Tipos:Booleano");
            act.Should().NotThrow();
            config.Read <bool>("Tipos:Booleano").Should().Be(false);
        }
コード例 #5
0
        public void TestWriteType()
        {
            var config = XmlConfig.From("TestFile.xml");

            // Número entero
            Action act = () => config.Write("Escrito:Entero", 2);

            act.Should().NotThrow();
            config.Read <int>("Escrito:Entero").Should().Be(2);

            // Número largo
            act = () => config.Write("Escrito:Largo", 2L);
            act.Should().NotThrow();
            config.Read <long>("Escrito:Largo").Should().Be(2);

            // Número doble
            act = () => config.Write("Escrito:Doble", 2.5d);
            act.Should().NotThrow();
            config.Read <double>("Escrito:Doble").Should().Be(2.5d);

            // Número flotante
            act = () => config.Write("Escrito:Flotante", 2.5f);
            act.Should().NotThrow();
            config.Read <float>("Escrito:Flotante").Should().Be(2.5f);

            // Caracteres
            act = () => config.Write("Escrito:Caracter", 'x');
            act.Should().NotThrow();
            config.Read <char>("Escrito:Caracter").Should().Be('x');

            // Booleano
            act = () => config.Write("Escrito:Booleano", true);
            act.Should().NotThrow();
            config.Read <bool>("Escrito:Booleano").Should().Be(true);
        }
コード例 #6
0
        public void TestInvalidKey()
        {
            var    config = XmlConfig.From("TestFile.xml");
            Action act    = () => config.Read("Esta:Clave:Es:Invalida");

            act.Should().Throw <InvalidKeyFormatException>();
        }
コード例 #7
0
        public void TestInvalidJsonFile()
        {
            Action act = () => XmlConfig.From("TestFile.json");

            //act.Should().Throw<InvalidFileFormatException>(); New version allows any file format
            act.Should().NotThrow();
        }
コード例 #8
0
        public void TestIndexAccess()
        {
            var config = XmlConfig.From(@"TestFile.xml");

            config["SettingIndex"] = "100";
            config["SettingIndex"].Should().Be("100");
        }
コード例 #9
0
        public void TestNewDottedFile()
        {
            Action act = () => XmlConfig.From(@"New.File.xml");

            act.Should().NotThrow();

            System.IO.File.Delete("New.File.xml");
        }
コード例 #10
0
        public void TestUpdateGlobal()
        {
            var config = XmlConfig.From(@"TestFile.xml");

            config.Write("GlobalKey", "NewGlobalValue", "Global Comment");

            config.Read("GlobalKey").Should().Be("NewGlobalValue");
        }
コード例 #11
0
        public void UnknownFileTransfer()
        {
            var    iniCio = IniConfig.From("TestFile.ini");
            Action act    = () => iniCio.TransferTo(XmlConfig.From("Incorrecto"));

            //act.Should().Throw<InvalidFileFormatException>(); New version allows any file format
            act.Should().NotThrow();
        }
コード例 #12
0
        public void TestWriteCategorizedKeyNewFormat()
        {
            var    config = XmlConfig.From("TestNewFormat.xml");
            Action act    = () => config.Write("Categoria:OtraClave", "2");

            act.Should().NotThrow();
            config.Read("Categoria:OtraClave").Should().Be("2");
        }
コード例 #13
0
        public void TestWriteOrphanKey()
        {
            var    config = XmlConfig.From("TestFile.xml");
            Action act    = () => config.Write("OtraSinCategoria", "-1");

            act.Should().NotThrow();
            config.Read("OtraSinCategoria").Should().Be("-1");
        }
コード例 #14
0
        public void TestModifyKey()
        {
            var config = XmlConfig.From(@"TestFile.xml");

            config.Write("Multi:Escritura", 100, "Primera escritura");
            config.Write("Multi:Escritura", 200, "Segunda escritura");

            config.Read <int>("Multi:Escritura").Should().Be(200);
        }
コード例 #15
0
        public void TestWriteCommentedKey()
        {
            var    config = XmlConfig.From("TestFile.xml");
            Action act    = () => config.Write("Categoria:Cosa Compleja", "Foo",
                                               "Este ajuste es muy complejo");

            act.Should().NotThrow();
            config.Read("Categoria:Cosa Compleja").Should().Be("Foo");
        }
コード例 #16
0
        public void TestUpdateComment()
        {
            var config = XmlConfig.From(@"TestFile.xml");

            config.Write("Categoria:Comentada", "False", "Nuevo comentario");

            config.Write("Comentarios:Primera", "Foo", "Comentario 1");
            config.Write("Comentarios:Primera", "Bar", "Comentario 2");
        }
コード例 #17
0
        internal static string IconFor(string user)
        {
            var path = Path.Combine(DressingRoom.AppDirectory, "Vestis");

            path = Path.Combine(path, "Profiles");
            path = Path.Combine(path, $"{user}.Wardrobe.xml");
            var config = XmlConfig.From(path);

            return(config.Read("ProfileIcon"));
        }
コード例 #18
0
ファイル: DressingRoom.cs プロジェクト: carlubian/Vestis
        public static void SeeWelcomePage()
        {
            var path = Path.Combine(AppDirectory, "Vestis");

            path = Path.Combine(path, "GlobalSettings.xml");

            var config = XmlConfig.From(path);

            config.Write("WelcomePageSeen", "True");
        }
コード例 #19
0
ファイル: DressingRoom.cs プロジェクト: carlubian/Vestis
        public static bool WelcomePageSeen()
        {
            var path = Path.Combine(AppDirectory, "Vestis");

            path = Path.Combine(path, "GlobalSettings.xml");

            var config = XmlConfig.From(path);

            return(config.Read("WelcomePageSeen") != null);
        }
コード例 #20
0
        public void TestNewPath()
        {
            Action act = () => XmlConfig.From(@"TestFileNewPath.xml");

            act.Should().NotThrow();

            var config = XmlConfig.From(@"TestFileNewPath.xml");

            config.Write("Ajuste:Prueba", "Valor");

            config.Read("Ajuste:Prueba").Should().Be("Valor");
        }
コード例 #21
0
        internal static IEnumerable <string> AllUsers()
        {
            var path = Path.Combine(DressingRoom.AppDirectory, "Vestis");

            path = Path.Combine(path, "GlobalSettings.xml");

            var config = XmlConfig.From(path);

            foreach (var profile in config.SettingsIn("UserProfiles"))
            {
                yield return(profile.Key);
            }
        }
コード例 #22
0
        public void TestSettingsInSectionNewFormat()
        {
            var config = XmlConfig.From(@"TestNewFormat.xml");
            IDictionary <string, string> settings = null;

            Action act = () => settings = config.SettingsIn("Categoria");

            act.Should().NotThrow();

            settings.Should().HaveCountGreaterOrEqualTo(2);
            settings.Should().ContainKeys("SubClave", "Comentada");
            settings.Should().ContainValue("1");
            settings.Should().NotContainKeys("ClaveSinCategoria", "Doble");
        }
コード例 #23
0
        public void TestDeleteSectionNewFormat()
        {
            var config = XmlConfig.From(@"TestNewFormat.xml");

            config.Write("SectionToDelete:Key1", "Foo");
            config.Write("SectionToDelete:Key2", "Bar");

            Action act = () => config.DeleteSection("SectionToDelete");

            act.Should().NotThrow();

            config.Read("SectionToDelete:Key1").Should().Be(null);
            config.Read("SectionToDelete:Key2").Should().Be(null);
        }
コード例 #24
0
        internal static string AddGarment(string user, Garment garment)
        {
            var path = Path.Combine(DressingRoom.AppDirectory, "Vestis");

            path = Path.Combine(path, "Profiles");
            var config = XmlConfig.From(Path.Combine(path, $"{user}.Wardrobe.xml"));

            // Create garment ID
            var clothes = config.Read("Clothes");
            var id      = "";

            if (clothes is "" || clothes is null)
            {
                id = "Garment_01";
            }
コード例 #25
0
        internal static void DeleteUser(string name)
        {
            var path   = Path.Combine(DressingRoom.AppDirectory, "Vestis");
            var config = XmlConfig.From(Path.Combine(path, "GlobalSettings.xml"));

            config.DeleteKey($"UserProfiles:{name}");

            if (Directory.Exists(Path.Combine(path, "Profiles")))
            {
                path = Path.Combine(path, "Profiles");
                if (File.Exists(Path.Combine(path, $"{name}.Wardrobe.xml")))
                {
                    File.Delete(Path.Combine(path, $"{name}.Wardrobe.xml"));
                }
            }
        }
コード例 #26
0
        internal static bool UserExists(string user)
        {
            var path = Path.Combine(DressingRoom.AppDirectory, "Vestis");

            path = Path.Combine(path, "GlobalSettings.xml");

            var config = XmlConfig.From(path);

            foreach (var profile in config.SettingsIn("UserProfiles"))
            {
                if (profile.Key.Equals(user))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #27
0
        internal static void AddUser(string name, string color, string icon)
        {
            // All validation criteria are presumed to be successful.
            var path   = Path.Combine(DressingRoom.AppDirectory, "Vestis");
            var config = XmlConfig.From(Path.Combine(path, "GlobalSettings.xml"));

            config.Write($"UserProfiles:{name}", "Local");

            if (!Directory.Exists(Path.Combine(path, "Profiles")))
            {
                Directory.CreateDirectory(Path.Combine(path, "Profiles"));
            }

            path   = Path.Combine(path, "Profiles");
            config = XmlConfig.From(Path.Combine(path, $"{name}.Wardrobe.xml"));

            config.Write("UserProfile", name);
            config.Write("ProfileColor", color);
            config.Write("ProfileIcon", icon);
        }
コード例 #28
0
        internal static OneOf <IEnumerable <Garment>, IFailure> GarmentsFor(string user)
        {
            var result = new List <Garment>();

            var path = Path.Combine(DressingRoom.AppDirectory, "Vestis");

            path = Path.Combine(path, "Profiles");
            path = Path.Combine(path, $"{user}.Wardrobe.xml");

            if (!File.Exists(path))
            {
                return(new UserHasNoWardrobeFailure(user));
            }

            var config = XmlConfig.From(path);

            if (config.Read("Clothes") is null)
            {
                return(result);
            }
            foreach (var garment in config.Read("Clothes").Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                result.Add(new Garment
                {
                    ID           = garment,
                    Name         = config.Read($"{garment}:Name"),
                    Type         = ClothingTypeUtil.Parse(config.Read($"{garment}:Type")),
                    PurchaseDate = new PurchaseDate(config.Read($"{garment}:PurchaseDate")),
                    ColorTags    = new ReadOnlyCollection <string>(config.Read($"{garment}:ColorTags").Split(' ')),
                    StyleTags    = new ReadOnlyCollection <string>(config.Read($"{garment}:StyleTags").Split(' ')),
                    UserTags     = new ReadOnlyCollection <string>(config.Read($"{garment}:UserTags").Split(' '))
                });
            }

            return(result);
        }
コード例 #29
0
        internal static void EditUser(string oldName, string newName, string color, string icon)
        {
            var path = Path.Combine(DressingRoom.AppDirectory, "Vestis");

            if (!oldName.Equals(newName))
            {
                // Change profile name
                var config = XmlConfig.From(Path.Combine(path, "GlobalSettings.xml"));
                config.DeleteKey($"UserProfiles:{oldName}");
                config.Write($"UserProfiles:{newName}", "Local");

                if (Directory.Exists(Path.Combine(path, "Profiles")))
                {
                    path = Path.Combine(path, "Profiles");
                    if (File.Exists(Path.Combine(path, $"{oldName}.Wardrobe.xml")))
                    {
                        File.Move(Path.Combine(path, $"{oldName}.Wardrobe.xml"), Path.Combine(path, $"{newName}.Wardrobe.xml"));
                        config = XmlConfig.From(Path.Combine(path, $"{newName}.Wardrobe.xml"));
                        config.Write("UserProfile", newName);
                    }
                }
            }

            path = Path.Combine(DressingRoom.AppDirectory, "Vestis");
            // Update profile preferences
            if (Directory.Exists(Path.Combine(path, "Profiles")))
            {
                path = Path.Combine(path, "Profiles");
                if (File.Exists(Path.Combine(path, $"{newName}.Wardrobe.xml")))
                {
                    var config = XmlConfig.From(Path.Combine(path, $"{newName}.Wardrobe.xml"));
                    config.Write("ProfileColor", color);
                    config.Write("ProfileIcon", icon);
                }
            }
        }
コード例 #30
0
        public void TestNonexistantKeyNewFormat()
        {
            var config = XmlConfig.From("TestNewFormat.xml");

            config.Read("NoExiste:EstaClave").Should().BeNull();
        }