DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DbConfigTest.cs
Go to the documentation of this file.
1 using System;
2 using System.IO;
3 using System.Text;
4 
6 
7 using NUnit.Framework;
8 
9 namespace Deveel.Data.Control {
10  [TestFixture]
11  public sealed class DbConfigTest {
12  [Test]
14  Assert.DoesNotThrow(() => DbController.Create());
15  }
16 
17  [Test]
18  public void LoadTest() {
19  StringBuilder sb = new StringBuilder();
20  StringWriter writer = new StringWriter(sb);
21 
22  writer.WriteLine("key1=value1");
23  writer.WriteLine("key2 = on");
24  writer.WriteLine("key3= true");
25  writer.Flush();
26 
27  MemoryStream stream = new MemoryStream(Encoding.GetEncoding("ISO-8859-1").GetBytes(sb.ToString()));
28 
29  DbConfig config = DbConfig.Empty;
30  config.Load(stream);
31 
32  string value = config.GetValue<string>("key1");
33  Assert.IsNotNull(value, "The 'key1' was not set into the config.");
34  Assert.IsNotEmpty(value, "The value of 'key1' is empty.");
35  Assert.AreEqual("value1", value, "The value for 'key1' is not correct.");
36 
37  value = config.GetValue<string>("key2");
38  Assert.IsNotNull(value, "The 'key2' was not set into the config.");
39  Assert.IsNotEmpty(value, "The value of 'key2' is empty.");
40  Assert.AreEqual("on", value, "The value for 'key2' is not correct.");
41 
42  value = config.GetValue<string>("key3");
43  Assert.IsNotNull(value, "The 'key3' was not set into the config.");
44  Assert.IsNotEmpty(value, "The value of 'key3' is empty.");
45  Assert.AreEqual("true", value, "The value for 'key1' is not correct.");
46  }
47 
48  [Test]
49  public void SaveToTest() {
50  DbConfig config = DbConfig.Empty;
51  config.SetValue("key1", "value1");
52  config.SetValue("key2", "on");
53  config.SetValue("key3", "true");
54 
55  MemoryStream stream = new MemoryStream();
56  config.Save(stream);
57 
58  }
59  }
60 }