Beispiel #1
0
        public void GetClrType_Cached_OnlyOneInstance()
        {
            // Arrange
            ClrTypeCache    cache   = new ClrTypeCache();
            Type            clrType = typeof(CacheAddress);
            IEdmComplexType address = _model.SchemaElements.OfType <IEdmComplexType>().FirstOrDefault(c => c.Name == "Address");

            Action cacheCallAndVerify = () =>
            {
                IEdmComplexTypeReference addressTypeTrue = new EdmComplexTypeReference(address, true);
                Type actual = cache.GetClrType(addressTypeTrue, _model);
                Assert.Same(clrType, actual);

                IEdmComplexTypeReference addressTypeFalse = new EdmComplexTypeReference(address, false);
                actual = cache.GetClrType(addressTypeFalse, _model);
                Assert.Same(clrType, actual);

                Assert.Equal(2, cache.EdmToClrTypeCache.Count);
            };

            // Act & Assert
            cacheCallAndVerify();

            // 5 is a magic number, it doesn't matter, just want to call it mulitple times.
            for (int i = 0; i < 5; i++)
            {
                cacheCallAndVerify();
            }

            cacheCallAndVerify();
        }
Beispiel #2
0
        public void GetClrType_Returns_CorrectType()
        {
            // Arrange
            ClrTypeCache    cache   = new ClrTypeCache();
            Type            clrType = typeof(CacheAddress);
            IEdmComplexType address = _model.SchemaElements.OfType <IEdmComplexType>().FirstOrDefault(c => c.Name == "Address");

            // Act & Assert
            IEdmComplexTypeReference addressType = new EdmComplexTypeReference(address, true);
            Type actual = cache.GetClrType(addressType, _model);

            Assert.Same(clrType, actual);

            addressType = new EdmComplexTypeReference(address, false);
            actual      = cache.GetClrType(addressType, _model);
            Assert.Same(clrType, actual);
        }