Skip to content

Commit

Permalink
Merge pull request #16 from CatLib/1.2
Browse files Browse the repository at this point in the history
CatLib.Core 1.2 Beta
  • Loading branch information
喵喵大人 authored Jan 20, 2018
2 parents 72c3eb6 + 17494fe commit 3874a17
Show file tree
Hide file tree
Showing 60 changed files with 7,234 additions and 2,173 deletions.
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.1.4
Install-Package CatLib.Core -Version 1.2.0
```

**直接下载发布版本**
Expand Down
30 changes: 17 additions & 13 deletions src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,32 @@
<Compile Include="..\CatLib.Core\CatLib\IServiceProviderType.cs" Link="CatLib\IServiceProviderType.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" />
<Compile Include="..\CatLib.Core\Support\Container\BindData.cs" Link="Support\Container\BindData.cs" />
<Compile Include="..\CatLib.Core\Support\Container\Container.cs" Link="Support\Container\Container.cs" />
<Compile Include="..\CatLib.Core\Support\Container\ContainerExtend.cs" Link="Support\Container\ContainerExtend.cs" />
<Compile Include="..\CatLib.Core\Support\Container\GivenData.cs" Link="Support\Container\GivenData.cs" />
<Compile Include="..\CatLib.Core\Support\Container\IBindable.cs" Link="Support\Container\IBindable.cs" />
<Compile Include="..\CatLib.Core\Support\Container\IBindData.cs" Link="Support\Container\IBindData.cs" />
<Compile Include="..\CatLib.Core\Support\Container\IContainer.cs" Link="Support\Container\IContainer.cs" />
<Compile Include="..\CatLib.Core\Support\Container\IGivenData.cs" Link="Support\Container\IGivenData.cs" />
<Compile Include="..\CatLib.Core\Support\Container\IMethodBind.cs" Link="Support\Container\IMethodBind.cs" />
<Compile Include="..\CatLib.Core\Support\Container\InjectAttribute.cs" Link="Support\Container\InjectAttribute.cs" />
<Compile Include="..\CatLib.Core\Support\Container\Internal\IBindData.cs" Link="Support\Container\Internal\IBindData.cs" />
<Compile Include="..\CatLib.Core\Support\Container\Internal\IGivenData.cs" Link="Support\Container\Internal\IGivenData.cs" />
<Compile Include="..\CatLib.Core\Support\Dispatcher\Dispatcher.cs" Link="Support\Dispatcher\Dispatcher.cs" />
<Compile Include="..\CatLib.Core\Support\Dispatcher\EventHandler.cs" Link="Support\Dispatcher\EventHandler.cs" />
<Compile Include="..\CatLib.Core\Support\Dispatcher\IDispatcher.cs" Link="Support\Dispatcher\IDispatcher.cs" />
<Compile Include="..\CatLib.Core\Support\Dispatcher\IEventHandler.cs" Link="Support\Dispatcher\IEventHandler.cs" />
<Compile Include="..\CatLib.Core\Support\Container\IVariant.cs" Link="Support\Container\IVariant.cs" />
<Compile Include="..\CatLib.Core\Support\Container\MethodBind.cs" Link="Support\Container\MethodBind.cs" />
<Compile Include="..\CatLib.Core\Support\Container\MethodContainer.cs" Link="Support\Container\MethodContainer.cs" />
<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" />
<Compile Include="..\CatLib.Core\Support\Exception\AssertException.cs" Link="Support\Exception\AssertException.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" />
<Compile Include="..\CatLib.Core\Support\Guard\Guard.cs" Link="Support\Guard\Guard.cs" />
<Compile Include="..\CatLib.Core\Support\LruCache\CacheNode.cs" Link="Support\LruCache\CacheNode.cs" />
<Compile Include="..\CatLib.Core\Support\LruCache\ILruCache.cs" Link="Support\LruCache\ILruCache.cs" />
<Compile Include="..\CatLib.Core\Support\LruCache\LruCache.cs" Link="Support\LruCache\LruCache.cs" />
<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" />
Expand All @@ -99,6 +105,7 @@
<Compile Include="..\CatLib.Core\Support\Template\SingleManaged.cs" Link="Support\Template\SingleManaged.cs" />
<Compile Include="..\CatLib.Core\Support\Template\SingleManager.cs" Link="Support\Template\SingleManager.cs" />
<Compile Include="..\CatLib.Core\Support\Util\Arr.cs" Link="Support\Util\Arr.cs" />
<Compile Include="..\CatLib.Core\Support\Util\Dict.cs" Link="Support\Util\Dict.cs" />
<Compile Include="..\CatLib.Core\Support\Util\Enum.cs" Link="Support\Util\Enum.cs" />
<Compile Include="..\CatLib.Core\Support\Util\IAwait.cs" Link="Support\Util\IAwait.cs" />
<Compile Include="..\CatLib.Core\Support\Util\IReferenceCount.cs" Link="Support\Util\IReferenceCount.cs" />
Expand All @@ -113,16 +120,13 @@
<Folder Include="..\CatLib.Core\Properties\" />
<Folder Include="CatLib\" />
<Folder Include="Support\Attribute\" />
<Folder Include="Support\Container\Internal\" />
<Folder Include="Support\Dispatcher\" />
<Folder Include="Support\Events\" />
<Folder Include="Support\Exception\" />
<Folder Include="Support\FilterChain\" />
<Folder Include="Support\Guard\" />
<Folder Include="Support\LruCache\" />
<Folder Include="Support\QuickList\" />
<Folder Include="Support\SortSet\" />
<Folder Include="Support\Template\" />
<Folder Include="Support\Util\" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion src/CatLib.Core.Tests/CatLib.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<ItemGroup>
<Compile Include="CatLib\ApplicationTests.cs" />
<Compile Include="CatLib\FacaedTests.cs" />
<Compile Include="Support\Container\ContainerPerformanceTests.cs" />
<Compile Include="Support\Container\MethodContainerTests.cs" />
<Compile Include="Support\Dispatcher\DispatcherTests.cs" />
<Compile Include="ExceptionAssert.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -44,13 +46,13 @@
<Compile Include="Support\Container\ContainerTests.cs" />
<Compile Include="Support\Container\GivenDataTests.cs" />
<Compile Include="Support\FilterChain\FilterChainTests.cs" />
<Compile Include="Support\LruCache\LruCacheTests.cs" />
<Compile Include="Support\QuickList\InternalListTests.cs" />
<Compile Include="Support\QuickList\QuickListTests.cs" />
<Compile Include="Support\SortSet\SortSetTests.cs" />
<Compile Include="Support\Template\ManagerTests.cs" />
<Compile Include="Support\Template\SingleManagerTests.cs" />
<Compile Include="Support\Util\ArrTests.cs" />
<Compile Include="Support\Util\DictTests.cs" />
<Compile Include="Support\Util\EnumTests.cs" />
<Compile Include="Support\Util\ReferenceCountTests.cs" />
<Compile Include="Support\Util\StrTests.cs" />
Expand Down
15 changes: 11 additions & 4 deletions src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public void GetVersionTest()
public void MakeAssemblyClass()
{
var app = new Application();
var lru = app.MakeWith<LruCache<string, string>>(10);
var sortSet = app.Make<SortSet<string, string>>();

Assert.AreNotEqual(null, lru);
Assert.AreNotEqual(null, sortSet);
}

[TestMethod]
Expand All @@ -131,7 +131,7 @@ public void TestOn()
var app = new Application();
ExceptionAssert.DoesNotThrow(() =>
{
app.On("hello", (o) => { });
app.On("hello", () => { });
});
}

Expand All @@ -145,6 +145,13 @@ public void GetCurrentProcess()
Assert.AreEqual(Application.StartProcess.Inited, app.Process);
}

[TestMethod]
public void TestDebugLevel()
{
App.DebugLevel = DebugLevels.Dev;
Assert.AreEqual(DebugLevels.Dev, App.DebugLevel);
}

/// <summary>
/// 重复的引导测试
/// </summary>
Expand Down Expand Up @@ -302,7 +309,7 @@ public void TestOnDispatcher()
{
var app = MakeApplication();

app.Listen("testevent", (payload) =>
app.Listen("testevent", (object payload) =>
{
Assert.AreEqual("abc", payload);
return 123;
Expand Down
171 changes: 165 additions & 6 deletions src/CatLib.Core.Tests/CatLib/FacaedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,90 @@ namespace CatLib.Tests
[TestClass]
public class FacaedTests
{
public class FacaedTestClass : IFacaedTestClass
{
}

public interface IFacaedTestClass
{
}
public class TestClassFacade : Facade<IFacaedTestClass>
{

}

public class TestClassFacadeError : Facade<FacaedTestClass>
{

}

public class FacaedTestClass
[TestMethod]
public void FacadeErrorTest()
{
var app = new Application();
app.Bootstrap();
app.Singleton<FacaedTestClass>();

var isError = false;
try
{
var data = TestClassFacadeError.Instance;
}
catch (TypeInitializationException)
{
isError = true;
}

Assert.AreEqual(true, isError);
}

public class TestClassFacaed : Facade<FacaedTestClass>
[TestMethod]
public void FacadeWatchTest()
{
var app = new Application();
app.Bootstrap();
app.Singleton<FacaedTestClass>().Alias<IFacaedTestClass>();
var old = TestClassFacade.Instance;
app.Unbind<FacaedTestClass>();
app.Singleton<FacaedTestClass>().Alias<IFacaedTestClass>();

Assert.AreNotSame(old, TestClassFacade.Instance);
}

[TestMethod]
public void FacadeWatchTestWithInstance()
{
var app = new Application();
app.Bootstrap();
app.Singleton<FacaedTestClass>().Alias<IFacaedTestClass>();

var cls = new FacaedTestClass();
app.Instance<FacaedTestClass>(cls);

Assert.AreSame(cls, TestClassFacade.Instance);
}

[TestMethod]
public void FacadeMakeFaild()
{
var app = new Application();
app.Bootstrap();
app.Singleton<FacaedTestClass>().Alias<IFacaedTestClass>();
var old = TestClassFacade.Instance;

Assert.AreNotEqual(null, old);
app.Unbind<FacaedTestClass>();

var isError = false;
try
{
var data = TestClassFacade.Instance;
}
catch (UnresolvableException)
{
isError = true;
}
Assert.AreEqual(true, isError);
}

/// <summary>
Expand All @@ -36,15 +111,99 @@ public void FacadeTest()
{
var app = new Application();
app.Bootstrap();
var obj = new FacaedTestClass();
IFacaedTestClass obj = new FacaedTestClass();
app.Singleton<FacaedTestClass>((c, p) =>
{
return obj;
});
}).Alias<IFacaedTestClass>();

Assert.AreEqual(obj, TestClassFacaed.Instance);
Assert.AreSame(obj, TestClassFacade.Instance);
//double run
Assert.AreEqual(obj, TestClassFacaed.Instance);
Assert.AreSame(obj, TestClassFacade.Instance);
Assert.AreSame(obj, TestClassFacade.Instance);
}

[TestMethod]
public void FacadeReleaseTest()
{
var app = new Application();
app.Bootstrap();
app.Singleton<FacaedTestClass>().Alias<IFacaedTestClass>();

var data = TestClassFacade.Instance;
Assert.AreSame(data, TestClassFacade.Instance);
app.Release<IFacaedTestClass>();
Assert.AreNotSame(data, TestClassFacade.Instance);
}

[TestMethod]
public void TestNotStaticBindFacade()
{
var app = new Application();
app.Bootstrap();
app.Bind<FacaedTestClass>().Alias<IFacaedTestClass>();

var data = TestClassFacade.Instance;
Assert.AreNotSame(data, TestClassFacade.Instance);
Assert.AreNotSame(TestClassFacade.Instance, TestClassFacade.Instance);
}

[TestMethod]
public void TestBindingStateSwitchSingletonToBind()
{
var app = new Application();
app.Bootstrap();
app.Singleton<FacaedTestClass>().Alias<IFacaedTestClass>();

var data = TestClassFacade.Instance;
Assert.AreSame(data, TestClassFacade.Instance);

app.Unbind<IFacaedTestClass>();
app.Bind<FacaedTestClass>().Alias<IFacaedTestClass>();
Assert.AreNotSame(data, TestClassFacade.Instance);
Assert.AreNotSame(TestClassFacade.Instance, TestClassFacade.Instance);
}

[TestMethod]
public void TestBindingStateSwitchBindToSingleton()
{
var app = new Application();
app.Bootstrap();
app.Bind<FacaedTestClass>().Alias<IFacaedTestClass>();

var data = TestClassFacade.Instance;
Assert.AreNotSame(data, TestClassFacade.Instance);
Assert.AreNotSame(TestClassFacade.Instance, TestClassFacade.Instance);

app.Unbind<IFacaedTestClass>();
app.Singleton<FacaedTestClass>().Alias<IFacaedTestClass>();
data = TestClassFacade.Instance;
Assert.AreSame(data, TestClassFacade.Instance);
Assert.AreSame(TestClassFacade.Instance, TestClassFacade.Instance);
}

[TestMethod]
public void TestNotBind()
{
var app = new Application();
app.Bootstrap();
app.Instance<IFacaedTestClass>(new FacaedTestClass());

var data = TestClassFacade.Instance;
Assert.AreSame(data, TestClassFacade.Instance);

app.Release<IFacaedTestClass>();

var isError = false;
try
{
data = TestClassFacade.Instance;
}
catch (UnresolvableException)
{
isError = true;
}
Assert.AreEqual(true, isError);
}
}
}
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.1.4.0")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
14 changes: 9 additions & 5 deletions src/CatLib.Core.Tests/Support/Container/BindDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void CanAddOnResolving()

bindData.OnResolving((bind, obj) => null);

var data = bindData.ExecResolvingDecorator(new Container());
var data = bindData.TriggerResolving(new Container());
Assert.AreEqual(null, data);
}

Expand All @@ -194,7 +194,7 @@ public void CheckIllegalResolving()
}
#endregion

#region UnBind
#region Unbind
/// <summary>
/// 能够正常解除绑定
/// </summary>
Expand All @@ -205,8 +205,12 @@ public void CanUnBind()
var bindData = container.Bind("CanUnBind", (app, param) => "hello world", false);

Assert.AreEqual("hello world", container.Make("CanUnBind").ToString());
bindData.UnBind();
Assert.AreEqual(null, container.Make("CanUnBind"));
bindData.Unbind();

ExceptionAssert.Throws<UnresolvableException>(() =>
{
container.Make("CanUnBind");
});
}

/// <summary>
Expand All @@ -217,7 +221,7 @@ public void CheckIllegalUnBindInput()
{
var container = new Container();
var bindData = container.Bind("CanUnBind", (app, param) => "hello world", false);
bindData.UnBind();
bindData.Unbind();

ExceptionAssert.Throws<RuntimeException>(() =>
{
Expand Down
Loading

0 comments on commit 3874a17

Please sign in to comment.