Skip to content

Commit b1c9ed0

Browse files
author
喵喵大人
authored
Merge pull request #76 from CatLib/feature/1.3.0
Feature/1.3.0
2 parents dc79e8a + 20f8bb2 commit b1c9ed0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2072
-725
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.12
31+
Install-Package CatLib.Core -Version 1.3.0
3232
```
3333

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Compile Include="..\CatLib.Core\CatLib\Facades\Template\SingleManager.cs" Link="CatLib\Facades\Template\SingleManager.cs" />
7070
<Compile Include="..\CatLib.Core\CatLib\IApplication.cs" Link="CatLib\IApplication.cs" />
7171
<Compile Include="..\CatLib.Core\CatLib\IBootstrap.cs" Link="CatLib\IBootstrap.cs" />
72+
<Compile Include="..\CatLib.Core\CatLib\ICoroutineInit.cs" Link="CatLib\ICoroutineInit.cs" />
7273
<Compile Include="..\CatLib.Core\CatLib\IServiceProvider.cs" Link="CatLib\IServiceProvider.cs" />
7374
<Compile Include="..\CatLib.Core\CatLib\IServiceProviderType.cs" Link="CatLib\IServiceProviderType.cs" />
7475
<Compile Include="..\CatLib.Core\CatLib\ServiceProvider.cs" Link="CatLib\ServiceProvider.cs" />
@@ -97,6 +98,7 @@
9798
<Compile Include="..\CatLib.Core\Support\Events\IDispatcher.cs" Link="Support\Events\IDispatcher.cs" />
9899
<Compile Include="..\CatLib.Core\Support\Events\IEvent.cs" Link="Support\Events\IEvent.cs" />
99100
<Compile Include="..\CatLib.Core\Support\Exception\AssertException.cs" Link="Support\Exception\AssertException.cs" />
101+
<Compile Include="..\CatLib.Core\Support\Exception\CodeStandardException.cs" Link="Support\Exception\CodeStandardException.cs" />
100102
<Compile Include="..\CatLib.Core\Support\Exception\RuntimeException.cs" Link="Support\Exception\RuntimeException.cs" />
101103
<Compile Include="..\CatLib.Core\Support\FilterChain\FilterChain.cs" Link="Support\FilterChain\FilterChain.cs" />
102104
<Compile Include="..\CatLib.Core\Support\FilterChain\IFilterChain.cs" Link="Support\FilterChain\IFilterChain.cs" />

src/CatLib.Core.Tests/CatLib.Core.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
<Compile Include="Support\RingBuffer\RingBufferTests.cs" />
5353
<Compile Include="Support\SortSet\SortSetTests.cs" />
5454
<Compile Include="Support\Storage\MemoryStorageTests.cs" />
55+
<Compile Include="Support\Stream\CombineStreamTests.cs" />
5556
<Compile Include="Support\Stream\PipelineStreamTests.cs" />
57+
<Compile Include="Support\Stream\SegmentStreamTests.cs" />
5658
<Compile Include="Support\Stream\StorageStreamTests.cs" />
5759
<Compile Include="Support\Template\ManagerTests.cs" />
5860
<Compile Include="Support\Template\SingleManagerTests.cs" />

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

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
using System;
13+
using System.Collections;
1314
using Microsoft.VisualStudio.TestTools.UnitTesting;
1415

1516
namespace CatLib.Tests
@@ -63,8 +64,32 @@ public void Register()
6364
}
6465
}
6566

67+
public class TestYieldProvider : ServiceProvider
68+
{
69+
public bool IsDone;
70+
public override IEnumerator CoroutineInit()
71+
{
72+
IsDone = true;
73+
yield return 1;
74+
yield return 2;
75+
yield return base.CoroutineInit();
76+
}
77+
}
78+
6679
[TestMethod]
67-
[ExpectedException(typeof(RuntimeException))]
80+
public void TestYieldProviderTest()
81+
{
82+
var app = new Application();
83+
app.Bootstrap();
84+
var test = new TestYieldProvider();
85+
app.Register(test);
86+
app.Init();
87+
88+
Assert.AreEqual(true, test.IsDone);
89+
}
90+
91+
[TestMethod]
92+
[ExpectedException(typeof(CodeStandardException))]
6893
public void RepeatInitTest()
6994
{
7095
var app = MakeApplication();
@@ -171,12 +196,12 @@ public void TestStopRegisterProvider()
171196
}
172197

173198
[TestMethod]
174-
[ExpectedException(typeof(RuntimeException))]
199+
[ExpectedException(typeof(CodeStandardException))]
175200
public void TestInitingRegisterProvider()
176201
{
177202
var application = Application.New();
178203
application.Register(new StopProvider());
179-
application.On<IServiceProvider>(ApplicationEvents.OnIniting, (b) =>
204+
application.On<IServiceProvider>(ApplicationEvents.OnProviderInit, (b) =>
180205
{
181206
application.Register(new TestServiceProvider());
182207
});
@@ -185,7 +210,7 @@ public void TestInitingRegisterProvider()
185210
}
186211

187212
[TestMethod]
188-
[ExpectedException(typeof(RuntimeException))]
213+
[ExpectedException(typeof(CodeStandardException))]
189214
public void TestTerminateRegisterProvider()
190215
{
191216
var application = Application.New();
@@ -263,15 +288,15 @@ public void GetCurrentProcess()
263288
[TestMethod]
264289
public void TestDebugLevel()
265290
{
266-
App.DebugLevel = DebugLevels.Dev;
267-
Assert.AreEqual(DebugLevels.Dev, App.DebugLevel);
291+
App.DebugLevel = DebugLevels.Development;
292+
Assert.AreEqual(DebugLevels.Development, App.DebugLevel);
268293
}
269294

270295
/// <summary>
271296
/// 重复的引导测试
272297
/// </summary>
273298
[TestMethod]
274-
[ExpectedException(typeof(RuntimeException))]
299+
[ExpectedException(typeof(CodeStandardException))]
275300
public void RepeatBootstrap()
276301
{
277302
var app = new Application();
@@ -441,6 +466,22 @@ public void TestIsMainThread()
441466
Assert.AreEqual(true, app.IsMainThread);
442467
}
443468

469+
public class TestRegisterProcessMakeServiceProvider : ServiceProvider
470+
{
471+
public override void Register()
472+
{
473+
App.Make<object>();
474+
}
475+
}
476+
477+
[TestMethod]
478+
[ExpectedException(typeof(CodeStandardException))]
479+
public void TestRegisterProcessMake()
480+
{
481+
var app = MakeApplication();
482+
app.Register(new TestRegisterProcessMakeServiceProvider());
483+
}
484+
444485
private Application MakeApplication()
445486
{
446487
var app = new Application();

src/CatLib.Core.Tests/CatLib/FacaedTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ public void TestNotBind()
190190
public void TestStructBindAndRebound()
191191
{
192192
var app = new Application();
193-
Assert.AreEqual(0, Facade<int>.Instance);
194-
Assert.AreEqual(0, Facade<int>.Instance); // double check
195193
var makeCount = 0;
196194
var binder = app.Bind<int>(() =>
197195
{
@@ -200,7 +198,7 @@ public void TestStructBindAndRebound()
200198
});
201199
Assert.AreEqual(100, Facade<int>.Instance);
202200
Assert.AreEqual(100, Facade<int>.Instance); // double check
203-
Assert.AreEqual(3, makeCount); // 这里为3是因为最开始的facade触发已经引发了解决事件
201+
Assert.AreEqual(2, makeCount);
204202
binder.Unbind();
205203
Assert.AreEqual(0, Facade<int>.Instance);
206204
Assert.AreEqual(0, Facade<int>.Instance); // double check
@@ -211,7 +209,7 @@ public void TestStructBindAndRebound()
211209
});
212210
Assert.AreEqual(200, Facade<int>.Instance);
213211
Assert.AreEqual(200, Facade<int>.Instance); // double check
214-
Assert.AreEqual(6, makeCount);
212+
Assert.AreEqual(5, makeCount); // 其中多出的一个计数是门面的watch导致的。
215213
}
216214

217215
[TestMethod]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525

2626
[assembly: Guid("3c9f4024-910c-4881-a04d-34a6c3a09019")]
2727

28-
[assembly: AssemblyVersion("1.2.0.0")]
29-
[assembly: AssemblyFileVersion("1.2.12.0")]
28+
[assembly: AssemblyVersion("1.3.0.0")]
29+
[assembly: AssemblyFileVersion("1.3.0.0")]

src/CatLib.Core.Tests/Support/Container/BindDataTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,21 @@ public void TestAddOnResolvingWithExtend()
209209
Assert.AreEqual("hello world", data);
210210
}
211211

212+
[TestMethod]
213+
public void TestAddOnResolvingWithExtendNoneInstance()
214+
{
215+
var container = new Container();
216+
var bindData = new BindData(container, "CanAddOnResolving", (app, param) => "hello world", false);
217+
var call = false;
218+
bindData.OnResolving(() =>
219+
{
220+
call = true;
221+
});
222+
var data = bindData.TriggerResolving("hello world");
223+
Assert.AreEqual("hello world", data);
224+
Assert.AreEqual(true, call);
225+
}
226+
212227
/// <summary>
213228
/// 是否能追加到解决事件
214229
/// </summary>

src/CatLib.Core.Tests/Support/Container/ContainerHelperTests.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ public void TestWatch()
265265
container.Instance<IContainer>(container);
266266

267267
var cls = new TestWatchCLass();
268-
container.Watch<IWatchTest>(cls, "OnChange");
269268
container.Instance<IWatchTest>(100);
269+
container.Watch<IWatchTest>(cls, "OnChange");
270270
container.Instance<IWatchTest>(200);
271271

272272
Assert.AreEqual(200, cls.value);
@@ -280,12 +280,12 @@ public void TestWatchLambda()
280280
container.Instance<IContainer>(container);
281281

282282
var isCall = false;
283+
container.Instance<IWatchTest>(new TestData(100));
283284
container.Watch<IWatchTest>((val) =>
284285
{
285286
isCall = true;
286287
Assert.AreEqual(200, val.getValue());
287288
});
288-
container.Instance<IWatchTest>(new TestData(100));
289289
container.Instance<IWatchTest>(new TestData(200));
290290

291291
Assert.AreEqual(true, isCall);
@@ -299,11 +299,11 @@ public void TestWatchLambdaNoParam()
299299
container.Instance<IContainer>(container);
300300

301301
var isCall = false;
302+
container.Instance<IWatchTest>(100);
302303
container.Watch<IWatchTest>(() =>
303304
{
304305
isCall = true;
305306
});
306-
container.Instance<IWatchTest>(100);
307307
container.Instance<IWatchTest>(200);
308308

309309
Assert.AreEqual(true, isCall);
@@ -344,6 +344,16 @@ public void TestReleaseWithObject()
344344
Assert.AreEqual(998, data[1]);
345345
}
346346

347+
[TestMethod]
348+
public void TestSetAlias()
349+
{
350+
var container = new Container();
351+
container.Instance<object>("abc");
352+
container.Alias<string, object>();
353+
354+
Assert.AreEqual("abc", container.Make<string>());
355+
}
356+
347357
/// <summary>
348358
/// 生成容器
349359
/// </summary>
@@ -352,7 +362,7 @@ private Container MakeContainer()
352362
{
353363
var container = new Container();
354364
container.Instance("ContainerHelperTests", this);
355-
container.Instance(container.Type2Service(typeof(ContainerHelperTests)), this);
365+
container.Alias(container.Type2Service(typeof(ContainerHelperTests)), "ContainerHelperTests");
356366
return container;
357367
}
358368
}

0 commit comments

Comments
 (0)