Skip to content

Commit dc79e8a

Browse files
author
喵喵大人
authored
Merge pull request #53 from CatLib/feature/1.2.12
Feature/1.2.12
2 parents 922a6b6 + b7f6ec0 commit dc79e8a

File tree

19 files changed

+461
-30
lines changed

19 files changed

+461
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
**使用Nuget安装**
2929

3030
```PM
31-
Install-Package CatLib.Core -Version 1.2.11
31+
Install-Package CatLib.Core -Version 1.2.12
3232
```
3333

3434
**直接下载发布版本**

src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
<Compile Include="..\CatLib.Core\CatLib\Events\IGlobalDispatcher.cs" Link="CatLib\Events\IGlobalDispatcher.cs" />
6464
<Compile Include="..\CatLib.Core\CatLib\Events\IOriginalDispatcher.cs" Link="CatLib\Events\IOriginalDispatcher.cs" />
6565
<Compile Include="..\CatLib.Core\CatLib\Facade.cs" Link="CatLib\Facade.cs" />
66+
<Compile Include="..\CatLib.Core\CatLib\Facades\Template\Managed.cs" Link="CatLib\Facades\Template\Managed.cs" />
67+
<Compile Include="..\CatLib.Core\CatLib\Facades\Template\Manager.cs" Link="CatLib\Facades\Template\Manager.cs" />
68+
<Compile Include="..\CatLib.Core\CatLib\Facades\Template\SingleManaged.cs" Link="CatLib\Facades\Template\SingleManaged.cs" />
69+
<Compile Include="..\CatLib.Core\CatLib\Facades\Template\SingleManager.cs" Link="CatLib\Facades\Template\SingleManager.cs" />
6670
<Compile Include="..\CatLib.Core\CatLib\IApplication.cs" Link="CatLib\IApplication.cs" />
6771
<Compile Include="..\CatLib.Core\CatLib\IBootstrap.cs" Link="CatLib\IBootstrap.cs" />
6872
<Compile Include="..\CatLib.Core\CatLib\IServiceProvider.cs" Link="CatLib\IServiceProvider.cs" />
@@ -133,6 +137,7 @@
133137
<ItemGroup>
134138
<Folder Include="..\CatLib.Core\Properties\" />
135139
<Folder Include="CatLib\Events\" />
140+
<Folder Include="CatLib\Facades\Template\" />
136141
<Folder Include="Support\Attribute\" />
137142
<Folder Include="Support\Events\" />
138143
<Folder Include="Support\Exception\" />

src/CatLib.Core.Tests/CatLib/ApplicationTests.cs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void Register()
6464
}
6565

6666
[TestMethod]
67+
[ExpectedException(typeof(RuntimeException))]
6768
public void RepeatInitTest()
6869
{
6970
var app = MakeApplication();
@@ -106,6 +107,98 @@ public void NoBootstrapInit()
106107
});
107108
}
108109

110+
public class StopBootstrap : IBootstrap
111+
{
112+
public string value = string.Empty;
113+
public bool stop = false;
114+
public void Bootstrap()
115+
{
116+
value = "bootstrap";
117+
}
118+
}
119+
120+
[TestMethod]
121+
public void TestStopBootstrap()
122+
{
123+
var bootstrapStopped = new StopBootstrap() { stop = true };
124+
var bootstrapNotStopped = new StopBootstrap();
125+
var application = Application.New();
126+
application.Listen<IBootstrap, object>(ApplicationEvents.Bootstrapping, (b) =>
127+
{
128+
if (((StopBootstrap)b).stop)
129+
{
130+
return false;
131+
}
132+
return null;
133+
});
134+
application.Bootstrap(bootstrapStopped, bootstrapNotStopped);
135+
Assert.AreEqual(string.Empty, bootstrapStopped.value);
136+
Assert.AreEqual("bootstrap", bootstrapNotStopped.value);
137+
}
138+
139+
public class StopProvider : IServiceProvider
140+
{
141+
public string value = string.Empty;
142+
public bool stop = false;
143+
public void Register()
144+
{
145+
value = "register";
146+
}
147+
public void Init()
148+
{
149+
}
150+
}
151+
152+
[TestMethod]
153+
public void TestStopRegisterProvider()
154+
{
155+
var providerStopped = new StopProvider() { stop = true };
156+
var providerNotStopped = new StopProvider();
157+
158+
var application = Application.New();
159+
application.Listen<IServiceProvider, object>(ApplicationEvents.OnRegisterProvider, (b) =>
160+
{
161+
if (((StopProvider)b).stop)
162+
{
163+
return false;
164+
}
165+
return null;
166+
});
167+
application.Register(providerStopped);
168+
application.Register(providerNotStopped);
169+
Assert.AreEqual(string.Empty, providerStopped.value);
170+
Assert.AreEqual("register", providerNotStopped.value);
171+
}
172+
173+
[TestMethod]
174+
[ExpectedException(typeof(RuntimeException))]
175+
public void TestInitingRegisterProvider()
176+
{
177+
var application = Application.New();
178+
application.Register(new StopProvider());
179+
application.On<IServiceProvider>(ApplicationEvents.OnIniting, (b) =>
180+
{
181+
application.Register(new TestServiceProvider());
182+
});
183+
application.Bootstrap();
184+
application.Init();
185+
}
186+
187+
[TestMethod]
188+
[ExpectedException(typeof(RuntimeException))]
189+
public void TestTerminateRegisterProvider()
190+
{
191+
var application = Application.New();
192+
application.Register(new StopProvider());
193+
application.On(ApplicationEvents.OnTerminate, () =>
194+
{
195+
application.Register(new TestServiceProvider());
196+
});
197+
application.Bootstrap();
198+
application.Init();
199+
application.Terminate();
200+
}
201+
109202
/// <summary>
110203
/// 测试终止程序
111204
/// </summary>
@@ -164,7 +257,7 @@ public void TestOn()
164257
public void GetCurrentProcess()
165258
{
166259
var app = MakeApplication();
167-
Assert.AreEqual(Application.StartProcess.Inited, app.Process);
260+
Assert.AreEqual(Application.StartProcess.Running, app.Process);
168261
}
169262

170263
[TestMethod]
@@ -178,13 +271,13 @@ public void TestDebugLevel()
178271
/// 重复的引导测试
179272
/// </summary>
180273
[TestMethod]
274+
[ExpectedException(typeof(RuntimeException))]
181275
public void RepeatBootstrap()
182276
{
183277
var app = new Application();
184278
app.Bootstrap();
185279
app.Init();
186280
app.Bootstrap();
187-
Assert.AreEqual(Application.StartProcess.Inited, app.Process);
188281
}
189282

190283
/// <summary>

src/CatLib.Core.Tests/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
[assembly: Guid("3c9f4024-910c-4881-a04d-34a6c3a09019")]
2727

2828
[assembly: AssemblyVersion("1.2.0.0")]
29-
[assembly: AssemblyFileVersion("1.2.11.0")]
29+
[assembly: AssemblyFileVersion("1.2.12.0")]

src/CatLib.Core.Tests/Support/Util/DictTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public void TestSetRemove()
7777
Assert.AreEqual(false, Dict.Remove(dict, "hello.name.is.world"));
7878
}
7979

80+
[TestMethod]
81+
public void TestSetNotObject()
82+
{
83+
var dict = new Dictionary<string, object>();
84+
dict.Add("string", "string");
85+
Dict.Set(dict, "string.hello", "hello");
86+
}
87+
8088
[TestMethod]
8189
public void TestKeys()
8290
{

src/CatLib.Core.Tests/Support/Util/StreamExtensionTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ public void TestStreamToTextLarage()
5959
Assert.AreEqual(builder.ToString(), stream1.ToText());
6060
}
6161

62+
[TestMethod]
63+
public void TestChineseText()
64+
{
65+
var stream1 = new StorageStream(new MemoryStorage());
66+
var builder = new StringBuilder();
67+
for (var i = 0; i < (ThreadStatic.Buffer.Length / 10) + 1; i++)
68+
{
69+
var data = Encoding.UTF8.GetBytes("12中文34测试的5这是67890");
70+
stream1.Write(data, 0, data.Length);
71+
builder.Append("12中文34测试的5这是67890");
72+
}
73+
stream1.Seek(0, SeekOrigin.Begin);
74+
Assert.AreEqual(builder.ToString(), stream1.ToText());
75+
}
76+
6277
[TestMethod]
6378
public void TestStreamToTextEmpty()
6479
{

src/CatLib.Core/CatLib.Core.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
<Compile Include="CatLib\Events\IGlobalDispatcher.cs" />
4545
<Compile Include="CatLib\Events\IOriginalDispatcher.cs" />
4646
<Compile Include="CatLib\Facade.cs" />
47+
<Compile Include="CatLib\Facades\Template\Managed.cs" />
48+
<Compile Include="CatLib\Facades\Template\Manager.cs" />
49+
<Compile Include="CatLib\Facades\Template\SingleManaged.cs" />
50+
<Compile Include="CatLib\Facades\Template\SingleManager.cs" />
4751
<Compile Include="CatLib\IApplication.cs" />
4852
<Compile Include="CatLib\IBootstrap.cs" />
4953
<Compile Include="CatLib\IServiceProvider.cs" />

src/CatLib.Core/CatLib/App.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static IApplication Handler
4141
{
4242
if (instance == null)
4343
{
44-
Application.New();
44+
return New();
4545
}
4646
return instance;
4747
}
@@ -54,6 +54,15 @@ public static IApplication Handler
5454
}
5555
}
5656
}
57+
58+
/// <summary>
59+
/// 创建CatLib实例
60+
/// </summary>
61+
/// <returns>CatLib实例</returns>
62+
protected static IApplication New()
63+
{
64+
return Application.New();
65+
}
5766
#endregion
5867

5968
#region Application API

0 commit comments

Comments
 (0)