Symplify.Conversion.SDK 0.5.3

dotnet add package Symplify.Conversion.SDK --version 0.5.3
NuGet\Install-Package Symplify.Conversion.SDK -Version 0.5.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Symplify.Conversion.SDK" Version="0.5.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Symplify.Conversion.SDK --version 0.5.3
#r "nuget: Symplify.Conversion.SDK, 0.5.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Symplify.Conversion.SDK as a Cake Addin
#addin nuget:?package=Symplify.Conversion.SDK&version=0.5.3

// Install Symplify.Conversion.SDK as a Cake Tool
#tool nuget:?package=Symplify.Conversion.SDK&version=0.5.3

Symplify Server-Side Testing SDK for C#

This is the C# implementation of the Symplify Server-Side Testing SDK.

It is a cross platform .NET Core library, to enable integration regardless of e.g. web frameworks used for building applications.

Changes

See CHANGELOG.md.

Requirements

Installing

Using the dotnet CLI:

dotnet add package Symplify.Conversion.SDK

https://www.nuget.org/packages/Symplify.Conversion.SDK has installation instructions for the different .NET development environments.

Usage

On your application startup:

  1. Create an SDK instance (it's meant to be used as a singleton, you can wrap it in a service).
  2. Call LoadConfig to start its config updater loop.
// `yourWebsiteID` comes from your config.
// `httpClient` is an HttpClient, probably injected.
// `LoadConfig` is async and an await ensures the initial configuration loading is complete but as long as you call it it will eventually be loaded, so awaiting is not strictly necessary.
var sstSDK = new SymplifyClient(yourWebsiteID, httpClient);
await sstSDK.LoadConfig();

On each request where you want to use variations:

  1. Call findVariation, providing a CookieJar (see below)
// `cookieJar` is an ICookieJar you need to create, see the CookieJar section
sstSDK.FindVariation("my ab-test", cookieJar)

See the project Symplify.Conversion.SDK.DemoApp for more elaborate example code. Running instructions for it are in CONTRIBUTING.md.

CookieJar

To ensure visitors get the same variation consistently, the SDK needs to read and write cookies. See SST-documentation repository for general cookie setup information.

To be compatible with any web framework, the SDK uses an interface ICookieJar which you implement to provide reading and writing of cookies. Here is an example using IHttpContextAccessor which you can use in eveyr request you handle:

using Microsoft.AspNetCore.Http;
using Symplify.Conversion.SDK.Cookies;

class HttpContextCookieJar : ICookieJar
{
    private readonly string domain;
    private readonly IHttpContextAccessor accessor;

    public HttpContextCookieJar(string domain, IHttpContextAccessor accessor)
    {
        this.domain = domain;
        this.accessor = accessor;
    }

    public string GetCookie(string name)
    {
        return accessor.HttpContext.Request.Cookies[name];
    }

    public void SetCookie(string name, string value, uint expireInDays)
    {
        CookieOptions opts = new();
        opts.Domain = domain;
        opts.Expires = DateTimeOffset.Now.AddDays(expireInDays);
        accessor.HttpContext.Response.Cookies.Append(name, value, opts);
    }
}

If you run test on a site with multiple subdomains, you will need to use a common "parent" domain for the cookies, such as ".example.com" for e.g. "b2b.example.com" and "store.example.com".

Custom audience

It's possible to limit for which requests/visitors a certain test project should apply by using "audience" rules. See Audiences.md for details.

The audience is evaluated when your server calls findVariation, and if the rules you have setup in the audience references "custom attributes" your server must provide the values of these attributes for each request.

For example, you might want a test project to only apply for visitors from a certain country. The audience can be configured in your project, using a custom attribute "country", and then your server provides it when finding the variation on each request:

    // fictional helper function to get discounts for each request we serve
   public double[] getDiscounts(Client sdk, ICookieJar cookieJar)
    {
        // This code assumes you have a `LookupGeoIP` helper function in your project.
        JArray customAttributes = JArray.Parse($"[{{'country': '{LookupGeoIp(usersIPAddress).GetCountry()}'}}]");
        
        // Custom attributes are passed as an JArray, in this case we set 'country'
        // and assume the audience is configured with the "string-attribute" rule to look for specific countries.
        string variation = sdk.FindVariation("Discounts, May 2022", cookieJar, customAttributes);

        switch (variation)
        {
            case "huge":
                return new double[1] { 0.25 };
            case "small":
                return new double[1] { 0.1 };
        }

        // `findVariation` returns empty array if the project audience does not match for
        // a given request. We handle that by a fallthrough return here.
        return new double[1];
    }

SDK Development

See CONTRIBUTING.md or RELEASING.md.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.3 213 6/9/2023
0.5.2 201 3/20/2023
0.5.1 347 11/1/2022
0.5.0 314 11/1/2022
0.3.0 369 8/12/2022
0.2.0 360 6/23/2022
0.1.0 385 6/21/2022
0.0.1-preview03 119 6/17/2022