Skip to content

Commit

Permalink
Merge pull request #53 from CatLib/feature/1.2.12
Browse files Browse the repository at this point in the history
Feature/1.2.12
  • Loading branch information
喵喵大人 authored Nov 2, 2018
2 parents 922a6b6 + b7f6ec0 commit dc79e8a
Show file tree
Hide file tree
Showing 19 changed files with 461 additions and 30 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.2.11
Install-Package CatLib.Core -Version 1.2.12
```

**直接下载发布版本**
Expand Down
5 changes: 5 additions & 0 deletions src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<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\Facades\Template\Managed.cs" Link="CatLib\Facades\Template\Managed.cs" />
<Compile Include="..\CatLib.Core\CatLib\Facades\Template\Manager.cs" Link="CatLib\Facades\Template\Manager.cs" />
<Compile Include="..\CatLib.Core\CatLib\Facades\Template\SingleManaged.cs" Link="CatLib\Facades\Template\SingleManaged.cs" />
<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\IServiceProvider.cs" Link="CatLib\IServiceProvider.cs" />
Expand Down Expand Up @@ -133,6 +137,7 @@
<ItemGroup>
<Folder Include="..\CatLib.Core\Properties\" />
<Folder Include="CatLib\Events\" />
<Folder Include="CatLib\Facades\Template\" />
<Folder Include="Support\Attribute\" />
<Folder Include="Support\Events\" />
<Folder Include="Support\Exception\" />
Expand Down
97 changes: 95 additions & 2 deletions src/CatLib.Core.Tests/CatLib/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void Register()
}

[TestMethod]
[ExpectedException(typeof(RuntimeException))]
public void RepeatInitTest()
{
var app = MakeApplication();
Expand Down Expand Up @@ -106,6 +107,98 @@ public void NoBootstrapInit()
});
}

public class StopBootstrap : IBootstrap
{
public string value = string.Empty;
public bool stop = false;
public void Bootstrap()
{
value = "bootstrap";
}
}

[TestMethod]
public void TestStopBootstrap()
{
var bootstrapStopped = new StopBootstrap() { stop = true };
var bootstrapNotStopped = new StopBootstrap();
var application = Application.New();
application.Listen<IBootstrap, object>(ApplicationEvents.Bootstrapping, (b) =>
{
if (((StopBootstrap)b).stop)
{
return false;
}
return null;
});
application.Bootstrap(bootstrapStopped, bootstrapNotStopped);
Assert.AreEqual(string.Empty, bootstrapStopped.value);
Assert.AreEqual("bootstrap", bootstrapNotStopped.value);
}

public class StopProvider : IServiceProvider
{
public string value = string.Empty;
public bool stop = false;
public void Register()
{
value = "register";
}
public void Init()
{
}
}

[TestMethod]
public void TestStopRegisterProvider()
{
var providerStopped = new StopProvider() { stop = true };
var providerNotStopped = new StopProvider();

var application = Application.New();
application.Listen<IServiceProvider, object>(ApplicationEvents.OnRegisterProvider, (b) =>
{
if (((StopProvider)b).stop)
{
return false;
}
return null;
});
application.Register(providerStopped);
application.Register(providerNotStopped);
Assert.AreEqual(string.Empty, providerStopped.value);
Assert.AreEqual("register", providerNotStopped.value);
}

[TestMethod]
[ExpectedException(typeof(RuntimeException))]
public void TestInitingRegisterProvider()
{
var application = Application.New();
application.Register(new StopProvider());
application.On<IServiceProvider>(ApplicationEvents.OnIniting, (b) =>
{
application.Register(new TestServiceProvider());
});
application.Bootstrap();
application.Init();
}

[TestMethod]
[ExpectedException(typeof(RuntimeException))]
public void TestTerminateRegisterProvider()
{
var application = Application.New();
application.Register(new StopProvider());
application.On(ApplicationEvents.OnTerminate, () =>
{
application.Register(new TestServiceProvider());
});
application.Bootstrap();
application.Init();
application.Terminate();
}

/// <summary>
/// 测试终止程序
/// </summary>
Expand Down Expand Up @@ -164,7 +257,7 @@ public void TestOn()
public void GetCurrentProcess()
{
var app = MakeApplication();
Assert.AreEqual(Application.StartProcess.Inited, app.Process);
Assert.AreEqual(Application.StartProcess.Running, app.Process);
}

[TestMethod]
Expand All @@ -178,13 +271,13 @@ public void TestDebugLevel()
/// 重复的引导测试
/// </summary>
[TestMethod]
[ExpectedException(typeof(RuntimeException))]
public void RepeatBootstrap()
{
var app = new Application();
app.Bootstrap();
app.Init();
app.Bootstrap();
Assert.AreEqual(Application.StartProcess.Inited, app.Process);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/CatLib.Core.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
[assembly: Guid("3c9f4024-910c-4881-a04d-34a6c3a09019")]

[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.11.0")]
[assembly: AssemblyFileVersion("1.2.12.0")]
8 changes: 8 additions & 0 deletions src/CatLib.Core.Tests/Support/Util/DictTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public void TestSetRemove()
Assert.AreEqual(false, Dict.Remove(dict, "hello.name.is.world"));
}

[TestMethod]
public void TestSetNotObject()
{
var dict = new Dictionary<string, object>();
dict.Add("string", "string");
Dict.Set(dict, "string.hello", "hello");
}

[TestMethod]
public void TestKeys()
{
Expand Down
15 changes: 15 additions & 0 deletions src/CatLib.Core.Tests/Support/Util/StreamExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ public void TestStreamToTextLarage()
Assert.AreEqual(builder.ToString(), stream1.ToText());
}

[TestMethod]
public void TestChineseText()
{
var stream1 = new StorageStream(new MemoryStorage());
var builder = new StringBuilder();
for (var i = 0; i < (ThreadStatic.Buffer.Length / 10) + 1; i++)
{
var data = Encoding.UTF8.GetBytes("12中文34测试的5这是67890");
stream1.Write(data, 0, data.Length);
builder.Append("12中文34测试的5这是67890");
}
stream1.Seek(0, SeekOrigin.Begin);
Assert.AreEqual(builder.ToString(), stream1.ToText());
}

[TestMethod]
public void TestStreamToTextEmpty()
{
Expand Down
4 changes: 4 additions & 0 deletions src/CatLib.Core/CatLib.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<Compile Include="CatLib\Events\IGlobalDispatcher.cs" />
<Compile Include="CatLib\Events\IOriginalDispatcher.cs" />
<Compile Include="CatLib\Facade.cs" />
<Compile Include="CatLib\Facades\Template\Managed.cs" />
<Compile Include="CatLib\Facades\Template\Manager.cs" />
<Compile Include="CatLib\Facades\Template\SingleManaged.cs" />
<Compile Include="CatLib\Facades\Template\SingleManager.cs" />
<Compile Include="CatLib\IApplication.cs" />
<Compile Include="CatLib\IBootstrap.cs" />
<Compile Include="CatLib\IServiceProvider.cs" />
Expand Down
11 changes: 10 additions & 1 deletion src/CatLib.Core/CatLib/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IApplication Handler
{
if (instance == null)
{
Application.New();
return New();
}
return instance;
}
Expand All @@ -54,6 +54,15 @@ public static IApplication Handler
}
}
}

/// <summary>
/// 创建CatLib实例
/// </summary>
/// <returns>CatLib实例</returns>
protected static IApplication New()
{
return Application.New();
}
#endregion

#region Application API
Expand Down
Loading

0 comments on commit dc79e8a

Please sign in to comment.