Skip to content

Commit

Permalink
Merge pull request #157 from CatLib/feature/1.3.0-beta
Browse files Browse the repository at this point in the history
Feature/1.3.0 beta
  • Loading branch information
喵喵大人 authored Jan 4, 2019
2 parents 6e73c28 + 8fddc97 commit 95ebf46
Show file tree
Hide file tree
Showing 24 changed files with 569 additions and 364 deletions.
4 changes: 4 additions & 0 deletions CatLib.Core.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>
4 changes: 2 additions & 2 deletions src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
<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\BindDataExtend.cs" Link="Support\Container\BindDataExtend.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\ExtendBindData.cs" Link="Support\Container\ExtendBindData.cs" />
<Compile Include="..\CatLib.Core\Support\Container\ExtendContainer.cs" Link="Support\Container\ExtendContainer.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" />
Expand Down
106 changes: 91 additions & 15 deletions src/CatLib.Core.Tests/Support/Container/ContainerHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,6 @@ public int getValue()
}
}

[TestMethod]
public void TestWatch()
{
var container = new Container();
container.Instance<IContainer>(container);

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

Assert.AreEqual(200, cls.value);
Assert.AreSame(container, cls.container);
}

[TestMethod]
public void TestWatchLambda()
{
Expand Down Expand Up @@ -409,6 +394,53 @@ public void TestExtendContainer()
Assert.AreEqual("hello world", container.Make<string>());
}

[TestMethod]
public void TestExtendContainerWithService()
{
var container = new Container();
container.Extend("abc", (instance, _) =>
{
Assert.AreSame(container, _);
return instance + " world";
});

container.Bind("abc", (b, p) => "hello", false);
Assert.AreEqual("hello world", container.Make("abc"));
}

[TestMethod]
public void TestExtendContainerWithService2()
{
var container = new Container();
container.Extend("abc", (instance) => instance + " world");

container.Bind("abc", (b, p) => "hello", false);
Assert.AreEqual("hello world", container.Make("abc"));
}

[TestMethod]
public void TestExtendWithServiceName()
{
var container = new Container();
container.Extend<ITypeMatchInterface, TestTypeMatchOnResolvingClass>((instance) => null);
container.Bind<ITypeMatchInterface, TestTypeMatchOnResolvingClass>();

Assert.AreEqual(null, container.Make<ITypeMatchInterface>());
}

[TestMethod]
public void TestExtendWithServiceName2()
{
var container = new Container();
container.Extend<ITypeMatchInterface, TestTypeMatchOnResolvingClass>((instance, c) =>
{
Assert.AreEqual(container, c);
return null;
});
container.Bind<ITypeMatchInterface, TestTypeMatchOnResolvingClass>();
Assert.AreEqual(null, container.Make<ITypeMatchInterface>());
}

public interface ITypeMatchInterface
{

Expand Down Expand Up @@ -494,6 +526,50 @@ public void TestTypeMatchOnRelease()
Assert.AreEqual(2, stringCount);
}

[TestMethod]
public void TestBindFunc2()
{
var container = new Container();
var obj = new object();
container.Bind<IAwait>((p) => (bool) p[0] ? obj : new object()).Alias("created");
Assert.AreSame(obj, container.Make("created", true));
Assert.AreNotSame(obj, container.Make("created", false));
}

[TestMethod]
public void TestSingletonFunc2()
{
var container = new Container();
var obj = new object();
container.Singleton<IAwait>((p) => (bool)p[0] ? obj : new object()).Alias("created");
Assert.AreSame(obj, container.Make("created", true));
Assert.AreSame(obj, container.Make("created", false));
}

[TestMethod]
public void TestBindIfFunc2()
{
var container = new Container();
var obj = new object();
Assert.AreEqual(true, container.BindIf<IAwait>((p) => (bool)p[0] ? obj : new object(), out IBindData bindData));
Assert.AreEqual(false, container.BindIf<IAwait>((p) => null, out bindData));
bindData.Alias("created");
Assert.AreSame(obj, container.Make("created", true));
Assert.AreNotSame(obj, container.Make("created", false));
}

[TestMethod]
public void TestSingletonIfFunc2()
{
var container = new Container();
var obj = new object();
Assert.AreEqual(true, container.SingletonIf<IAwait>((p) => (bool)p[0] ? obj : new object(), out IBindData bindData));
Assert.AreEqual(false, container.SingletonIf<IAwait>((p) => null, out bindData));
bindData.Alias("created");
Assert.AreSame(obj, container.Make("created", true));
Assert.AreSame(obj, container.Make("created", false));
}

/// <summary>
/// 生成容器
/// </summary>
Expand Down
46 changes: 10 additions & 36 deletions src/CatLib.Core.Tests/Support/Container/ContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,21 +2291,6 @@ public void OnChange(int instance, IContainer container)
}
}

[TestMethod]
public void TestWatch()
{
var container = new Container();

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

Assert.AreEqual(200, cls.value);
Assert.AreSame(container, cls.container);
}

[TestMethod]
public void TestInstanceAndDecorator()
{
Expand All @@ -2323,27 +2308,6 @@ public void TestInstanceAndDecorator()
Assert.AreSame(newObject, ins);
}

[TestMethod]
public void TestOccupiedKeyInstance()
{
var container = new Container();
container.Instance<IBindData>(null);
var cls = new TestWatchCLass();
container.Instance("WatchService", 100);
container.Watch("WatchService", cls, "OnChange");
var isThrow = false;
try
{
container.Instance("WatchService", 200);
}
catch (RuntimeException)
{
isThrow = true;
}

Assert.AreEqual(true, isThrow);
}

[TestMethod]
public void TestFlashOnBind()
{
Expand Down Expand Up @@ -2783,6 +2747,16 @@ public void TestGivenInvalidTypeNotSupportNullInject()
.Needs("$container").Given(() => null);
container.Make<TestGivenInvalidTypeClass>();
}

[TestMethod]
[ExpectedException(typeof(LogicException))]
public void TestSetAliasIsService()
{
var container = new Container();
container.Bind("abc", (c, p) => 1, false);
container.Bind("ccc", (c, p) => 1, false);
container.Alias("abc", "ccc");
}
#endregion

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions src/CatLib.Core.Tests/Support/Util/ArrTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,16 @@ public void TestMapIEnumerable()
Assert.AreEqual(3, data[2]);
}

[TestMethod]
public void TestMapIntToString()
{
var data = new[] { 1, 2, 3 };
var result = Arr.Map(data, (i) => i.ToString());
Assert.AreEqual("1", result[0]);
Assert.AreEqual("2", result[1]);
Assert.AreEqual("3", result[2]);
}

[TestMethod]
public void TestPop()
{
Expand Down
7 changes: 5 additions & 2 deletions src/CatLib.Core/CatLib.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<AssemblyName>CatLib.Core</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -34,6 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="CatLib\App.cs" />
Expand All @@ -55,7 +58,7 @@
<Compile Include="CatLib\IServiceProviderType.cs" />
<Compile Include="CatLib\ServiceProvider.cs" />
<Compile Include="Support\Container\Bindable.cs" />
<Compile Include="Support\Container\BindDataExtend.cs" />
<Compile Include="Support\Container\ExtendBindData.cs" />
<Compile Include="Support\Container\IBindable.cs" />
<Compile Include="Support\Container\IMethodBind.cs" />
<Compile Include="Support\Container\IParams.cs" />
Expand All @@ -73,7 +76,7 @@
<Compile Include="Support\Attribute\PriorityAttribute.cs" />
<Compile Include="Support\Container\BindData.cs" />
<Compile Include="Support\Container\Container.cs" />
<Compile Include="Support\Container\ContainerExtend.cs" />
<Compile Include="Support\Container\ExtendContainer.cs" />
<Compile Include="Support\Container\GivenData.cs" />
<Compile Include="Support\Container\IContainer.cs" />
<Compile Include="Support\Container\InjectAttribute.cs" />
Expand Down
Loading

0 comments on commit 95ebf46

Please sign in to comment.