public void AffinitizeRequest_AffinityDisabled_DoNothing()
    {
        var dataProtector = GetDataProtector();
        var provider      = new ProviderStub(dataProtector.Object, AffinityTestHelper.GetLogger <BaseSessionAffinityPolicy <string> >().Object);

        Assert.Throws <InvalidOperationException>(() => provider.AffinitizeResponse(new DefaultHttpContext(), new ClusterState("cluster"), new SessionAffinityConfig(), new DestinationState("id")));
    }
    public void AffinitizeRequest_RequestIsAffinitized_DoNothing()
    {
        var dataProtector = GetDataProtector();
        var provider      = new ProviderStub(dataProtector.Object, AffinityTestHelper.GetLogger <BaseSessionAffinityPolicy <string> >().Object);
        var context       = new DefaultHttpContext();

        provider.DirectlySetExtractedKeyOnContext(context, "ExtractedKey");
        provider.AffinitizeResponse(context, new ClusterState("cluster"), _defaultOptions, new DestinationState("id"));
        Assert.Null(provider.LastSetEncryptedKey);
        dataProtector.Verify(p => p.Protect(It.IsAny <byte[]>()), Times.Never);
    }
    public void AffinitizeRequest_RequestIsNotAffinitized_SetAffinityKey()
    {
        var dataProtector = GetDataProtector();
        var provider      = new ProviderStub(dataProtector.Object, AffinityTestHelper.GetLogger <BaseSessionAffinityPolicy <string> >().Object);
        var destination   = new DestinationState("dest-A");

        provider.AffinitizeResponse(new DefaultHttpContext(), new ClusterState("cluster"), _defaultOptions, destination);
        Assert.Equal("ZGVzdC1B", provider.LastSetEncryptedKey);
        var keyBytes = Encoding.UTF8.GetBytes(destination.DestinationId);

        dataProtector.Verify(p => p.Protect(It.Is <byte[]>(b => b.SequenceEqual(keyBytes))), Times.Once);
    }