コード例 #1
0
        public void ViewLocationCacheKeyComparer_EqualsReturnsFalseIfViewNamesAreDifferent(
            string viewName1,
            string viewName2)
        {
            // Arrange
            var actionContext = GetActionContext();
            var viewLocationExpanderContext1 = new ViewLocationExpanderContext(
                actionContext,
                viewName1,
                isPartial: true);
            var viewLocationExpanderContext2 = new ViewLocationExpanderContext(
                actionContext,
                viewName2,
                isPartial: true);

            // 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);
        }
コード例 #2
0
        public void ViewLocationCacheKeyComparer_EqualsReturnsFalseIfViewLocationExpanderIsNullForEitherKey()
        {
            // Arrange
            var viewLocationExpanderContext1 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", "Area1"),
                "View1",
                isPartial: false);

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

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

            // 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);
        }
コード例 #3
0
        public void ViewLocationCacheKeyComparer_EqualsReturnsTrueIfControllerAreaAndViewNamesAreIdentical()
        {
            // Arrange
            var viewLocationExpanderContext1 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", "Area1"),
                "View1",
                isPartial: false);
            var viewLocationExpanderContext2 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", "Area1"),
                "View1",
                isPartial: false);

            // 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);
        }
コード例 #4
0
        public void ViewLocationCacheKeyComparer_EqualsReturnsFalseIfIsAreaNamesAreDifferent(
            string area1,
            string area2)
        {
            // Arrange
            var viewLocationExpanderContext1 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", area1),
                "View1",
                isPartial: false);
            var viewLocationExpanderContext2 = new ViewLocationExpanderContext(
                GetActionContext("Controller1", area2),
                "View1",
                isPartial: false);

            // 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);
        }
コード例 #5
0
        public void CacheKeyIsComputedBasedOnValuesInExpander(ViewLocationExpanderContext context, string expected)
        {
            // Act
            var result = DefaultViewLocationCache.GenerateKey(context);

            // Assert
            Assert.Equal(expected, result);
        }
コード例 #6
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);
        }