Skip to content

Commit

Permalink
Added initial implementation of Wonka.UnitTests project.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaerith committed Aug 27, 2020
1 parent be955a8 commit f5b284c
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ WonkaSystem/WonkaImport/obj/
Solidity/WonkaEngine/bin/
WonkaSystem/Wonka.Storage/bin/
WonkaSystem/Wonka.Storage/obj/
Wonka.UnitTests/obj
Wonka.UnitTests/bin
102 changes: 102 additions & 0 deletions Wonka.UnitTests/BasicWonkaTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Moq;
using Xunit;

using Wonka.BizRulesEngine;
using Wonka.Eth.Contracts;
using Wonka.MetaData;

namespace Wonka.UnitTests
{
public class BasicWonkaTests
{
public const string CONST_INFURA_IPFS_GATEWAY_URL = "https://ipfs.infura.io/ipfs/";

private readonly WonkaRefEnvironment _refEnvHandle = null;

private readonly WonkaBizRulesEngine _rulesEngine = null;

private readonly Mock<IOrchestrate> _client;

public BasicWonkaTests()
{
var metadataSource =
new Wonka.BizRulesEngine.Samples.WonkaBreMetadataTestSource();

_refEnvHandle = WonkaRefEnvironment.CreateInstance(false, metadataSource);

using (var client = new System.Net.Http.HttpClient())
{
var sIpfsUrl = String.Format("{0}/{1}", CONST_INFURA_IPFS_GATEWAY_URL, "QmXcsGDQthxbGW8C3Sx9r4tV9PGSj4MxJmtXF7dnXN5XUT");
var sRulesContents = client.GetStringAsync(sIpfsUrl).Result;

_rulesEngine = new WonkaBizRulesEngine(new StringBuilder(sRulesContents), metadataSource);
}

_client = new Mock<IOrchestrate>();
}

[Fact]
public void Metadata_NotEmptyCollection()
{
var collection = _refEnvHandle.AttrCache;

// Assert
Assert.NotEmpty(collection);
}

[Fact]
public void RulesEngine_NotEmptyCollection()
{
var collection = _rulesEngine.RuleTreeRoot.ChildRuleSets;

// Assert
Assert.NotEmpty(collection);
}

[Fact]
public void Metadata_SingleItem()
{
var collection = _refEnvHandle.AttrCache;

// Assert
Assert.True(collection.Exists(x => x.AttrName == "AuditReviewFlag"));
}

[Fact]
public void RulesEngine_SingleItem()
{
var collection = _rulesEngine.RuleTreeRoot.ChildRuleSets;

// Assert
Assert.Single(collection);

// Assert
Assert.True(collection.Exists(x => x.Description.Contains("the incoming record")));
}

[Fact]
public void Orchestrate_WithBadData()
{
bool bContractInitialized = false;

try
{
var contract =
_client.Object.GetContract(new BizRulesEngine.RuleTree.WonkaBizSource("", "", "", "", "", "", "", null));

bContractInitialized = true;
}
catch (Exception ex)
{
bContractInitialized = false;
}

Assert.False(bContractInitialized);
}
}
}
17 changes: 17 additions & 0 deletions Wonka.UnitTests/Wonka.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.14.5" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WonkaSystem\WonkaEth\Wonka.Eth.csproj" />
<ProjectReference Include="..\WonkaSystem\WonkaBre\Wonka.BizRulesEngine.csproj" />
<ProjectReference Include="..\WonkaSystem\WonkaRef\Wonka.MetaData.csproj" />
<ProjectReference Include="..\WonkaSystem\WonkaPrd\Wonka.Product.csproj" />
</ItemGroup>
</Project>
42 changes: 24 additions & 18 deletions WonkaSystem/WonkaSystem.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.852
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WonkaSystem", "WonkaSystem\WonkaSystem.csproj", "{054C2B2B-3263-4C28-AEB4-A32E0207D912}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WonkaSystem", "WonkaSystem\WonkaSystem.csproj", "{054C2B2B-3263-4C28-AEB4-A32E0207D912}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wonka.MetaData", "WonkaRef\Wonka.MetaData.csproj", "{F1813200-E062-4D82-A63D-4C9CD3BC73F4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wonka.Product", "WonkaPrd\Wonka.Product.csproj", "{3C3F0446-5FBF-4AED-B4C0-A6D96C905445}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wonka.BizRulesEngine", "WonkaBre\Wonka.BizRulesEngine.csproj", "{D3F26FB8-89AC-44A5-96C3-6A785AF0DE51}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wonka.Eth", "WonkaEth\Wonka.Eth.csproj", "{A45CE3D8-9F1B-4401-8561-A5A7F79BB57C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wonka.IpfsW", "WonkaIpfs\Wonka.IpfsW.csproj", "{CDE8B010-2F96-4801-8DEE-BB110FC709A9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wonka.Import", "WonkaImport\Wonka.Import.csproj", "{2DFD6C9A-8E9D-40F4-A8DD-B65A98B7A116}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wonka.Storage", "Wonka.Storage\Wonka.Storage.csproj", "{B12A2912-AC33-42C7-B01E-EE54B0A60815}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wonka.Product", "WonkaPrd\Wonka.Product.csproj", "{14E2CF0C-87E9-46EA-AA2D-4664E525A2E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wonka.BizRulesEngine", "WonkaBre\Wonka.BizRulesEngine.csproj", "{68058384-9DEB-43D5-8423-BE71D80D8D56}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wonka.Storage", "Wonka.Storage\Wonka.Storage.csproj", "{D8FAB512-41FD-4E24-A0AC-F73DBF44B78B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wonka.UnitTests", "..\Wonka.UnitTests\Wonka.UnitTests.csproj", "{5384D070-C496-4F9D-90CF-B7E4D412D3FA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -33,14 +35,6 @@ Global
{F1813200-E062-4D82-A63D-4C9CD3BC73F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1813200-E062-4D82-A63D-4C9CD3BC73F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1813200-E062-4D82-A63D-4C9CD3BC73F4}.Release|Any CPU.Build.0 = Release|Any CPU
{3C3F0446-5FBF-4AED-B4C0-A6D96C905445}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C3F0446-5FBF-4AED-B4C0-A6D96C905445}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C3F0446-5FBF-4AED-B4C0-A6D96C905445}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C3F0446-5FBF-4AED-B4C0-A6D96C905445}.Release|Any CPU.Build.0 = Release|Any CPU
{D3F26FB8-89AC-44A5-96C3-6A785AF0DE51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3F26FB8-89AC-44A5-96C3-6A785AF0DE51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3F26FB8-89AC-44A5-96C3-6A785AF0DE51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3F26FB8-89AC-44A5-96C3-6A785AF0DE51}.Release|Any CPU.Build.0 = Release|Any CPU
{A45CE3D8-9F1B-4401-8561-A5A7F79BB57C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A45CE3D8-9F1B-4401-8561-A5A7F79BB57C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A45CE3D8-9F1B-4401-8561-A5A7F79BB57C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -53,10 +47,22 @@ Global
{2DFD6C9A-8E9D-40F4-A8DD-B65A98B7A116}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2DFD6C9A-8E9D-40F4-A8DD-B65A98B7A116}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2DFD6C9A-8E9D-40F4-A8DD-B65A98B7A116}.Release|Any CPU.Build.0 = Release|Any CPU
{B12A2912-AC33-42C7-B01E-EE54B0A60815}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B12A2912-AC33-42C7-B01E-EE54B0A60815}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B12A2912-AC33-42C7-B01E-EE54B0A60815}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B12A2912-AC33-42C7-B01E-EE54B0A60815}.Release|Any CPU.Build.0 = Release|Any CPU
{14E2CF0C-87E9-46EA-AA2D-4664E525A2E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14E2CF0C-87E9-46EA-AA2D-4664E525A2E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14E2CF0C-87E9-46EA-AA2D-4664E525A2E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14E2CF0C-87E9-46EA-AA2D-4664E525A2E1}.Release|Any CPU.Build.0 = Release|Any CPU
{68058384-9DEB-43D5-8423-BE71D80D8D56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68058384-9DEB-43D5-8423-BE71D80D8D56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68058384-9DEB-43D5-8423-BE71D80D8D56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68058384-9DEB-43D5-8423-BE71D80D8D56}.Release|Any CPU.Build.0 = Release|Any CPU
{D8FAB512-41FD-4E24-A0AC-F73DBF44B78B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8FAB512-41FD-4E24-A0AC-F73DBF44B78B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8FAB512-41FD-4E24-A0AC-F73DBF44B78B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8FAB512-41FD-4E24-A0AC-F73DBF44B78B}.Release|Any CPU.Build.0 = Release|Any CPU
{5384D070-C496-4F9D-90CF-B7E4D412D3FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5384D070-C496-4F9D-90CF-B7E4D412D3FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5384D070-C496-4F9D-90CF-B7E4D412D3FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5384D070-C496-4F9D-90CF-B7E4D412D3FA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit f5b284c

Please sign in to comment.