Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
**使用Nuget安装**

```PM
Install-Package CatLib.Core -Version 1.2.12
Install-Package CatLib.Core -Version 1.3.0
```

**直接下载发布版本**
Expand Down
2 changes: 2 additions & 0 deletions src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<Compile Include="..\CatLib.Core\CatLib\Facades\Template\SingleManager.cs" Link="CatLib\Facades\Template\SingleManager.cs" />
<Compile Include="..\CatLib.Core\CatLib\IApplication.cs" Link="CatLib\IApplication.cs" />
<Compile Include="..\CatLib.Core\CatLib\IBootstrap.cs" Link="CatLib\IBootstrap.cs" />
<Compile Include="..\CatLib.Core\CatLib\ICoroutineInit.cs" Link="CatLib\ICoroutineInit.cs" />
<Compile Include="..\CatLib.Core\CatLib\IServiceProvider.cs" Link="CatLib\IServiceProvider.cs" />
<Compile Include="..\CatLib.Core\CatLib\IServiceProviderType.cs" Link="CatLib\IServiceProviderType.cs" />
<Compile Include="..\CatLib.Core\CatLib\ServiceProvider.cs" Link="CatLib\ServiceProvider.cs" />
Expand Down Expand Up @@ -97,6 +98,7 @@
<Compile Include="..\CatLib.Core\Support\Events\IDispatcher.cs" Link="Support\Events\IDispatcher.cs" />
<Compile Include="..\CatLib.Core\Support\Events\IEvent.cs" Link="Support\Events\IEvent.cs" />
<Compile Include="..\CatLib.Core\Support\Exception\AssertException.cs" Link="Support\Exception\AssertException.cs" />
<Compile Include="..\CatLib.Core\Support\Exception\CodeStandardException.cs" Link="Support\Exception\CodeStandardException.cs" />
<Compile Include="..\CatLib.Core\Support\Exception\RuntimeException.cs" Link="Support\Exception\RuntimeException.cs" />
<Compile Include="..\CatLib.Core\Support\FilterChain\FilterChain.cs" Link="Support\FilterChain\FilterChain.cs" />
<Compile Include="..\CatLib.Core\Support\FilterChain\IFilterChain.cs" Link="Support\FilterChain\IFilterChain.cs" />
Expand Down
2 changes: 2 additions & 0 deletions src/CatLib.Core.Tests/CatLib.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
<Compile Include="Support\RingBuffer\RingBufferTests.cs" />
<Compile Include="Support\SortSet\SortSetTests.cs" />
<Compile Include="Support\Storage\MemoryStorageTests.cs" />
<Compile Include="Support\Stream\CombineStreamTests.cs" />
<Compile Include="Support\Stream\PipelineStreamTests.cs" />
<Compile Include="Support\Stream\SegmentStreamTests.cs" />
<Compile Include="Support\Stream\StorageStreamTests.cs" />
<Compile Include="Support\Template\ManagerTests.cs" />
<Compile Include="Support\Template\SingleManagerTests.cs" />
Expand Down
55 changes: 48 additions & 7 deletions src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

using System;
using System.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CatLib.Tests
Expand Down Expand Up @@ -63,8 +64,32 @@ public void Register()
}
}

public class TestYieldProvider : ServiceProvider
{
public bool IsDone;
public override IEnumerator CoroutineInit()
{
IsDone = true;
yield return 1;
yield return 2;
yield return base.CoroutineInit();
}
}

[TestMethod]
[ExpectedException(typeof(RuntimeException))]
public void TestYieldProviderTest()
{
var app = new Application();
app.Bootstrap();
var test = new TestYieldProvider();
app.Register(test);
app.Init();

Assert.AreEqual(true, test.IsDone);
}

[TestMethod]
[ExpectedException(typeof(CodeStandardException))]
public void RepeatInitTest()
{
var app = MakeApplication();
Expand Down Expand Up @@ -171,12 +196,12 @@ public void TestStopRegisterProvider()
}

[TestMethod]
[ExpectedException(typeof(RuntimeException))]
[ExpectedException(typeof(CodeStandardException))]
public void TestInitingRegisterProvider()
{
var application = Application.New();
application.Register(new StopProvider());
application.On<IServiceProvider>(ApplicationEvents.OnIniting, (b) =>
application.On<IServiceProvider>(ApplicationEvents.OnProviderInit, (b) =>
{
application.Register(new TestServiceProvider());
});
Expand All @@ -185,7 +210,7 @@ public void TestInitingRegisterProvider()
}

[TestMethod]
[ExpectedException(typeof(RuntimeException))]
[ExpectedException(typeof(CodeStandardException))]
public void TestTerminateRegisterProvider()
{
var application = Application.New();
Expand Down Expand Up @@ -263,15 +288,15 @@ public void GetCurrentProcess()
[TestMethod]
public void TestDebugLevel()
{
App.DebugLevel = DebugLevels.Dev;
Assert.AreEqual(DebugLevels.Dev, App.DebugLevel);
App.DebugLevel = DebugLevels.Development;
Assert.AreEqual(DebugLevels.Development, App.DebugLevel);
}

/// <summary>
/// 重复的引导测试
/// </summary>
[TestMethod]
[ExpectedException(typeof(RuntimeException))]
[ExpectedException(typeof(CodeStandardException))]
public void RepeatBootstrap()
{
var app = new Application();
Expand Down Expand Up @@ -441,6 +466,22 @@ public void TestIsMainThread()
Assert.AreEqual(true, app.IsMainThread);
}

public class TestRegisterProcessMakeServiceProvider : ServiceProvider
{
public override void Register()
{
App.Make<object>();
}
}

[TestMethod]
[ExpectedException(typeof(CodeStandardException))]
public void TestRegisterProcessMake()
{
var app = MakeApplication();
app.Register(new TestRegisterProcessMakeServiceProvider());
}

private Application MakeApplication()
{
var app = new Application();
Expand Down
6 changes: 2 additions & 4 deletions src/CatLib.Core.Tests/CatLib/FacaedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ public void TestNotBind()
public void TestStructBindAndRebound()
{
var app = new Application();
Assert.AreEqual(0, Facade<int>.Instance);
Assert.AreEqual(0, Facade<int>.Instance); // double check
var makeCount = 0;
var binder = app.Bind<int>(() =>
{
Expand All @@ -200,7 +198,7 @@ public void TestStructBindAndRebound()
});
Assert.AreEqual(100, Facade<int>.Instance);
Assert.AreEqual(100, Facade<int>.Instance); // double check
Assert.AreEqual(3, makeCount); // 这里为3是因为最开始的facade触发已经引发了解决事件
Assert.AreEqual(2, makeCount);
binder.Unbind();
Assert.AreEqual(0, Facade<int>.Instance);
Assert.AreEqual(0, Facade<int>.Instance); // double check
Expand All @@ -211,7 +209,7 @@ public void TestStructBindAndRebound()
});
Assert.AreEqual(200, Facade<int>.Instance);
Assert.AreEqual(200, Facade<int>.Instance); // double check
Assert.AreEqual(6, makeCount);
Assert.AreEqual(5, makeCount); // 其中多出的一个计数是门面的watch导致的。
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions src/CatLib.Core.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@

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

[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.12.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
15 changes: 15 additions & 0 deletions src/CatLib.Core.Tests/Support/Container/BindDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ public void TestAddOnResolvingWithExtend()
Assert.AreEqual("hello world", data);
}

[TestMethod]
public void TestAddOnResolvingWithExtendNoneInstance()
{
var container = new Container();
var bindData = new BindData(container, "CanAddOnResolving", (app, param) => "hello world", false);
var call = false;
bindData.OnResolving(() =>
{
call = true;
});
var data = bindData.TriggerResolving("hello world");
Assert.AreEqual("hello world", data);
Assert.AreEqual(true, call);
}

/// <summary>
/// 是否能追加到解决事件
/// </summary>
Expand Down
18 changes: 14 additions & 4 deletions src/CatLib.Core.Tests/Support/Container/ContainerHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ public void TestWatch()
container.Instance<IContainer>(container);

var cls = new TestWatchCLass();
container.Watch<IWatchTest>(cls, "OnChange");
container.Instance<IWatchTest>(100);
container.Watch<IWatchTest>(cls, "OnChange");
container.Instance<IWatchTest>(200);

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

var isCall = false;
container.Instance<IWatchTest>(new TestData(100));
container.Watch<IWatchTest>((val) =>
{
isCall = true;
Assert.AreEqual(200, val.getValue());
});
container.Instance<IWatchTest>(new TestData(100));
container.Instance<IWatchTest>(new TestData(200));

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

var isCall = false;
container.Instance<IWatchTest>(100);
container.Watch<IWatchTest>(() =>
{
isCall = true;
});
container.Instance<IWatchTest>(100);
container.Instance<IWatchTest>(200);

Assert.AreEqual(true, isCall);
Expand Down Expand Up @@ -344,6 +344,16 @@ public void TestReleaseWithObject()
Assert.AreEqual(998, data[1]);
}

[TestMethod]
public void TestSetAlias()
{
var container = new Container();
container.Instance<object>("abc");
container.Alias<string, object>();

Assert.AreEqual("abc", container.Make<string>());
}

/// <summary>
/// 生成容器
/// </summary>
Expand All @@ -352,7 +362,7 @@ private Container MakeContainer()
{
var container = new Container();
container.Instance("ContainerHelperTests", this);
container.Instance(container.Type2Service(typeof(ContainerHelperTests)), this);
container.Alias(container.Type2Service(typeof(ContainerHelperTests)), "ContainerHelperTests");
return container;
}
}
Expand Down
Loading