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 CatLib.Core.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2002
VisualStudioVersion = 15.0.27130.2036
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatLib.Core", "src\CatLib.Core\CatLib.Core.csproj", "{4204658E-81FD-4106-A347-890CD369C8A4}"
EndProject
Expand Down
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.5
Install-Package CatLib.Core -Version 1.2.6
```

**直接下载发布版本**
Expand Down
12 changes: 9 additions & 3 deletions src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG;NETSTANDARD2_0;CATLIB;</DefineConstants>
<DefineConstants>TRACE;DEBUG;NETSTANDARD2_0;CATLIB;CATLIB_PERFORMANCE;NETSTANDARD2_0</DefineConstants>
<DocumentationFile></DocumentationFile>
</PropertyGroup>

Expand All @@ -58,11 +58,16 @@
<Compile Include="..\CatLib.Core\CatLib\Application.cs" Link="CatLib\Application.cs" />
<Compile Include="..\CatLib.Core\CatLib\ApplicationEvents.cs" Link="CatLib\ApplicationEvents.cs" />
<Compile Include="..\CatLib.Core\CatLib\DebugLevels.cs" Link="CatLib\DebugLevels.cs" />
<Compile Include="..\CatLib.Core\CatLib\Events\DispatcherExtend.cs" Link="CatLib\Events\DispatcherExtend.cs" />
<Compile Include="..\CatLib.Core\CatLib\Events\GlobalDispatcher.cs" Link="CatLib\Events\GlobalDispatcher.cs" />
<Compile Include="..\CatLib.Core\CatLib\Events\IGlobalDispatcher.cs" Link="CatLib\Events\IGlobalDispatcher.cs" />
<Compile Include="..\CatLib.Core\CatLib\Events\IOriginalDispatcher.cs" Link="CatLib\Events\IOriginalDispatcher.cs" />
<Compile Include="..\CatLib.Core\CatLib\Facade.cs" Link="CatLib\Facade.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\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" />
<Compile Include="..\CatLib.Core\Support\Attribute\ExcludeFromCodeCoverageAttribute.cs" Link="Support\Attribute\ExcludeFromCodeCoverageAttribute.cs" />
<Compile Include="..\CatLib.Core\Support\Attribute\PriorityAttribute.cs" Link="Support\Attribute\PriorityAttribute.cs" />
<Compile Include="..\CatLib.Core\Support\Container\Bindable.cs" Link="Support\Container\Bindable.cs" />
Expand All @@ -84,7 +89,6 @@
<Compile Include="..\CatLib.Core\Support\Container\Params.cs" Link="Support\Container\Params.cs" />
<Compile Include="..\CatLib.Core\Support\Container\UnresolvableException.cs" Link="Support\Container\UnresolvableException.cs" />
<Compile Include="..\CatLib.Core\Support\Events\Dispatcher.cs" Link="Support\Events\Dispatcher.cs" />
<Compile Include="..\CatLib.Core\Support\Events\DispatcherExtend.cs" Link="Support\Events\DispatcherExtend.cs" />
<Compile Include="..\CatLib.Core\Support\Events\Event.cs" Link="Support\Events\Event.cs" />
<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" />
Expand All @@ -96,6 +100,7 @@
<Compile Include="..\CatLib.Core\Support\QuickList\InternalList.cs" Link="Support\QuickList\InternalList.cs" />
<Compile Include="..\CatLib.Core\Support\QuickList\IQuickList.cs" Link="Support\QuickList\IQuickList.cs" />
<Compile Include="..\CatLib.Core\Support\QuickList\QuickList.cs" Link="Support\QuickList\QuickList.cs" />
<Compile Include="..\CatLib.Core\Support\RingBuffer\RingBuffer.cs" Link="Support\RingBuffer\RingBuffer.cs" />
<Compile Include="..\CatLib.Core\Support\SortSet\ISortSet.cs" Link="Support\SortSet\ISortSet.cs" />
<Compile Include="..\CatLib.Core\Support\SortSet\SortSet.cs" Link="Support\SortSet\SortSet.cs" />
<Compile Include="..\CatLib.Core\Support\Template\IManaged.cs" Link="Support\Template\IManaged.cs" />
Expand All @@ -120,7 +125,7 @@

<ItemGroup>
<Folder Include="..\CatLib.Core\Properties\" />
<Folder Include="CatLib\" />
<Folder Include="CatLib\Events\" />
<Folder Include="Support\Attribute\" />
<Folder Include="Support\Events\" />
<Folder Include="Support\Exception\" />
Expand All @@ -129,6 +134,7 @@
<Folder Include="Support\QuickList\" />
<Folder Include="Support\SortSet\" />
<Folder Include="Support\Template\" />
<Folder Include="Support\RingBuffer\" />
</ItemGroup>

</Project>
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 @@ -36,6 +36,7 @@
<ItemGroup>
<Compile Include="CatLib\ApplicationTests.cs" />
<Compile Include="CatLib\FacaedTests.cs" />
<Compile Include="CatLib\GlobalDispatcherTests.cs" />
<Compile Include="Support\Container\ContainerPerformanceTests.cs" />
<Compile Include="Support\Container\MethodContainerTests.cs" />
<Compile Include="Support\Dispatcher\DispatcherTests.cs" />
Expand All @@ -48,6 +49,7 @@
<Compile Include="Support\FilterChain\FilterChainTests.cs" />
<Compile Include="Support\QuickList\InternalListTests.cs" />
<Compile Include="Support\QuickList\QuickListTests.cs" />
<Compile Include="Support\RingBuffer\RingBufferTests.cs" />
<Compile Include="Support\SortSet\SortSetTests.cs" />
<Compile Include="Support\Template\ManagerTests.cs" />
<Compile Include="Support\Template\SingleManagerTests.cs" />
Expand Down
284 changes: 284 additions & 0 deletions src/CatLib.Core.Tests/CatLib/GlobalDispatcherTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
/*
* This file is part of the CatLib package.
*
* (c) Yu Bin <support@catlib.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Document: http://catlib.io/
*/

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CatLib.Tests
{
[TestClass]
public class GlobalDispatcherTests
{
[TestMethod]
public void TestOn()
{
Application.New();

var n = string.Empty;
var a = new object[]{};
var r = new object();
App.Listen("Events.On", (name, args) =>
{
n = name;
a = args;
return r;
});

Assert.AreEqual(r, App.TriggerHalt("Events.On","helloworld", "catlib"));
Assert.AreEqual("Events.On", n);
Assert.AreEqual("helloworld", a[0]);
Assert.AreEqual("catlib", a[1]);
}

[TestMethod]
public void TestDispatcherGroup()
{
Application.New();
var isCall = false;
App.On("Events", () =>
{
isCall = true;
}, "catlib");

App.On("Events2", () =>
{
isCall = true;
}, "catlib");

App.Trigger("Events");
Assert.AreEqual(true, isCall);
isCall = false;
App.Trigger("Events2");
Assert.AreEqual(true, isCall);
isCall = false;

App.Off("catlib");
App.Trigger("Events");
App.Trigger("Events2");
Assert.AreEqual(false, isCall);
}

[TestMethod]
public void TestT1()
{
var dispatcher = new Dispatcher();
Application.New();
var n = 0;
dispatcher.On("Events.T1", (int num) =>
{
n = num;
});

App.On("Events.T1",(int num) =>
{
n = num + 1;
});

dispatcher.Listen("Events.T1.Listen", (int num) =>
{
n = num;
return 100;
});

App.Listen("Events.T1.Listen", (int num) =>
{
n = num + 1;
return 200;
});

var isCall = false;
dispatcher.On("Events.T0", () =>
{
isCall = true;
});

dispatcher.Listen("Events.T0.Listen", () =>
{
return 300;
});

App.Listen("Events.T0.Listen", () =>
{
return 300;
});

dispatcher.Trigger("Events.T1",199478);
Assert.AreEqual(199478, n);
App.Trigger("Events.T1", 199478);
Assert.AreEqual(199479, n);

Assert.AreEqual(100, dispatcher.TriggerHalt("Events.T1.Listen", "abc", App.Handler, 199478));
Assert.AreEqual(199478, n);
Assert.AreEqual(200, App.TriggerHalt("Events.T1.Listen", "abcd", dispatcher, 199478));
Assert.AreEqual(199479, n);

dispatcher.TriggerHalt("Events.T0", "abcd", dispatcher, 199478);
Assert.AreEqual(true, isCall);
Assert.AreEqual(300, dispatcher.TriggerHalt("Events.T0.Listen", "abcd", dispatcher, 199478));
Assert.AreEqual(300, App.TriggerHalt("Events.T0.Listen", "abcd", dispatcher, 199478));
}

[TestMethod]
public void TestT1_2()
{
var dispatcher = new Dispatcher();
Application.New();
var n = 0;
var s = string.Empty;
dispatcher.On("Events.T1_2", (int num, string hello) =>
{
n = num;
s = hello;
});

App.On("Events.T1_2", (int num, string hello) =>
{
n = num + 1;
s = hello;
});

dispatcher.Listen("Events.T1_2.Listen", (int num, string hello) =>
{
n = num;
s = hello;
return 100;
});

App.Listen("Events.T1_2.Listen", (int num, string hello) =>
{
n = num + 1;
s = hello;
return 200;
});

dispatcher.Trigger("Events.T1_2", "abc",199478);
Assert.AreEqual(199478, n);
Assert.AreEqual("abc", s);
App.Trigger("Events.T1_2", "abcd", 199478);
Assert.AreEqual(199479, n);
Assert.AreEqual("abcd", s);

Assert.AreEqual(100, dispatcher.TriggerHalt("Events.T1_2.Listen", "abc", App.Handler, 199478));
Assert.AreEqual(199478, n);
Assert.AreEqual("abc", s);
Assert.AreEqual(200, App.TriggerHalt("Events.T1_2.Listen", "abcd", dispatcher, 199478));
Assert.AreEqual(199479, n);
Assert.AreEqual("abcd", s);
}

[TestMethod]
public void Test1_3()
{
var dispatcher = new Dispatcher();
Application.New();
var n = 0;
var s = string.Empty;
dispatcher.On("Events.T1_3", (int num, string hello, IDispatcher disp) =>
{
n = num;
s = hello;
Assert.AreEqual(App.Handler, disp);
});

App.On("Events.T1_3", (int num, string hello, IDispatcher disp) =>
{
n = num + 1;
s = hello;
Assert.AreEqual(dispatcher, disp);
});

dispatcher.Listen("Events.T1_3.Listen", (int num, string hello, IDispatcher disp) =>
{
n = num;
s = hello;
Assert.AreEqual(App.Handler, disp);
return 100;
});

App.Listen("Events.T1_3.Listen", (int num, string hello, IDispatcher disp) =>
{
n = num + 1;
s = hello;
Assert.AreEqual(dispatcher, disp);
return 200;
});

dispatcher.Trigger("Events.T1_3", "abc", App.Handler, 199478);
Assert.AreEqual(199478, n);
Assert.AreEqual("abc", s);
App.Trigger("Events.T1_3", "abcd", dispatcher, 199478);
Assert.AreEqual(199479, n);
Assert.AreEqual("abcd", s);

Assert.AreEqual(100, dispatcher.TriggerHalt("Events.T1_3.Listen", "abc", App.Handler, 199478));
Assert.AreEqual(199478, n);
Assert.AreEqual("abc", s);
Assert.AreEqual(200, App.TriggerHalt("Events.T1_3.Listen", "abcd", dispatcher, 199478));
Assert.AreEqual(199479, n);
Assert.AreEqual("abcd", s);
}

[TestMethod]
public void Test1_4()
{
var dispatcher = new Dispatcher();
Application.New();
var n = 0;
var s = string.Empty;
dispatcher.On("Events.T1_4", (int num, string hello, IDispatcher disp, IApplication application) =>
{
n = num;
s = hello;
Assert.AreEqual(App.Handler, disp);
Assert.AreEqual(App.Handler, application);
});

App.On("Events.T1_4", (int num, string hello, IDispatcher disp, IApplication application) =>
{
n = num + 1;
s = hello;
Assert.AreEqual(dispatcher, disp);
Assert.AreEqual(App.Handler, application);
});

dispatcher.Listen("Events.T1_4.Listen", (int num, string hello, IDispatcher disp, IApplication application) =>
{
n = num;
s = hello;
Assert.AreEqual(App.Handler, disp);
Assert.AreEqual(App.Handler, application);
return 100;
});

App.Listen("Events.T1_4.Listen", (int num, string hello, IDispatcher disp, IApplication application) =>
{
n = num + 1;
s = hello;
Assert.AreEqual(dispatcher, disp);
Assert.AreEqual(App.Handler, application);
return 200;
});

dispatcher.Trigger("Events.T1_4", "abc", App.Handler, 199478);
Assert.AreEqual(199478, n);
Assert.AreEqual("abc", s);
App.Trigger("Events.T1_4", "abcd", dispatcher, 199478);
Assert.AreEqual(199479, n);
Assert.AreEqual("abcd", s);

Assert.AreEqual(100, dispatcher.TriggerHalt("Events.T1_4.Listen", "abc", App.Handler, 199478));
Assert.AreEqual(199478, n);
Assert.AreEqual("abc", s);
Assert.AreEqual(200, App.TriggerHalt("Events.T1_4.Listen", "abcd", dispatcher, 199478));
Assert.AreEqual(199479, n);
Assert.AreEqual("abcd", s);
}
}
}
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.5.0")]
[assembly: AssemblyFileVersion("1.2.5.0")]
[assembly: AssemblyVersion("1.2.6.0")]
[assembly: AssemblyFileVersion("1.2.6.0")]
Loading