Skip to content

Commit 1e2677e

Browse files
committed
for Unity
1 parent ba74606 commit 1e2677e

39 files changed

+4597
-1774
lines changed

.circleci/config.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ executors:
1111
# https://hub.docker.com/r/gableroux/unity3d/tags
1212
- image: gableroux/unity3d:2018.3.12f1-windows
1313
jobs:
14-
# .NET Core, Debug(try to build and test).
15-
build-test:
16-
executor: dotnet
17-
steps:
18-
- checkout
19-
- run: dotnet build -c Debug
20-
- run: dotnet test -c Debug --no-build
21-
# Unity, create .unitypackage and make IL2CPP headless build and test it.
2214
build-unity:
2315
executor: unity
2416
steps:
@@ -33,23 +25,24 @@ jobs:
3325
- run: apt update && apt install libunwind8 -y
3426
- run:
3527
name: Build Linux(Mono)
36-
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod Exporter.BuildCliTestLinux
28+
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend Mono2x /BuildTarget StandaloneLinux64
3729
working_directory: src/RandomFixtureKit.Unity
38-
- run: src/RandomFixtureKit.Unity/bin/linux-x64/tests
39-
- run:
40-
name: Build Windows(IL2CPP)
41-
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod Exporter.BuildCliTestWindows
42-
working_directory: src/RandomFixtureKit.Unity
43-
- store_artifacts:
44-
path: src/RandomFixtureKit.Unity/bin/win-x64
45-
destination: /bin/win-x64
30+
- run: src/RandomFixtureKit.Unity/bin/UnitTest/StandaloneLinux64_Mono2x/test
4631
- run:
4732
name: Export unitypackage
48-
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod Exporter.Export
33+
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
4934
working_directory: src/RandomFixtureKit.Unity
5035
- store_artifacts:
5136
path: src/RandomFixtureKit.Unity/RandomFixtureKit.unitypackage
5237
destination: /RandomFixtureKit.unitypackage
38+
# .NET Core, Debug(try to build and test).
39+
build-test:
40+
executor: dotnet
41+
steps:
42+
- checkout
43+
- run: dotnet build -c Debug
44+
- run: dotnet test -c Debug --no-build
45+
# Unity, create .unitypackage and make IL2CPP headless build and test it.
5346
# .NET Core, Release, create NuGet package and push.
5447
build-push:
5548
executor: dotnet

README.md

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ Fill random/edge-case value to target type for unit testing, supports both .NET
66

77
![image](https://user-images.githubusercontent.com/46207/56805033-abce0480-6862-11e9-91d0-7ca9c08aa688.png)
88

9-
Documantation is not yet but core library is completed. .unitypackage and upm coming soon.
10-
119
NuGet: [RandomFixtureKit](https://www.nuget.org/packages/RandomFixtureKit)
1210

1311
```
1412
Install-Package RandomFixturekit
1513
```
1614

15+
Unity: [releases/RandomFixtureKit.unitypackage](https://github.com/Cysharp/RandomFixtureKit/releases)
16+
17+
or package.json exists on `src/RandomFixtureKit.Unity/Assets/Scripts/RandomFixtureKit` for unity package manager.
18+
1719
How to use
1820
---
1921

@@ -57,7 +59,60 @@ var v = FixtureFactory.Create<IFoo>(); // return Foo object
5759

5860
edge-case, for example int is filled `int.MinValue`, `int.MaxValue`, `0`, `-1` or `1`. collection(array, list, etc...) is filled `null`, `zero-elements`, `one-elements`, `nine-elements`.
5961

60-
TODO: More sample of combine resolvers and create custom generator.
62+
Custom Generator
63+
---
64+
Implement `IGenerator` and setup composite-resolver, you can control how generate values.
65+
66+
67+
```csharp
68+
// for example, increment Id on create MyClass value.
69+
public class MyClass
70+
{
71+
public int Id { get; set; }
72+
public int Age { get; set; }
73+
public string Name { get; set; }
74+
75+
public override string ToString()
76+
{
77+
return (Id, Age, Name).ToString();
78+
}
79+
}
80+
81+
// Create IGenerator.
82+
public class MyClassSequentialIdGenerator : IGenerator
83+
{
84+
int sequence = 0;
85+
IGenerator fallbackGenerator = new Int32Generator();
86+
87+
// this generator called if requires int value.
88+
public Type Type => typeof(int);
89+
90+
public object Generate(in GenerationContext context)
91+
{
92+
// check target int field belongs MyClass.
93+
if (context.FieldInfo != null)
94+
{
95+
// auto-implemented property's field: <Id>k__BackingField
96+
if (context.FieldInfo.DeclaringType == typeof(MyClass) && context.FieldInfo.Name.StartsWith("<Id>"))
97+
{
98+
return (sequence++);
99+
}
100+
}
101+
102+
return fallbackGenerator.Generate(context);
103+
}
104+
}
105+
106+
// setup generator to use
107+
var resolver = new CompositeResolver(new[] { new MyClassSequentialIdGenerator() }, new[] { StandardResolver.NonNull });
108+
var fixture = new Fixture(resolver); // fixture is instance version of FixtureFactory
109+
110+
var foo = fixture.CreateMany<MyClass>(100);
111+
foreach (var item in foo)
112+
{
113+
Console.WriteLine(item);
114+
}
115+
```
61116

62117
Author Info
63118
---
@@ -68,4 +123,4 @@ He is known as the creator of [UniRx](https://github.com/neuecc/UniRx/) and [Mes
68123

69124
License
70125
---
71-
This library is under the MIT License.
126+
This library is under the MIT License.

0 commit comments

Comments
 (0)