public virtual void DeserializeAllMetadataAndCacheIt(Stream byteStream)
        {
            long initialStreamPostion     = byteStream.Position;
            uint metadataByteCount        = byteStream.DeserializeUint32();
            long metadataLastBytePosition = metadataByteCount + sizeof(uint) + initialStreamPostion;

            while (byteStream.Position < metadataLastBytePosition)
            {
                MetadataTypes metadataType = byteStream.DeserializeMetadataType();
                MetadataBase  result       = null;
                switch (metadataType)
                {
                case MetadataTypes.AssemblyMetadata:
                    var assemblyMetadata = new AssemblyMetadata(byteStream);
                    _assemblyCache.Add(assemblyMetadata);
                    result = assemblyMetadata;
                    break;

                case MetadataTypes.ModuleMedatada:
                    var moduleMetadata = new ModuleMetadata(byteStream, _assemblyCache);
                    _moduleCache.Add(moduleMetadata);
                    result = moduleMetadata;
                    break;

                case MetadataTypes.ClassMedatada:
                    var classMetadata = new ClassMetadata(byteStream, _moduleCache);
                    _classCache.Add(classMetadata);
                    result = classMetadata;
                    break;

                case MetadataTypes.MethodMedatada:
                    var methodMetadata = new MethodMetadata(byteStream, _classCache, _sourceLocatorFactory);
                    _methodCache.Add(methodMetadata);
                    result = methodMetadata;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Contract.Assume(result != null);
                Contract.Assume(result.Id != 0);
                Contract.Assume(result.MdToken != 0);
                Contract.Assume(metadataType == result.MetadataType);
            }
        }
        public virtual void DeserializeAllMetadataAndCacheIt(Stream byteStream)
        {
            long initialStreamPostion = byteStream.Position;
            uint metadataByteCount = byteStream.DeserializeUint32();
            long metadataLastBytePosition = metadataByteCount + sizeof (uint) + initialStreamPostion;
            while (byteStream.Position < metadataLastBytePosition)
            {
                MetadataTypes metadataType = byteStream.DeserializeMetadataType();
                MetadataBase result = null;
                switch (metadataType)
                {
                    case MetadataTypes.AssemblyMetadata:
                        var assemblyMetadata = new AssemblyMetadata(byteStream);
                        _assemblyCache.Add(assemblyMetadata);
                        result = assemblyMetadata;
                        break;
                    case MetadataTypes.ModuleMedatada:
                        var moduleMetadata = new ModuleMetadata(byteStream, _assemblyCache);
                        _moduleCache.Add(moduleMetadata);
                        result = moduleMetadata;
                        break;
                    case MetadataTypes.ClassMedatada:
                        var classMetadata = new ClassMetadata(byteStream, _moduleCache);
                        _classCache.Add(classMetadata);
                        result = classMetadata;
                        break;
                    case MetadataTypes.MethodMedatada:
                        var methodMetadata = new MethodMetadata(byteStream, _classCache, _sourceLocatorFactory);
                        _methodCache.Add(methodMetadata);
                        result = methodMetadata;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                Contract.Assume(result != null);
                Contract.Assume(result.Id != 0);
                Contract.Assume(result.MdToken != 0);
                Contract.Assume(metadataType == result.MetadataType);
            }
        }
Exemplo n.º 3
0
        public void SetUp()
        {
            var mockAssemblyCache = new Mock<MetadataCache<AssemblyMetadata>>(MockBehavior.Strict);
            mockAssemblyCache.Setup(cache => cache[It.IsAny<uint>()]).Returns(() => null);
            _moduleMetadata = new ModuleMetadata(_moduleBytes.ConvertToMemoryStream(), mockAssemblyCache.Object);

            _mockModuleCache = new Mock<MetadataCache<ModuleMetadata>>(MockBehavior.Strict);
            _mockModuleCache.Setup(cache => cache[It.IsAny<uint>()]).Returns(() => _moduleMetadata).Verifiable();

            _classMetadata = new ClassMetadata(_classBytes.ConvertToMemoryStream(), _mockModuleCache.Object);

            _mockModuleCache.Verify();
        }
Exemplo n.º 4
0
        public void SetUp()
        {
            var mockModuleCache = new Mock<MetadataCache<ModuleMetadata>>(MockBehavior.Strict);
            mockModuleCache.Setup(cache => cache[It.IsAny<uint>()]).Returns(() => null);
            _classMetadata = new ClassMetadata(_classBytes.ConvertToMemoryStream(), mockModuleCache.Object);

            var mockClassCache = new Mock<MetadataCache<ClassMetadata>>(MockBehavior.Strict);
            mockClassCache.Setup(cache => cache[It.IsAny<uint>()]).Returns(_classMetadata);

            _mockMethodLine = new Mock<IMethodLine>(MockBehavior.Strict);
            _mockMethodLine.SetupGet(meLin => meLin.StartLine).Returns(12);
            _mockMethodLine.SetupGet(meLin => meLin.EndLine).Returns(12);
            _mockMethodLine.SetupGet(meLin => meLin.StartIndex).Returns(160);
            _mockMethodLine.SetupGet(meLin => meLin.EndIndex).Returns(220);
            _mockMethodLine.SetupGet(meLin => meLin.StartColumn).Returns(10);
            _mockMethodLine.SetupGet(meLin => meLin.EndColumn).Returns(70);

            var mockSourceLocator = new Mock<ISourceLocator>(MockBehavior.Strict);
            mockSourceLocator.Setup(soLoc => soLoc.GetMethodLines(It.IsAny<uint>())).Returns(
                new[]
                    {
                        _mockMethodLine.Object,
                        _mockMethodLine.Object,
                        _mockMethodLine.Object
                    });

            mockSourceLocator.Setup(soLoc => soLoc.GetSourceFilePath(It.IsAny<uint>())).Returns(SourceFilePath);

            _mockSourceLocatorFactory = new Mock<ISourceLocatorFactory>(MockBehavior.Strict);
            _mockSourceLocatorFactory.Setup(soFac => soFac.GetSourceLocator(It.IsAny<MethodMetadata>())).Returns(
                mockSourceLocator.Object);

            _methodMetadata1 = new MethodMetadata(_method1Bytes.ConvertToMemoryStream(), mockClassCache.Object,
                                                  _mockSourceLocatorFactory.Object);
            _methodMetadata2 = new MethodMetadata(_method2Bytes.ConvertToMemoryStream(), mockClassCache.Object,
                                                  _mockSourceLocatorFactory.Object);
            _methodMetadata3 = new MethodMetadata(_method3Bytes.ConvertToMemoryStream(), mockClassCache.Object,
                                                  _mockSourceLocatorFactory.Object);

            mockClassCache.Verify(cache => cache[It.IsAny<uint>()], Times.Exactly(3));
        }