diff --git a/README.md b/README.md
index 19b9a92..460c268 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@
**使用Nuget安装**
```PM
-Install-Package CatLib.Core -Version 1.1.4
+Install-Package CatLib.Core -Version 1.2.0
```
**直接下载发布版本**
diff --git a/src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj b/src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
index 9c78109..8d4a8d8 100644
--- a/src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
+++ b/src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
@@ -65,26 +65,32 @@
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
@@ -99,6 +105,7 @@
+
@@ -113,16 +120,13 @@
-
-
+
-
-
diff --git a/src/CatLib.Core.Tests/CatLib.Core.Tests.csproj b/src/CatLib.Core.Tests/CatLib.Core.Tests.csproj
index de80f89..b01e6aa 100644
--- a/src/CatLib.Core.Tests/CatLib.Core.Tests.csproj
+++ b/src/CatLib.Core.Tests/CatLib.Core.Tests.csproj
@@ -36,6 +36,8 @@
+
+
@@ -44,13 +46,13 @@
-
+
diff --git a/src/CatLib.Core.Tests/CatLib/ApplicationTests.cs b/src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
index 8efa32a..7be5d7d 100644
--- a/src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
+++ b/src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
@@ -120,9 +120,9 @@ public void GetVersionTest()
public void MakeAssemblyClass()
{
var app = new Application();
- var lru = app.MakeWith>(10);
+ var sortSet = app.Make>();
- Assert.AreNotEqual(null, lru);
+ Assert.AreNotEqual(null, sortSet);
}
[TestMethod]
@@ -131,7 +131,7 @@ public void TestOn()
var app = new Application();
ExceptionAssert.DoesNotThrow(() =>
{
- app.On("hello", (o) => { });
+ app.On("hello", () => { });
});
}
@@ -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);
+ }
+
///
/// 重复的引导测试
///
@@ -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;
diff --git a/src/CatLib.Core.Tests/CatLib/FacaedTests.cs b/src/CatLib.Core.Tests/CatLib/FacaedTests.cs
index dc65e21..6302e92 100644
--- a/src/CatLib.Core.Tests/CatLib/FacaedTests.cs
+++ b/src/CatLib.Core.Tests/CatLib/FacaedTests.cs
@@ -17,15 +17,90 @@ namespace CatLib.Tests
[TestClass]
public class FacaedTests
{
+ public class FacaedTestClass : IFacaedTestClass
+ {
+ }
+
+ public interface IFacaedTestClass
+ {
+ }
+ public class TestClassFacade : Facade
+ {
+
+ }
+
+ public class TestClassFacadeError : Facade
+ {
+
+ }
- public class FacaedTestClass
+ [TestMethod]
+ public void FacadeErrorTest()
{
+ var app = new Application();
+ app.Bootstrap();
+ app.Singleton();
+
+ var isError = false;
+ try
+ {
+ var data = TestClassFacadeError.Instance;
+ }
+ catch (TypeInitializationException)
+ {
+ isError = true;
+ }
+ Assert.AreEqual(true, isError);
}
- public class TestClassFacaed : Facade
+ [TestMethod]
+ public void FacadeWatchTest()
{
+ var app = new Application();
+ app.Bootstrap();
+ app.Singleton().Alias();
+ var old = TestClassFacade.Instance;
+ app.Unbind();
+ app.Singleton().Alias();
+ Assert.AreNotSame(old, TestClassFacade.Instance);
+ }
+
+ [TestMethod]
+ public void FacadeWatchTestWithInstance()
+ {
+ var app = new Application();
+ app.Bootstrap();
+ app.Singleton().Alias();
+
+ var cls = new FacaedTestClass();
+ app.Instance(cls);
+
+ Assert.AreSame(cls, TestClassFacade.Instance);
+ }
+
+ [TestMethod]
+ public void FacadeMakeFaild()
+ {
+ var app = new Application();
+ app.Bootstrap();
+ app.Singleton().Alias();
+ var old = TestClassFacade.Instance;
+
+ Assert.AreNotEqual(null, old);
+ app.Unbind();
+
+ var isError = false;
+ try
+ {
+ var data = TestClassFacade.Instance;
+ }
+ catch (UnresolvableException)
+ {
+ isError = true;
+ }
+ Assert.AreEqual(true, isError);
}
///
@@ -36,15 +111,99 @@ public void FacadeTest()
{
var app = new Application();
app.Bootstrap();
- var obj = new FacaedTestClass();
+ IFacaedTestClass obj = new FacaedTestClass();
app.Singleton((c, p) =>
{
return obj;
- });
+ }).Alias();
- 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().Alias();
+
+ var data = TestClassFacade.Instance;
+ Assert.AreSame(data, TestClassFacade.Instance);
+ app.Release();
+ Assert.AreNotSame(data, TestClassFacade.Instance);
+ }
+
+ [TestMethod]
+ public void TestNotStaticBindFacade()
+ {
+ var app = new Application();
+ app.Bootstrap();
+ app.Bind().Alias();
+
+ 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().Alias();
+
+ var data = TestClassFacade.Instance;
+ Assert.AreSame(data, TestClassFacade.Instance);
+
+ app.Unbind();
+ app.Bind().Alias();
+ Assert.AreNotSame(data, TestClassFacade.Instance);
+ Assert.AreNotSame(TestClassFacade.Instance, TestClassFacade.Instance);
+ }
+
+ [TestMethod]
+ public void TestBindingStateSwitchBindToSingleton()
+ {
+ var app = new Application();
+ app.Bootstrap();
+ app.Bind().Alias();
+
+ var data = TestClassFacade.Instance;
+ Assert.AreNotSame(data, TestClassFacade.Instance);
+ Assert.AreNotSame(TestClassFacade.Instance, TestClassFacade.Instance);
+
+ app.Unbind();
+ app.Singleton().Alias();
+ 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(new FacaedTestClass());
+
+ var data = TestClassFacade.Instance;
+ Assert.AreSame(data, TestClassFacade.Instance);
+
+ app.Release();
+
+ var isError = false;
+ try
+ {
+ data = TestClassFacade.Instance;
+ }
+ catch (UnresolvableException)
+ {
+ isError = true;
+ }
+ Assert.AreEqual(true, isError);
}
}
}
diff --git a/src/CatLib.Core.Tests/Properties/AssemblyInfo.cs b/src/CatLib.Core.Tests/Properties/AssemblyInfo.cs
index 294fb01..3183efe 100644
--- a/src/CatLib.Core.Tests/Properties/AssemblyInfo.cs
+++ b/src/CatLib.Core.Tests/Properties/AssemblyInfo.cs
@@ -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")]
diff --git a/src/CatLib.Core.Tests/Support/Container/BindDataTests.cs b/src/CatLib.Core.Tests/Support/Container/BindDataTests.cs
index 579b31d..627abc4 100644
--- a/src/CatLib.Core.Tests/Support/Container/BindDataTests.cs
+++ b/src/CatLib.Core.Tests/Support/Container/BindDataTests.cs
@@ -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);
}
@@ -194,7 +194,7 @@ public void CheckIllegalResolving()
}
#endregion
- #region UnBind
+ #region Unbind
///
/// 能够正常解除绑定
///
@@ -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(() =>
+ {
+ container.Make("CanUnBind");
+ });
}
///
@@ -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(() =>
{
diff --git a/src/CatLib.Core.Tests/Support/Container/ContainerHelperTests.cs b/src/CatLib.Core.Tests/Support/Container/ContainerHelperTests.cs
index 8439fce..a2901c1 100644
--- a/src/CatLib.Core.Tests/Support/Container/ContainerHelperTests.cs
+++ b/src/CatLib.Core.Tests/Support/Container/ContainerHelperTests.cs
@@ -9,6 +9,7 @@
* Document: http://catlib.io/
*/
+using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CatLib.Tests
@@ -38,6 +39,14 @@ public void MakeTService()
Assert.AreSame(this, obj);
}
+ [TestMethod]
+ public void MakeTypeService()
+ {
+ var container = MakeContainer();
+ var obj = container.Make(typeof(ContainerHelperTests));
+ Assert.AreSame(this, obj);
+ }
+
///
/// 以单例形式绑定
///
@@ -110,11 +119,193 @@ public void TestRelease()
var container = MakeContainer();
var obj = new TestClassService();
container.Instance(obj);
+ container.OnFindType((str) =>
+ {
+ return Type.GetType(str);
+ });
Assert.AreSame(obj, container.Make());
container.Release();
// 因为被释放后容器会容器会自动推测出所需类的实例
- Assert.AreNotSame(obj, container.Make());
+ Assert.AreSame(obj.GetType(), container.Make().GetType());
+ }
+
+ [TestMethod]
+ public void TestBindIf()
+ {
+ var app = new Application();
+ IBindData bindData;
+ Assert.AreEqual(true, App.BindIf("TestBind", (c, p) => 1, out bindData));
+ Assert.AreEqual(false, App.BindIf("TestBind", (c, p) => 2, out bindData));
+ Assert.AreEqual(1, app["TestBind"]);
+
+ Assert.AreEqual(true, App.BindIf