Esempio n. 1
0
        public override bool VisitMethodDefinitionStatement(MethodDefinitionStatement methodDef)
        {
            if (!identifierService.IsValidMethodName(methodDef.Name))
            {
                errorReport.Error("TODOFILENAME", methodDef.Position, "'{0}' is an invalid method name.", methodDef.Name);

                return(false);
            }

            TransientType owner = methodDef.SymbolTable.CurrentTypeDefinition;

            System.Diagnostics.Debug.Assert(owner != null);

            try
            {
                owner.AddMethod(methodDef);
            }
            catch (Exception ex)
            {
                errorReport.Error("TODOFILENAME", methodDef.Position, ex.Message, methodDef.Name);

                return(false);
            }

            return(base.VisitMethodDefinitionStatement(methodDef));
        }
Esempio n. 2
0
        public void ShouldSelectConstructorWithMostResolvableParametersFromTypeImplementation()
        {
            var map = new Mock<IDependencyContainer>();
            map.Expect(m => m.Contains(It.IsAny<Dependency>())).Returns(true);
            map.Expect(m => m.Dependencies).Returns(new IDependency[] { });

            var expectedConstructor = typeof(Vehicle).GetConstructor(new Type[] { typeof(IPerson) });
            IImplementation<ConstructorInfo> implementation = new TransientType(typeof(Vehicle), map.Object, new ConstructorResolver());

            Assert.AreSame(implementation.Target, expectedConstructor);
        }
Esempio n. 3
0
        public void ShouldSelectConstructorWithMostResolvableParametersFromTypeImplementation()
        {
            var map = new Mock <IDependencyContainer>();

            map.Expect(m => m.Contains(It.IsAny <Dependency>())).Returns(true);
            map.Expect(m => m.Dependencies).Returns(new IDependency[] { });

            var expectedConstructor = typeof(Vehicle).GetConstructor(new Type[] { typeof(IPerson) });
            IImplementation <ConstructorInfo> implementation = new TransientType(typeof(Vehicle), map.Object, new ConstructorResolver());

            Assert.AreSame(implementation.Target, expectedConstructor);
        }
Esempio n. 4
0
        private void CreateField(SingleVariableDeclarationStatement decl)
        {
            if (decl.Identifier.Type == IdentifierType.Local)
            {
                return;
            }

            TransientType type = decl.SymbolTable.CurrentTypeDefinition;

            System.Diagnostics.Debug.Assert(type != null);

            type.AddField(decl);
        }
Esempio n. 5
0
        public void ShouldCallCacheOnCachedServiceType()
        {
            var map                  = new DependencyMap();
            var dependency           = new Dependency(typeof(IFoo));
            var implementation       = new TransientType(typeof(Foo), map, new ConstructorResolver());
            var cachedImplementation = new CachedInstantiation(implementation);

            map.AddSingletonService <ICache, MockCache>();
            map.AddService(dependency, cachedImplementation);

            // Compile the container
            var container = map.CreateContainer();

            // Grab the service instance
            var firstResult  = container.GetInstance <IFoo>();
            var secondResult = container.GetInstance <IFoo>();

            Assert.IsNotNull(firstResult);
            Assert.AreSame(firstResult, secondResult);
        }
Esempio n. 6
0
        public void ShouldCallCacheOnCachedServiceType()
        {
            var map = new DependencyMap();
            var dependency = new Dependency(typeof(IFoo));
            var implementation = new TransientType(typeof(Foo), map, new ConstructorResolver());
            var cachedImplementation = new CachedInstantiation(implementation);

            map.AddSingletonService<ICache, MockCache>();
            map.AddService(dependency, cachedImplementation);

            // Compile the container
            var container = map.CreateContainer();

            // Grab the service instance
            var firstResult = container.GetInstance<IFoo>();
            var secondResult = container.GetInstance<IFoo>();

            Assert.IsNotNull(firstResult);
            Assert.AreSame(firstResult, secondResult);
        }