Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Inforitnl/growthbook-c-sharp into f…
Browse files Browse the repository at this point in the history
…eature/automated-github-builds-test-and-deploy
  • Loading branch information
Mastermindzh committed Oct 30, 2023
2 parents 0d72e72 + 4bfab2e commit 8a24e63
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 103 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.1.1]

- Handle null namespace property.

## [0.1.0]

- Added a CHANGELOG.md based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added standard rules for markdown files in .editorconfig
- Ensured that all files have a consistent line-ending (based on what they already have)
- Added `IGrowthbook` interface
- Added `IGrowthBook` interface

## [0.0.6] - 2022-06-07

Expand Down
6 changes: 3 additions & 3 deletions GrowthBook/GrowthBook.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand All @@ -11,7 +11,7 @@
<RepositoryUrl>https://github.com/growthbook/growthbook-csharp.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>GrowthBook,A/B test,feature toggle</PackageTags>
<Version>0.0.7</Version>
<Version>0.1.1</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,4 +25,4 @@
</None>
</ItemGroup>

</Project>
</Project>
4 changes: 2 additions & 2 deletions GrowthBook/IGrowthbook.cs → GrowthBook/IGrowthBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public interface IGrowthbook
IDictionary<string, ExperimentAssignment> GetAllResults();

/// <summary>
/// Subscribes to a GrowthBook instance to be alerted every time growthbook.run is called.
/// Subscribes to a GrowthBook instance to be alerted every time GrowthBook.run is called.
/// This is different from the tracking callback since it also fires when a user is not included in an experiment.
/// </summary>
/// <param name="callback">The callback to trigger when growthbook.run is called.</param>
/// <param name="callback">The callback to trigger when GrowthBook.run is called.</param>
/// <returns>An action callback that can be used to unsubscribe.</returns>
Action Subscribe(Action<Experiment, ExperimentResult> callback);

Expand Down
4 changes: 2 additions & 2 deletions GrowthBook/NamespaceTupleConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand All @@ -22,7 +22,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
{
return new Namespace((JArray)token);
}
return new JsonSerializer().Deserialize(reader, objectType);
return null;
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
Expand Down
101 changes: 31 additions & 70 deletions Test/GrowthBook.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,80 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{649FDBB7-2442-4DF5-B493-401D2ECF527D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFramework>net6</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Remove="Json\custom-cases.json" />
<None Remove="Json\FeatureDictionary.json" />
<None Remove="Json\GrowthBookContext.json" />
<None Remove="Json\GrowthBookContext.NoFeatures.json" />
<None Remove="Json\SingleFeatureDictionary.WithNameSpace..json" />
<None Remove="Json\standard-cases.json" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<EmbeddedResource Include="Json\custom-cases.json" />
<EmbeddedResource Include="Json\FeatureDictionary.json" />
<EmbeddedResource Include="Json\GrowthBookContext.json" />
<EmbeddedResource Include="Json\GrowthBookContext.NoFeatures.json" />
<EmbeddedResource Include="Json\SingleFeatureDictionary.WithNameSpace..json" />
<EmbeddedResource Include="Json\standard-cases.json" />
</ItemGroup>

<ItemGroup>
<Compile Include="GrowthBookTests.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<PackageReference Include="MSTest" Version="3.1.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
<None Include="custom-cases.json" />
<None Include="standard-cases.json" />
<None Include="packages.config" />
<ProjectReference Include="..\GrowthBook\GrowthBook.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GrowthBook\GrowthBook.csproj">
<Project>{eb2e6969-d39e-4093-b267-826226de50dc}</Project>
<Name>GrowthBook</Name>
</ProjectReference>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" />
</Project>

</Project>
8 changes: 5 additions & 3 deletions Test/GrowthBookTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using GrowthBook;
using Growthbook.Tests.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using Test;

namespace Growthbook.Tests
{
Expand All @@ -22,8 +24,8 @@ public static void TestFixtureSetup(TestContext context)
throw new ArgumentNullException(nameof(context));
}

testCases = JObject.Parse(File.ReadAllText("../../standard-cases.json"));
customCases = JObject.Parse(File.ReadAllText("../../custom-cases.json"));
testCases = JObject.Parse(JsonTestHelpers.GetTestJson("standard-cases"));
customCases = JObject.Parse(JsonTestHelpers.GetTestJson("custom-cases"));
}

public static string GetTestNames(MethodInfo methodInfo, object[] values)
Expand Down
39 changes: 39 additions & 0 deletions Test/Json/FeatureDictionary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"backend_test1": {
"DefaultValue": [],
"Rules": []
},
"backend_test2": {
"DefaultValue": [],
"Rules": []
},
"backend_test3": {
"DefaultValue": [],
"Rules": [
{
"Condition": {
"tenantName": []
},
"Coverage": 1,
"Force": [],
"Variations": null,
"Key": null,
"Weights": null,
"Namespace": null,
"HashAttribute": "id"
},
{
"Condition": {
"tenantName": []
},
"Coverage": 1,
"Force": [],
"Variations": null,
"Key": null,
"Weights": null,
"Namespace": null,
"HashAttribute": "id"
}
]
}
}
11 changes: 11 additions & 0 deletions Test/Json/GrowthBookContext.NoFeatures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"EnvironmentName": "Dev",
"Enabled": true,
"Attributes": {},
"Url": null,
"Features": {
},
"ForcedVariations": {},
"QaMode": false,
"TrackingCallback": null
}
48 changes: 48 additions & 0 deletions Test/Json/GrowthBookContext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"EnvironmentName": "Dev",
"Enabled": true,
"Attributes": {},
"Url": null,
"Features": {
"backend_test1": {
"DefaultValue": [],
"Rules": []
},
"backend_test2": {
"DefaultValue": [],
"Rules": []
},
"backend_test3": {
"DefaultValue": [],
"Rules": [
{
"Condition": {
"tenantName": []
},
"Coverage": 1,
"Force": [],
"Variations": null,
"Key": null,
"Weights": null,
"Namespace": null,
"HashAttribute": "id"
},
{
"Condition": {
"tenantName": []
},
"Coverage": 1,
"Force": [],
"Variations": null,
"Key": null,
"Weights": null,
"Namespace": null,
"HashAttribute": "id"
}
]
}
},
"ForcedVariations": {},
"QaMode": false,
"TrackingCallback": null
}
33 changes: 33 additions & 0 deletions Test/Json/JsonTestHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.IO;
using System.Reflection;

namespace Growthbook.Tests.Json;

public static class JsonTestHelpers
{
public static string GetTestJson(string jsonName)
{
return GetTestJson(
Assembly.GetExecutingAssembly(),
$"{typeof(JsonTestHelpers).Namespace}/{jsonName}.json");
}

/// <summary>
/// Returns the contents of the embedded resource as a string.
/// </summary>
public static string GetTestJson(Assembly assembly, string resourceName)
{
using Stream stream = assembly.GetManifestResourceStream(resourceName.Replace('/', '.'));

if (stream == null)
{
throw new InvalidOperationException($"The resource {resourceName} is not available - make sure that it has Build Action set to Embedded Resource");
}

using StreamReader reader = new StreamReader(stream);

var json = reader.ReadToEnd();
return json;
}
}
19 changes: 19 additions & 0 deletions Test/Json/SingleFeatureDictionary.WithNameSpace..json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"backend_test3": {
"DefaultValue": [],
"Rules": [
{
"Condition": {
"tenantName": []
},
"Coverage": 1,
"Force": [],
"Variations": null,
"Key": null,
"Weights": null,
"Namespace": null,
"HashAttribute": "id"
}
]
}
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8a24e63

Please sign in to comment.