public void InvokingGetAfterSet_ReturnsCachedItem(ViewLocationExpanderContext context)
        {
            // Arrange
            var cache = new DefaultViewLocationCache();
            var value = new ViewLocationCacheResult(
                Guid.NewGuid().ToString(),
                new[]
                {
                    Guid.NewGuid().ToString(),
                    Guid.NewGuid().ToString()
                });

            // Act - 1
            cache.Set(context, value);
            var result = cache.Get(context);

            // Assert - 1
            Assert.Equal(value, result);

            // Act - 2
            result = cache.Get(context);

            // Assert - 2
            Assert.Equal(value, result);
        }
        public void Get_GeneratesCacheKeyIfItemDoesNotExist(ViewLocationExpanderContext context)
        {
            // Arrange
            var cache = new DefaultViewLocationCache();

            // Act
            var result = cache.Get(context);

            // Assert
            Assert.Null(result);
        }
        public void Get_ReturnsNoneResultIfItemDoesNotExist(ViewLocationExpanderContext context)
        {
            // Arrange
            var cache = new DefaultViewLocationCache();

            // Act
            var result = cache.Get(context);

            // Assert
            Assert.Equal(result, ViewLocationCacheResult.None);
        }
        public void Get_GeneratesCacheKeyIfItemDoesNotExist(ViewLocationExpanderContext context)
        {
            // Arrange
            var cache = new DefaultViewLocationCache();

            // Act
            var result = cache.Get(context);

            // Assert
            Assert.Null(result);
        }
Example #5
0
        public void Get_ReturnsNoneResultIfItemDoesNotExist(ViewLocationExpanderContext context)
        {
            // Arrange
            var cache = new DefaultViewLocationCache();

            // Act
            var result = cache.Get(context);

            // Assert
            Assert.Equal(result, ViewLocationCacheResult.None);
        }
        public void InvokingGetAfterSet_ReturnsCachedItem(ViewLocationExpanderContext context)
        {
            // Arrange
            var cache = new DefaultViewLocationCache();
            var value = Guid.NewGuid().ToString();

            // Act
            cache.Set(context, value);
            var result = cache.Get(context);

            // Assert
            Assert.Equal(value, result);
        }
Example #7
0
        public void ViewLocationCacheKeyComparer_EqualsReturnsTrueIfValuesAreSame()
        {
            // Arrange
            var viewLocationExpanderContext1 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", "Area1"),
                "View1",
                isPartial: false);

            viewLocationExpanderContext1.Values = new Dictionary <string, string>
            {
                { "somekey1", "value1" },
                { "somekey2", "value2" },
            };

            var viewLocationExpanderContext2 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", "Area1"),
                "View1",
                isPartial: false);

            viewLocationExpanderContext2.Values = new Dictionary <string, string>
            {
                { "somekey2", "value2" },
                { "somekey1", "value1" },
            };

            // Act
            var key1 = DefaultViewLocationCache.GenerateKey(
                viewLocationExpanderContext1,
                copyViewExpanderValues: false);

            var key2 = DefaultViewLocationCache.GenerateKey(
                viewLocationExpanderContext2,
                copyViewExpanderValues: false);

            var result = CacheKeyComparer.Equals(key1, key2);
            var hash1  = CacheKeyComparer.GetHashCode(key1);
            var hash2  = CacheKeyComparer.GetHashCode(key2);

            // Assert
            Assert.True(result);
            Assert.Equal(hash1, hash2);
        }
Example #8
0
        public void ViewLocationCacheKeyComparer_EqualsReturnsFalseIfKeysAreDifferent(
            string keyName1,
            string keyName2)
        {
            // Arrange
            var viewLocationExpanderContext1 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", "Area1"),
                "View1",
                isPartial: false);

            viewLocationExpanderContext1.Values = new Dictionary <string, string>
            {
                { keyName1, "somevalue" }
            };

            var viewLocationExpanderContext2 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", "Area1"),
                "View1",
                isPartial: false);

            viewLocationExpanderContext2.Values = new Dictionary <string, string>
            {
                { keyName2, "somevalue" },
            };

            // Act
            var key1 = DefaultViewLocationCache.GenerateKey(
                viewLocationExpanderContext1,
                copyViewExpanderValues: false);

            var key2 = DefaultViewLocationCache.GenerateKey(
                viewLocationExpanderContext2,
                copyViewExpanderValues: false);

            var result = CacheKeyComparer.Equals(key1, key2);
            var hash1  = CacheKeyComparer.GetHashCode(key1);
            var hash2  = CacheKeyComparer.GetHashCode(key2);

            // Assert
            Assert.False(result);
            Assert.NotEqual(hash1, hash2);
        }