コード例 #1
0
		public void Can_Parse_String_Values()
		{
			var reader = new FakeConfigReader();

			reader.Get<string>("text").Should().Be("text");
			reader.Get<string>(String.Empty).Should().BeEmpty();
		}
コード例 #2
0
		public void Cannot_Parse_Values_Of_Unkown_Type()
		{
			Action action;
			var reader = new FakeConfigReader();

			action = () => reader.Get<NullConfigReader>("name");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Cannot read configuration value of unknown type NullConfigReader.");
		}
コード例 #3
0
		public void Can_Parse_Boolean_Values()
		{
			Action action;
			var reader = new FakeConfigReader();

			reader.Get<bool>("true").Should().BeTrue();
			reader.Get<bool>("True").Should().BeTrue();
			reader.Get<bool>("TRUE").Should().BeTrue();
			reader.Get<bool>("TrUe").Should().BeTrue();

			reader.Get<bool>("false").Should().BeFalse();
			reader.Get<bool>("False").Should().BeFalse();
			reader.Get<bool>("FALSE").Should().BeFalse();
			reader.Get<bool>("FaLsE").Should().BeFalse();

			action = () => reader.Get<bool>("yes");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter 'yes' should contain value of type Boolean.");
		}
コード例 #4
0
		public void Can_Parse_Byte_Values()
		{
			Action action;
			var reader = new FakeConfigReader();

			reader.Get<byte>("25").Should().Be(25);

			action = () => reader.Get<byte>("-38");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter '-38' should contain value of type Byte.");

			action = () => reader.Get<byte>("1000");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter '1000' should contain value of type Byte.");

			action = () => reader.Get<byte>("NaN");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter 'NaN' should contain value of type Byte.");
		}
コード例 #5
0
		public void Can_Parse_Enum_Values()
		{
			Action action;
			var reader = new FakeConfigReader();

			reader.Get<FakeEnum>("Zero").Should().Be(FakeEnum.Zero);
			reader.Get<FakeEnum>("one").Should().Be(FakeEnum.One);
			reader.Get<FakeEnum>("TWO").Should().Be(FakeEnum.Two);
			reader.Get<FakeEnum>("0").Should().Be(FakeEnum.Zero);
			reader.Get<FakeEnum>("1").Should().Be(FakeEnum.One);
			reader.Get<FakeEnum>("2").Should().Be(FakeEnum.Two);
			reader.Get<FakeEnum>("3").Should().NotBe(FakeEnum.Zero)
				.And.Should().NotBe(FakeEnum.One)
				.And.Should().NotBe(FakeEnum.Two);

			action = () => reader.Get<FakeEnum>("unknown");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter 'unknown' should contain value of type FakeEnum.");
		}
コード例 #6
0
		public void Can_Parse_Guid_Values()
		{
			Action action;
			var reader = new FakeConfigReader();

			Guid id = new Guid("2DC0B86E-3E16-445A-88B8-C39EFF611331");
			reader.Get<Guid>("{2DC0B86E-3E16-445A-88B8-C39EFF611331}").Should().Be(id);
			reader.Get<Guid>("2DC0B86E-3E16-445A-88B8-C39EFF611331").Should().Be(id);
			reader.Get<Guid>("2dc0b86e-3e16-445a-88b8-c39eff611331").Should().Be(id);
			reader.Get<Guid>("2dc0b86e3e16445a88b8c39eff611331").Should().Be(id);

			action = () => reader.Get<Guid>("unknown");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter 'unknown' should contain value of type Guid.");
		}
コード例 #7
0
		public void Can_Parse_DateTime_Values()
		{
			Action action;
			var reader = new FakeConfigReader();

			reader.Get<DateTime>("1983-05-25").Should().Be(new DateTime(1983, 05, 25));
			reader.Get<DateTime>("2000-11-21 15:20:57").Should().Be(new DateTime(2000, 11, 21, 15, 20, 57));
			reader.Get<DateTime>("2000/11/21 15:20:57").Should().Be(new DateTime(2000, 11, 21, 15, 20, 57));

			action = () => reader.Get<DateTime>("unknown");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter 'unknown' should contain value of type DateTime.");
		}
コード例 #8
0
		public void Can_Parse_TimeSpan_Values()
		{
			Action action;
			var reader = new FakeConfigReader();

			reader.Get<TimeSpan>("15:20:57").Should().Be(TimeSpan.Parse("15:20:57"));
			reader.Get<TimeSpan>("25:20:57").Should().Be(TimeSpan.Parse("25:20:57"));
			reader.Get<TimeSpan>("1:15:20:57").Should().Be(TimeSpan.Parse("1:15:20:57"));

			action = () => reader.Get<TimeSpan>("unknown");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter 'unknown' should contain value of type TimeSpan.");
		}
コード例 #9
0
		public void Can_Parse_Decimal_Values()
		{
			Action action;
			var reader = new FakeConfigReader();

			reader.Get<decimal>("2.5").Should().Be(2.5m);
			reader.Get<decimal>("-0.2").Should().Be(-0.2m);
			reader.Get<decimal>("1000").Should().Be(1000m);
			reader.Get<decimal>("0.12345678901234567890").Should().Be(0.12345678901234567890m);

			action = () => reader.Get<decimal>("NaN");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter 'NaN' should contain value of type Decimal.");

			action = () => reader.Get<decimal>("Infinity");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter 'Infinity' should contain value of type Decimal.");

			reader.Get<decimal>("0").Should().Be(0);
			reader.Get<decimal>("+0").Should().Be(0);
			reader.Get<decimal>("-0").Should().Be(0);

			action = () => reader.Get<decimal>("100000000000000000000000000000");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter '100000000000000000000000000000' should contain value of type Decimal.");
		}
コード例 #10
0
		public void Can_Parse_Double_Values()
		{
			Action action;
			var reader = new FakeConfigReader();

			reader.Get<double>("2.5").Should().Be(2.5d);
			reader.Get<double>("-0.2").Should().Be(-0.2d);
			reader.Get<double>("1000").Should().Be(1000d);
			reader.Get<double>("3.4e-12").Should().Be(3.4e-12d);

			reader.Get<double>("NaN").Should().Be(Double.NaN);
			reader.Get<double>("-Infinity").Should().Be(Double.NegativeInfinity);
			reader.Get<double>("Infinity").Should().Be(Double.PositiveInfinity);

			action = () => reader.Get<double>("+Infinity");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter '+Infinity' should contain value of type Double.");

			reader.Get<double>("0").Should().Be(0);
			reader.Get<double>("+0").Should().Be(0);
			reader.Get<double>("-0").Should().Be(0);

			action = () => reader.Get<double>("1e309");
			action.ShouldThrow<ConfigurationException>()
				.WithMessage("Configuration parameter '1e309' should contain value of type Double.");
		}