Skip to content

Commit cf3c830

Browse files
committed
test: 增加 CreateInstance 扩展方法单元测试
1 parent d8fd55e commit cf3c830

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace UnitTestTcpSocket;
6+
7+
public class ActivationExtensionsTest
8+
{
9+
[Fact]
10+
public void Activation_Ok()
11+
{
12+
var type = typeof(Foo);
13+
var o = type.CreateInstance();
14+
Assert.NotNull(o);
15+
16+
var foo = o as Foo;
17+
Assert.NotNull(foo);
18+
19+
var foo1 = type.CreateInstance<Foo>();
20+
Assert.NotNull(foo1);
21+
}
22+
23+
[Fact]
24+
public void Activation_Nest()
25+
{
26+
var o = typeof(MockNestEntity).CreateInstance<MockNestEntity>([0.01f]);
27+
Assert.Equal(0.01f, o?.Rate);
28+
}
29+
30+
[Fact]
31+
public void Activation_Fail()
32+
{
33+
var type = typeof(string);
34+
var o = type.CreateInstance([123]);
35+
Assert.Null(o);
36+
37+
var foo = type.CreateInstance<Foo>();
38+
Assert.Null(foo);
39+
}
40+
41+
class MockNestEntity(float rate)
42+
{
43+
public float Rate { get; } = rate;
44+
}
45+
}

0 commit comments

Comments
 (0)