public void ShouldReadConfigWithOneDimension() { var subject = TomlConfig .FromStream(Resources.Load("cascading-sample.toml")) .Read <SampleConfig>(); var root = subject; Check.That(root.Host).IsEqualTo("www.default-hosting.com"); Check.That(root.WebServerRoot).IsEqualTo("/var/sites/default/www"); Check.That(root.Stack).IsEqualTo("java"); Check.That(root.User[0].Name).IsEqualTo("root"); Check.That(root.User[0].Rights).IsEquivalentTo("read", "write", "create", "remove"); var site1 = subject.Site[0]; Check.That(site1.Host).IsEqualTo("www.myproject.com"); Check.That(site1.WebServerRoot).IsEqualTo("/var/sites/myproject/www"); Check.That(site1.Stack).IsEqualTo("php"); Check.That(site1.User[0].Name).IsEqualTo("root"); Check.That(site1.User[0].Rights).IsEquivalentTo("read", "write", "create", "remove"); Check.That(site1.User[1].Name).IsEqualTo("john"); Check.That(site1.User[1].Rights).IsEquivalentTo("read", "write"); var site2 = subject.Site[1]; Check.That(site2.Host).IsEqualTo("www.second-project.com"); Check.That(site2.WebServerRoot).IsEqualTo("/var/sites/second-project/www"); Check.That(site2.Stack).IsEqualTo("haskell"); Check.That(site2.User[0].Name).IsEqualTo("root"); Check.That(site2.User[0].Rights).IsEquivalentTo("read", "write", "create", "remove"); Check.That(site2.User[1].Name).IsEqualTo("jess"); Check.That(site2.User[1].Rights).IsEquivalentTo("read", "write", "remove"); }
public void ShouldReadConfigWith3Levels() { var subject = TomlConfig .FromStream(Resources.Load("sample-3-levels.toml")) .Read <SampleConfigWithTowLevelDimension>(); var root = subject; Check.That(root.Host).IsEqualTo("www.default.com"); Check.That(root.Path).IsEqualTo("/"); Check.That(root.FileType).IsEqualTo("html"); var subDomain = subject.Hosts.Single(x => x.Host == "www.site1.com"); Check.That(subDomain.Path).IsEqualTo("/"); Check.That(subDomain.FileType).IsEqualTo("java"); var subDomainPhpPath = subDomain.Paths.Single(x => x.Path == "/site1/php"); Check.That(subDomainPhpPath.Host).IsEqualTo(subDomain.Host); Check.That(subDomainPhpPath.Path).IsEqualTo("/site1/php"); Check.That(subDomainPhpPath.FileType).IsEqualTo("php"); var subDomainJavaPath = subDomain.Paths.Single(x => x.Path == "/site1/java"); Check.That(subDomainJavaPath.Host).IsEqualTo(subDomain.Host); Check.That(subDomainJavaPath.Path).IsEqualTo("/site1/java"); Check.That(subDomainJavaPath.FileType).IsEqualTo("java"); var subDomain2Path2 = subject.Hosts.Single(x => x.Host == "www.site2.com") .Paths.Single(x => x.Path == "/site2/dotnet"); Check.That(subDomain2Path2.FileType).IsEqualTo("dotnet"); }
public void ArrayValuesCanNotBeAssignedToNonArrayProperties() { Check.ThatCode(() => TomlConfig.FromStream(Resources.Load("array-type-mismatch.toml")).Read <ArrayTestConfig>()) .Throws <TomlConfigurationException>() .AndWhichMessage() .Contains("System.Int32"); }
public void ShouldInheritNonSpecifiedValuesFromParent() { var subject = TomlConfig .FromStream(Resources.Load("cascading-sample.toml")) .Read <SampleConfig>(); Check.That(subject.Site.Select(x => x.CopyRight).Distinct()) .IsEquivalentTo("ACME LTD."); }
public void ShouldReadWithDefaultValues() { var @default = new SampleConfig { PiValue = 3.14159254f }; var objectInstance = TomlConfig .FromStream(Resources.Load("read.toml")) .ReadWithDefault(@default); Check.That(objectInstance.PiValue) .IsEqualTo(@default.PiValue); }
public void ShouldOverrideProperties() { var over = "overridden"; var subject = TomlConfig.FromStream(Resources.Load("multi-level.toml")) .WithOverrides(new Dictionary <string, string> { { "Value", "42" }, { "Path", over } }) .Read <MultiLevelConfig>(); foreach (var entry in subject.GetAllConfigEntries(x => x.SubPaths)) { Check.That(entry.Value).IsEqualTo(42); Check.That(entry.Path).IsEqualTo(over); } }
public void ShouldReadStreamToObject() { var instance = TomlConfig .FromStream(Resources.Load("read.toml")) .Read <SampleConfig>(); Check.That(instance.Value).IsEqualTo("Simple Value"); Check.That(instance.IntValue).IsEqualTo(42); Check.That(instance.FloatValue).IsEqualTo(3.14); Check.That(instance.BooleanValue).IsEqualTo(true); Check.That(instance.LocalDateTime).IsEqualTo(new DateTime(2002, 5, 27, 7, 32, 0)); Check.That(instance.DateTimeOffset).IsEqualTo(new DateTime(2002, 5, 27, 16, 32, 0, DateTimeKind.Local)); Check.That(instance.LocalTime.TimeOfDay).IsEqualTo(new TimeSpan(0, 7, 32, 0)); Check.That(instance.Array).IsEqualTo(new[] { 1, 2, 3 }); Check.That(instance.Database.User).IsEqualTo("root"); Check.That(instance.Database.Port).IsEqualTo(5432); Check.That(instance.Account[0].UserName).IsEqualTo("root"); Check.That(instance.Account[0].IsAdmin).IsEqualTo(true); Check.That(instance.Account[1].UserName).IsEqualTo("guest"); Check.That(instance.Account[1].IsAdmin).IsEqualTo(false); }
public void ShouldFailWithExpectedErrorIfFieldIsMissingOnTheType() { Check.ThatCode(() => TomlConfig.FromStream(Resources.Load("missing-field.toml")).Read <SampleConfig>()) .Throws <TomlConfigurationException>().AndWhichMessage() .Contains("MagicValue"); }