DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SystemTests.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 using System;
16 using System.Collections.Generic;
17 using System.Linq;
18 
19 using Deveel.Data.Services;
20 
21 using NUnit.Framework;
22 
23 namespace Deveel.Data {
24  [TestFixture]
25  public class SystemTests {
26  [Test]
27  public void FromDefaultConfig() {
28  var builder = new SystemBuilder();
29  ISystem system = null;
30  Assert.DoesNotThrow(() => system = builder.BuildSystem());
31  Assert.IsNotNull(system);
32  Assert.IsFalse(system.Context.ReadOnly());
33  Assert.IsTrue(system.Context.IgnoreIdentifiersCase());
34  Assert.AreEqual("APP", system.Context.DefaultSchema());
35  }
36 
37  [Test]
39  var builder = new SystemBuilder();
40  ISystem system = null;
41  Assert.DoesNotThrow(() => system = builder.BuildSystem());
42  Assert.IsNotNull(system);
43 
44  system.Context.RegisterService<TestService>();
45 
46  object serviceObj = null;
47  Assert.DoesNotThrow(() => serviceObj = system.Context.ResolveService(typeof(TestService)));
48  Assert.IsNotNull(serviceObj);
49  Assert.IsInstanceOf<TestService>(serviceObj);
50 
51  var service = (TestService)serviceObj;
52  Assert.DoesNotThrow(() => service.SayHello());
53  }
54 
55  [Test]
57  var builder = new SystemBuilder();
58  ISystem system = null;
59  Assert.DoesNotThrow(() => system = builder.BuildSystem());
60  Assert.IsNotNull(system);
61 
62  system.Context.RegisterService<TestService>();
63  system.Context.RegisterService<TestService2>();
64  system.Context.RegisterService<TestService3>();
65 
66  IEnumerable<ITestService> services = null;
67  Assert.DoesNotThrow(() => services = system.Context.ResolveAllServices<ITestService>());
68  Assert.IsNotNull(services);
69 
70  var serviceList = services.ToList();
71 
72  Assert.IsNotEmpty(serviceList);
73  Assert.AreEqual(2, serviceList.Count);
74  Assert.IsInstanceOf<TestService2>(serviceList[0]);
75  Assert.IsInstanceOf<TestService3>(serviceList[1]);
76  }
77 
78  [Test]
80  var builder = new SystemBuilder();
81  ISystem system = null;
82  Assert.DoesNotThrow(() => system = builder.BuildSystem());
83  Assert.IsNotNull(system);
84 
85  system.Context.RegisterInstance(new TestService());
86  system.Context.RegisterInstance(new TestService2());
87  system.Context.RegisterService<TestService3>();
88 
89  IEnumerable<ITestService> services = null;
90  Assert.DoesNotThrow(() => services = system.Context.ResolveAllServices<ITestService>());
91  Assert.IsNotNull(services);
92 
93  var serviceList = services.ToList();
94 
95  Assert.IsNotEmpty(serviceList);
96  Assert.AreEqual(2, serviceList.Count);
97  Assert.IsInstanceOf<TestService2>(serviceList[0]);
98  Assert.IsInstanceOf<TestService3>(serviceList[1]);
99  }
100 
101  #region TestService
102 
103  class TestService {
104  public void SayHello() {
105  Console.Out.WriteLine("Hello World.");
106  }
107  }
108 
109  #endregion
110 
111  #region ITestService
112 
113  interface ITestService {
114  }
115 
116  #endregion
117 
118  #region TestService2
119 
121 
122  }
123 
124  #endregion
125 
126  #region TestService3
127 
129  }
130 
131  #endregion
132  }
133 }
new ISystemContext Context
Definition: ISystem.cs:27
void ResolveInstanceOfServiceByInterface()
Definition: SystemTests.cs:79
void ResolveManyServicesForInterface()
Definition: SystemTests.cs:56
void ResolveSingleServiceFromRegister()
Definition: SystemTests.cs:38