public void TestWriteInvalidKey() { var config = XmlConfig.From(@"TestFile.xml"); Action act = () => config.Write("Invalid:Key:Name", "Value"); act.Should().Throw <InvalidKeyFormatException>(); }
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(); }
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"); }
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); }
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); }
public void TestInvalidKey() { var config = XmlConfig.From("TestFile.xml"); Action act = () => config.Read("Esta:Clave:Es:Invalida"); act.Should().Throw <InvalidKeyFormatException>(); }
public void TestInvalidJsonFile() { Action act = () => XmlConfig.From("TestFile.json"); //act.Should().Throw<InvalidFileFormatException>(); New version allows any file format act.Should().NotThrow(); }
public void TestIndexAccess() { var config = XmlConfig.From(@"TestFile.xml"); config["SettingIndex"] = "100"; config["SettingIndex"].Should().Be("100"); }
public void TestNewDottedFile() { Action act = () => XmlConfig.From(@"New.File.xml"); act.Should().NotThrow(); System.IO.File.Delete("New.File.xml"); }
public void TestUpdateGlobal() { var config = XmlConfig.From(@"TestFile.xml"); config.Write("GlobalKey", "NewGlobalValue", "Global Comment"); config.Read("GlobalKey").Should().Be("NewGlobalValue"); }
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(); }
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"); }
public void TestWriteOrphanKey() { var config = XmlConfig.From("TestFile.xml"); Action act = () => config.Write("OtraSinCategoria", "-1"); act.Should().NotThrow(); config.Read("OtraSinCategoria").Should().Be("-1"); }
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); }
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"); }
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"); }
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")); }
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"); }
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); }
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"); }
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); } }
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"); }
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); }
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"; }
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")); } } }
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); }
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); }
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); }
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); } } }
public void TestNonexistantKeyNewFormat() { var config = XmlConfig.From("TestNewFormat.xml"); config.Read("NoExiste:EstaClave").Should().BeNull(); }