Exemple #1
0
        public void FindAffinitizedDestinations_AffinityOptionSettingNotFound_Throw()
        {
            var provider = new ProviderStub(GetDataProtector().Object, AffinityTestHelper.GetLogger <BaseSessionAffinityProvider <string> >().Object);
            var options  = GetOptionsWithUnknownSetting();

            Assert.Throws <ArgumentException>(() => provider.FindAffinitizedDestinations(new DefaultHttpContext(), new[] { new DestinationInfo("dest-A") }, "cluster-1", options));
        }
        public void FindAffinitizedDestination_AffinityDisabledOnCluster_ReturnsAffinityDisabled()
        {
            var provider = new ProviderStub(GetDataProtector().Object, AffinityTestHelper.GetLogger <BaseSessionAffinityProvider <string> >().Object);
            var options  = new ClusterSessionAffinityOptions(false, _defaultOptions.Mode, _defaultOptions.FailurePolicy, _defaultOptions.Settings);

            Assert.Throws <InvalidOperationException>(() => provider.FindAffinitizedDestinations(new DefaultHttpContext(), new[] { new DestinationInfo("1") }, "cluster-1", options));
        }
    public void FindAffinitizedDestination_AffinityDisabledOnCluster_ReturnsAffinityDisabled()
    {
        var provider = new ProviderStub(GetDataProtector().Object, AffinityTestHelper.GetLogger <BaseSessionAffinityPolicy <string> >().Object);
        var options  = new SessionAffinityConfig
        {
            Enabled         = false,
            Policy          = _defaultOptions.Policy,
            FailurePolicy   = _defaultOptions.FailurePolicy,
            AffinityKeyName = _defaultOptions.AffinityKeyName
        };
        var cluster = new ClusterState("cluster");

        Assert.Throws <InvalidOperationException>(() => provider.FindAffinitizedDestinations(new DefaultHttpContext(), cluster, options, new[] { new DestinationState("1") }));
    }
    public void Request_FindAffinitizedDestinations(
        HttpContext context,
        DestinationState[] allDestinations,
        AffinityStatus expectedStatus,
        DestinationState expectedDestination,
        byte[] expectedEncryptedKey,
        bool unprotectCalled,
        LogLevel?expectedLogLevel,
        EventId expectedEventId)
    {
        var dataProtector  = GetDataProtector();
        var logger         = AffinityTestHelper.GetLogger <BaseSessionAffinityPolicy <string> >();
        var provider       = new ProviderStub(dataProtector.Object, logger.Object);
        var cluster        = new ClusterState("cluster");
        var affinityResult = provider.FindAffinitizedDestinations(context, cluster, _defaultOptions, allDestinations);

        if (unprotectCalled)
        {
            dataProtector.Verify(p => p.Unprotect(It.Is <byte[]>(b => b.SequenceEqual(expectedEncryptedKey))), Times.Once);
        }

        Assert.Equal(expectedStatus, affinityResult.Status);
        Assert.Same(expectedDestination, affinityResult.Destinations?.FirstOrDefault());

        if (expectedLogLevel != null)
        {
            logger.Verify(
                l => l.Log(expectedLogLevel.Value, expectedEventId, It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()),
                Times.Once);
        }

        if (expectedDestination != null)
        {
            Assert.Equal(1, affinityResult.Destinations.Count);
        }
        else
        {
            Assert.Null(affinityResult.Destinations);
        }
    }