Beispiel #1
0
        public void By_Double_ShouldBeCacheKeyString()
        {
            const double number = 5.5;
            var          key    = _cacheKeyBuilder.By(number).ToString();

            key.Should().Be(CacheKeyHelper.Format(number.ToString(CultureInfo.InvariantCulture)));
        }
Beispiel #2
0
        public void By_String_ShouldBeCacheKeyString()
        {
            const string text = "test";
            var          key  = _cacheKeyBuilder.By(text).ToString();

            key.Should().Be(CacheKeyHelper.Format(text));
        }
Beispiel #3
0
        public void By_Guid_ShouldBeCacheKeyString()
        {
            var guid = Guid.NewGuid();
            var key  = _cacheKeyBuilder.By(guid).ToString();

            key.Should().Be(CacheKeyHelper.Format(guid));
        }
Beispiel #4
0
        public void By_Integer_ShouldBeCacheKeyString()
        {
            const int number = 5;
            var       key    = _cacheKeyBuilder.By(number).ToString();

            key.Should().Be(CacheKeyHelper.Format(number));
        }
Beispiel #5
0
        public void By_DateTime_ShouldBeCacheKeyString()
        {
            var dateTime = default(DateTime);
            var key      = _cacheKeyBuilder.By(dateTime).ToString();

            key.Should().Be(CacheKeyHelper.Format(dateTime.Ticks));
        }
Beispiel #6
0
        public void By_CacheableObject_ShouldBeCacheKeyString()
        {
            const int    number = 5;
            const string text   = "test";
            var          obj    = new CacheableObject(number, text);
            var          key    = _cacheKeyBuilder.By(obj).ToString();

            key.Should().Be(CacheKeyHelper.Format(number) + CacheKeyHelper.Format(text));
        }
Beispiel #7
0
        public void By_List_ShouldBeCacheKeyString()
        {
            const string text1 = "test1";
            const string text2 = "test2";
            var          list  = new List <string> {
                text1, text2
            };
            var key = _cacheKeyBuilder.By(list).ToString();

            key.Should().Be(CacheKeyHelper.Format(text1) + CacheKeyHelper.Format(text2));
        }
Beispiel #8
0
        public void GetKey_FunctionWithoutParameters_ShouldReturnCacheKeyString()
        {
            using var fixture = new ExpressionCacheBaseFixture();
            var key      = fixture.ExpressionCacheBase.GetKey(() => _testFunctions.FunctionWithoutParameters());
            var asyncKey = fixture.ExpressionCacheBase.GetKey(() => _testFunctions.FunctionWithoutParametersAsync());

            key.Should().Be(CacheKeyHelper.Prefix(
                                CacheKeyHelper.Format(_testFunctions.ClassName) +
                                CacheKeyHelper.Format(nameof(_testFunctions.FunctionWithoutParameters))));
            asyncKey.Should().Be(CacheKeyHelper.Prefix(
                                     CacheKeyHelper.Format(_testFunctions.ClassName) +
                                     CacheKeyHelper.Format(nameof(_testFunctions.FunctionWithoutParametersAsync))));
        }
Beispiel #9
0
        public void GetKey_FunctionWithTwoParameters_ShouldReturnCacheKeyString()
        {
            const int    parameterOne = 1;
            const string parameterTwo = "Testing";

            using var fixture = new ExpressionCacheBaseFixture();
            var key      = fixture.ExpressionCacheBase.GetKey(() => _testFunctions.FunctionWithTwoParameters(parameterOne, parameterTwo));
            var asyncKey = fixture.ExpressionCacheBase.GetKey(() => _testFunctions.FunctionWithTwoParametersAsync(parameterOne, parameterTwo));

            key.Should().Be(CacheKeyHelper.Prefix(
                                CacheKeyHelper.Format(_testFunctions.ClassName) +
                                CacheKeyHelper.Format(nameof(_testFunctions.FunctionWithTwoParameters)) +
                                CacheKeyHelper.Format(parameterOne) +
                                CacheKeyHelper.Format(parameterTwo)));
            asyncKey.Should().Be(CacheKeyHelper.Prefix(
                                     CacheKeyHelper.Format(_testFunctions.ClassName) +
                                     CacheKeyHelper.Format(nameof(_testFunctions.FunctionWithTwoParametersAsync)) +
                                     CacheKeyHelper.Format(parameterOne) +
                                     CacheKeyHelper.Format(parameterTwo)));
        }
        public void GetKey_FunctionWithOneParameter_ShouldReturnCacheKeyString()
        {
            const int parameter = 1;

            using (var fixture = new ExpressionCacheBaseFixture())
            {
                var key      = fixture.ExpressionCacheBase.GetKey(() => _testFunctions.FunctionWithOneParameter(parameter));
                var asyncKey = fixture.ExpressionCacheBase.GetKey(() => _testFunctions.FunctionWithOneParameterAsync(parameter));

                key.ShouldBe(
                    CacheKeyHelper.Format(_testFunctions.ClassName) +
                    CacheKeyHelper.Format(nameof(_testFunctions.FunctionWithOneParameter)) +
                    CacheKeyHelper.Format(parameter)
                    );
                asyncKey.ShouldBe(
                    CacheKeyHelper.Format(_testFunctions.ClassName) +
                    CacheKeyHelper.Format(nameof(_testFunctions.FunctionWithOneParameterAsync)) +
                    CacheKeyHelper.Format(parameter)
                    );
            }
        }
Beispiel #11
0
        public void By_Null_ShouldBeCacheKeyString()
        {
            var key = _cacheKeyBuilder.By(null).ToString();

            key.Should().Be(CacheKeyHelper.Format(CacheKeyBuilder.NullString));
        }