Skip to content

Commit

Permalink
for Unity
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed May 6, 2019
1 parent ba74606 commit 1e2677e
Show file tree
Hide file tree
Showing 39 changed files with 4,597 additions and 1,774 deletions.
29 changes: 11 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ executors:
# https://hub.docker.com/r/gableroux/unity3d/tags
- image: gableroux/unity3d:2018.3.12f1-windows
jobs:
# .NET Core, Debug(try to build and test).
build-test:
executor: dotnet
steps:
- checkout
- run: dotnet build -c Debug
- run: dotnet test -c Debug --no-build
# Unity, create .unitypackage and make IL2CPP headless build and test it.
build-unity:
executor: unity
steps:
Expand All @@ -33,23 +25,24 @@ jobs:
- run: apt update && apt install libunwind8 -y
- run:
name: Build Linux(Mono)
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod Exporter.BuildCliTestLinux
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend Mono2x /BuildTarget StandaloneLinux64
working_directory: src/RandomFixtureKit.Unity
- run: src/RandomFixtureKit.Unity/bin/linux-x64/tests
- run:
name: Build Windows(IL2CPP)
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod Exporter.BuildCliTestWindows
working_directory: src/RandomFixtureKit.Unity
- store_artifacts:
path: src/RandomFixtureKit.Unity/bin/win-x64
destination: /bin/win-x64
- run: src/RandomFixtureKit.Unity/bin/UnitTest/StandaloneLinux64_Mono2x/test
- run:
name: Export unitypackage
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod Exporter.Export
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
working_directory: src/RandomFixtureKit.Unity
- store_artifacts:
path: src/RandomFixtureKit.Unity/RandomFixtureKit.unitypackage
destination: /RandomFixtureKit.unitypackage
# .NET Core, Debug(try to build and test).
build-test:
executor: dotnet
steps:
- checkout
- run: dotnet build -c Debug
- run: dotnet test -c Debug --no-build
# Unity, create .unitypackage and make IL2CPP headless build and test it.
# .NET Core, Release, create NuGet package and push.
build-push:
executor: dotnet
Expand Down
63 changes: 59 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ Fill random/edge-case value to target type for unit testing, supports both .NET

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

Documantation is not yet but core library is completed. .unitypackage and upm coming soon.

NuGet: [RandomFixtureKit](https://www.nuget.org/packages/RandomFixtureKit)

```
Install-Package RandomFixturekit
```

Unity: [releases/RandomFixtureKit.unitypackage](https://github.com/Cysharp/RandomFixtureKit/releases)

or package.json exists on `src/RandomFixtureKit.Unity/Assets/Scripts/RandomFixtureKit` for unity package manager.

How to use
---

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

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`.

TODO: More sample of combine resolvers and create custom generator.
Custom Generator
---
Implement `IGenerator` and setup composite-resolver, you can control how generate values.


```csharp
// for example, increment Id on create MyClass value.
public class MyClass
{
public int Id { get; set; }
public int Age { get; set; }
public string Name { get; set; }

public override string ToString()
{
return (Id, Age, Name).ToString();
}
}

// Create IGenerator.
public class MyClassSequentialIdGenerator : IGenerator
{
int sequence = 0;
IGenerator fallbackGenerator = new Int32Generator();

// this generator called if requires int value.
public Type Type => typeof(int);

public object Generate(in GenerationContext context)
{
// check target int field belongs MyClass.
if (context.FieldInfo != null)
{
// auto-implemented property's field: <Id>k__BackingField
if (context.FieldInfo.DeclaringType == typeof(MyClass) && context.FieldInfo.Name.StartsWith("<Id>"))
{
return (sequence++);
}
}

return fallbackGenerator.Generate(context);
}
}

// setup generator to use
var resolver = new CompositeResolver(new[] { new MyClassSequentialIdGenerator() }, new[] { StandardResolver.NonNull });
var fixture = new Fixture(resolver); // fixture is instance version of FixtureFactory
var foo = fixture.CreateMany<MyClass>(100);
foreach (var item in foo)
{
Console.WriteLine(item);
}
```

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

License
---
This library is under the MIT License.
This library is under the MIT License.
Loading

0 comments on commit 1e2677e

Please sign in to comment.