protected override IUnityContainer DoRegisterDefaults(
            IUnityContainer container,
            IDictionary <RegistrationLookup, ContainerRegistration> registrations)
        {
            ClassMetadataRegistrar
            .RegisterMetadata()
            .Register <WebException, WebExceptionDumpMetadata>()
            ;

            DumpFormat.Delegate         = "{4}{0}.{3}";
            DumpFormat.Type             = "{0}";
            DumpFormat.SequenceTypeName = "";
            DumpFormat.TypeInfo         = "{1}.{0}";

            if (!registrations.ContainsKey(new RegistrationLookup(typeof(InjectionPolicy), "ServicePolicy")))
            {
                container
                .Configure <Interception>()
                .AddPolicy("ServicePolicy")
                .AddMatchingRule <TagAttributeMatchingRule>(
                    new InjectionConstructor("ServicePolicy", false))

                .AddCallHandler <ServiceCallTraceCallHandler>(
                    new ContainerControlledLifetimeManager(),
                    new InjectionConstructor(Facility.LogWriter))

                .AddCallHandler <ServiceParameterValidatingCallHandler>(
                    new ContainerControlledLifetimeManager(),
                    new InjectionConstructor())
                ;
            }

            return(container);
        }
Exemplo n.º 2
0
        public void TestGetClassDumpAttribute_InCache()
        {
            ClassMetadataRegistrar.RegisterMetadata();

            var dumpAttribute = ClassMetadataResolver.GetClassDumpData(typeof(Exception));

            Assert.AreSame(typeof(ExceptionDumpMetadata), dumpAttribute.Metadata);
            Assert.AreSame(DumpAttribute.Default, dumpAttribute.DumpAttribute);
        }
Exemplo n.º 3
0
        public static void AssemblyInitialize(TestContext context)
        {
            try
            {
                ClassMetadataRegistrar
                .RegisterMetadata()
                .Register <ArgumentValidationException, ArgumentValidationExceptionDumpMetadata>()
                .Register <ValidationResult, ValidationResultDumpMetadata>()
                .Register <ValidationResults, ValidationResultsDumpMetadata>()
                .Register <ConfigurationErrorsException, ConfigurationErrorsExceptionDumpMetadata>()
                ;

                DIContainer
                .Initialize();

                lock (DIContainer.Root)
                {
                    var registrations = DIContainer.Root.GetRegistrationsSnapshot();

                    DIContainer
                    .Root
                    .UnsafeRegister(Facility.Registrar, registrations, true)
                    ;


                    // add AOP policies
                    DIContainer
                    .Root
                    .Configure <Interception>()
                    .AddPolicy(BaseTestCalls.Track)
                    .AddMatchingRule <TagAttributeMatchingRule>(
                        new InjectionConstructor(BaseTestCalls.Track, false))
                    .AddCallHandler <TrackCallHandler>(
                        new ContainerControlledLifetimeManager(),
                        new InjectionProperty(nameof(ICallHandler.Order), 1))
                    ;

                    DIContainer
                    .Root
                    .Configure <Interception>()
                    .AddPolicy(BaseTestCalls.Trace)
                    .AddMatchingRule <TagAttributeMatchingRule>(
                        new InjectionConstructor(BaseTestCalls.Trace, false))
                    .AddCallHandler <CallTraceCallHandler>(
                        new InjectionProperty(nameof(ICallHandler.Order), 2))
                    ;
                }
            }
            catch (Exception x)
            {
                context.WriteLine("{0}", x.DumpString());
                throw;
            }
        }
Exemplo n.º 4
0
 public static void AssemblyInitialize(TestContext context)
 {
     try
     {
         ClassMetadataRegistrar.RegisterMetadata();
     }
     catch (Exception x)
     {
         context.WriteLine("{0}", x.DumpString());
         throw;
     }
 }
Exemplo n.º 5
0
        public void TestSetClassDumpData()
        {
            Reset();
            ClassMetadataRegistrar.RegisterMetadata();
            var initialCacheSize = ClassMetadataResolver.GetSnapshotTypesDumpData().Count();

            ClassMetadataResolver.SetClassDumpData(typeof(ClassMetadataCacheTest), typeof(ClassMetadataResolver), new DumpAttribute(false), true);

            Assert.AreEqual(initialCacheSize + 1, ClassMetadataResolver.GetSnapshotTypesDumpData().Count());
            Assert.AreEqual(
                new ClassDumpData(typeof(ClassMetadataResolver), new DumpAttribute(false)),
                ClassMetadataResolver.GetSnapshotTypesDumpData()[typeof(ClassMetadataCacheTest)]);
        }
Exemplo n.º 6
0
        public void TestSetClassDumpData_NullArg3()
        {
            Reset();
            ClassMetadataRegistrar.RegisterMetadata();
            var initialCacheSize = TypesDumpData.Count();

            ClassMetadataResolver.SetClassDumpData(typeof(ClassMetadataCacheTest), typeof(ClassMetadataResolver), null, true);

            Assert.AreEqual(initialCacheSize + 1, TypesDumpData.Count());
            Assert.AreEqual(
                new ClassDumpData(typeof(ClassMetadataResolver), null),
                TypesDumpData[typeof(ClassMetadataCacheTest)]);
        }
Exemplo n.º 7
0
        public static void Initialize(TestContext context)
        {
            _schemas = new XmlSchemaSet();
            _schemas.Add(
                "urn:schemas-vm-com:Aspects.Linq.Expressions.Serialization",
                XmlReader.Create(
                    new FileStream(@"Expression.xsd", FileMode.Open, FileAccess.Read, FileShare.Read),
                    new XmlReaderSettings {
                DtdProcessing = DtdProcessing.Parse
            }));

            ClassMetadataRegistrar.RegisterMetadata();
        }
Exemplo n.º 8
0
            static void InitializeObjectDumper()
            {
                // initialize the ObjectDumper
                ClassMetadataRegistrar
                .RegisterMetadata()
                .Register <SqlException, SqlExceptionDumpMetadata>()
                .Register <SqlError, SqlErrorDumpMetadata>()
                .Register <WebException, WebExceptionDumpMetadata>()
                ;

                DumpFormat.Delegate         = "{4}{0}.{3}";
                DumpFormat.Type             = "{0}";
                DumpFormat.SequenceTypeName = "";
                DumpFormat.TypeInfo         = "{1}.{0}";
            }
Exemplo n.º 9
0
            static IUnityContainer RegisterCommon(
                IUnityContainer container,
                IDictionary <RegistrationLookup, IContainerRegistration> registrations,
                bool isTest = false)
            {
                ClassMetadataRegistrar
                .RegisterMetadata()
                ;

                return(container
                       .RegisterInstanceIfNot <ValidatorFactory>(registrations, ValidationFactory.DefaultCompositeValidatorFactory)
                       .RegisterTypeIfNot <IConfigurationProvider, AppConfigProvider>(registrations, new ContainerControlledLifetimeManager())
                       .RegisterTypeIfNot <ExceptionManager>(registrations, new ContainerControlledLifetimeManager(), new InjectionFactory(c => ExceptionPolicyProvider.CreateExceptionManager()))
                       .RegisterTypeIfNot <LogWriter>(registrations, new ContainerControlledLifetimeManager(), new InjectionFactory(c => LogConfigProvider.CreateLogWriter(LogConfigProvider.LogConfigurationFileName, string.Empty, isTest)))
                       .UnsafeRegister(LogConfigProvider.Registrar, registrations, isTest)
                       .UnsafeRegister(ExceptionPolicyProvider.Registrar, registrations, isTest)
                       );
            }
Exemplo n.º 10
0
        public virtual IUnityContainer RegisterDefaults()
        {
            if (InitializeLatch.Latched())
            {
                // ObjectDumper registrations
                ClassMetadataRegistrar
                .RegisterMetadata()
                .Register <ArgumentValidationException, ArgumentValidationExceptionDumpMetadata>()
                .Register <ValidationResult, ValidationResultDumpMetadata>()
                .Register <ValidationResults, ValidationResultsDumpMetadata>()
                .Register <ConfigurationErrorsException, ConfigurationErrorsExceptionDumpMetadata>()
                ;

                // container initialization:
                DIContainer.Initialize();

                lock (DIContainer.Root)
                {
                    var registrations = DIContainer.Root.GetRegistrationsSnapshot();

                    DIContainer
                    .Root
                    .UnsafeRegister(Facility.Registrar, registrations)
                    .UnsafeRegister(ServiceFaultFromExceptionHandlingPolicies.Registrar, registrations)
                    .UnsafeRegister(BindingConfigurator.Registrar, registrations)
                    .RegisterTypeIfNot <IWcfContextUtilities, WcfContextUtilities>(registrations, new ContainerControlledLifetimeManager())

                    // (re)register properly the service with the interceptor and the policy injection behavior, etc. whistles and blows,
                    // unless it was already registered before getting the registrations above.
                    .RegisterTypeIfNot <TContract, TService>(
                        registrations,
                        ObtainServiceResolveName(),
                        ServiceLifetimeManager,
                        DIContainer.PolicyInjection())
                    ;

                    // register the defaults of the inheriting classes
                    DoRegisterDefaults(DIContainer.Root, registrations);
                }
                VmAspectsEventSource.Log.ServiceHostFactoryRegisteredDefaults <TService>();
            }
            return(DIContainer.Root);
        }
Exemplo n.º 11
0
        static int Main(string[] args)
        {
            int result = 0;

            try
            {
                ClassMetadataRegistrar.RegisterMetadata();

                using (var parser = new Parser(s =>
                {
                    s.CaseInsensitiveEnumValues = true;
                    s.CaseSensitive = false;
                    s.HelpWriter = Console.Error;
                }))
                    result = parser
                             .ParseArguments <CreateParameters, ImportParameters, ExportParameters>(args)
                             .MapResult(
                        (CreateParameters p) => Create(p),
                        (ImportParameters p) => Import(p),
                        (ExportParameters p) => Export(p),
                        errors => 1);
            }
            catch (Exception x)
            {
                Debug.WriteLine(x.DumpString());
                Console.WriteLine(x.Message);

                result = 1;
            }

#if DEBUG
            if (_parameters?.WaitAtTheEnd == true)
            {
                Console.Write(Resources.PressAnyKey);
                Console.ReadKey(true);
            }
#endif

            return(result);
        }
Exemplo n.º 12
0
        public static void AssemblyInitialize(TestContext context)
        {
            try
            {
                ClassMetadataRegistrar.RegisterMetadata()
                .Register <ArgumentValidationException, ArgumentValidationExceptionDumpMetadata>()
                .Register <ValidationResult, ValidationResultDumpMetadata>()
                .Register <ValidationResults, ValidationResultsDumpMetadata>()
                .Register <ConfigurationErrorsException, ConfigurationErrorsExceptionDumpMetadata>()
                ;

                DIContainer
                .Initialize()
                .Register(Facility.Registrar, true)
                .Register(TestEFRepository.Registrar, true)
                .RegisterInstanceIfNot <IMoneyDefaults>(new MoneyDefaults());
            }
            catch (Exception x)
            {
                context.WriteLine("{0}", x.DumpString());
                throw;
            }
        }
Exemplo n.º 13
0
 static void RegisterMetadata()
 {
     ClassMetadataRegistrar.RegisterMetadata()
     .Register <SqlException, SqlExceptionDumpMetadata>()
     .Register <SqlError, SqlErrorDumpMetadata>()
     .Register <MetadataItem, MetadataItemDumpMetadata>()
     .Register <UpdateException, UpdateExceptionDumpMetadata>()
     .Register <DbUpdateException, DbUpdateExceptionDumpMetadata>()
     .Register <ObjectStateEntry, ObjectStateEntryDumpMetadata>()
     .Register <DbEntityEntry, DbEntityEntryDumpMetadata>()
     .Register <DbEntityValidationResult, DbEntityValidationResultDumpMetadata>()
     .Register <DbValidationError, DbValidationErrorDumpMetadata>()
     .Register <ObjectContext, ObjectContextDumpMetadata>()
     .Register <MetadataProperty, MetadataPropertyDumpMetadata>()
     .Register <FieldMetadata, FieldMetadataDumpMetadata>()
     .Register <EntityKey, EntityKeyDumpMetadata>()
     .Register <TypeUsage, TypeUsageDumpMetadata>()
     .Register <AssociationSet, AssociationSetDumpMetadata>()
     .Register <EntityRecordInfo, EntityRecordInfoDumpMetadata>()
     .Register <ReferentialConstraint, ReferentialConstraintDumpMetadata>()
     .Register <RelationshipManager, RelationshipManagerDumpMetadata>()
     .Register <ObjectContext, ObjectContextDumpMetadata>()
     ;
 }
Exemplo n.º 14
0
        public static void ClassInitialize(TestContext testContext)
        {
            try
            {
                ClassMetadataRegistrar
                .RegisterMetadata()
                .Register <UpdateException, UpdateExceptionDumpMetadata>()
                .Register <DbUpdateException, DbUpdateExceptionDumpMetadata>()
                .Register <ObjectStateEntry, ObjectStateEntryDumpMetadata>()
                ;

                var shouldDump = DIContainer.IsInitialized;

                DIContainer.Initialize();

                lock (DIContainer.Root)
                {
                    var registrations = DIContainer.Root.GetRegistrationsSnapshot();

                    DIContainer.Root
                    .UnsafeRegister(Facility.Registrar, registrations, true)
                    .UnsafeRegister(TestEFRepository.Registrar, registrations, true)
                    ;
                }

                if (shouldDump)
                {
                    DIContainer.Root.DebugDump();
                }
            }
            catch (Exception x)
            {
                testContext.WriteLine("{0}", x.DumpString());
                throw;
            }
        }
Exemplo n.º 15
0
        static void InitializeContainer()
        {
            try
            {
                ClassMetadataRegistrar
                .RegisterMetadata()
                .Register <ArgumentValidationException, ArgumentValidationExceptionDumpMetadata>()
                .Register <ValidationResult, ValidationResultDumpMetadata>()
                .Register <ValidationResults, ValidationResultsDumpMetadata>()
                .Register <ConfigurationErrorsException, ConfigurationErrorsExceptionDumpMetadata>()
                ;

                var container = DIContainer.Initialize();

                lock (container)
                {
                    var registrations = container.GetRegistrationsSnapshot();
                    var interception  = container.Configure <Interception>();

                    // add AOP policies
                    interception
                    // Track policy
                    .AddPolicy(BaseTestCalls.Track)
                    .AddMatchingRule <TagAttributeMatchingRule>(
                        new InjectionConstructor(BaseTestCalls.Track, false))
                    .AddCallHandler <TrackCallHandler>(
                        new ContainerControlledLifetimeManager())
                    ;

                    interception
                    // Trace policy
                    .AddPolicy(BaseTestCalls.Trace)
                    .AddMatchingRule <TagAttributeMatchingRule>(
                        new InjectionConstructor(BaseTestCalls.Trace, false))
                    .AddCallHandler <CallTraceCallHandler>()
                    ;

                    // register types to test
                    container

                    // register the facilities
                    .UnsafeRegister(Facility.Registrar, registrations)

                    // object with track policy
                    .RegisterTypeIfNot <ITestCalls, TrackTestCalls>(
                        registrations,
                        BaseTestCalls.Track,
                        DIContainer.PolicyInjection())

                    // object with trace policy
                    .RegisterTypeIfNot <ITestCalls, TraceTestCalls>(
                        registrations,
                        BaseTestCalls.Trace,
                        DIContainer.PolicyInjection())
                    ;

                    // dump the container
                    using (var writer = new StringWriter(CultureInfo.InvariantCulture))
                    {
                        DIContainer.Root.Dump(writer);
                        Debug.WriteLine(
                            $@"
Container registrations:
===============================
{writer.GetStringBuilder()}
===============================
");
                    }
                }
            }
            catch (Exception x)
            {
                Debug.WriteLine(x.DumpString());
                Console.WriteLine(x.DumpString());
                throw;
            }
        }
Exemplo n.º 16
0
 public static void AssemblyInitializer(TestContext testContext)
 {
     ClassMetadataRegistrar.RegisterMetadata();
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            ClassMetadataRegistrar
            .RegisterMetadata()
            .Register <ArgumentValidationException, ArgumentValidationExceptionDumpMetadata>()
            .Register <ValidationResult, ValidationResultDumpMetadata>()
            .Register <ValidationResults, ValidationResultsDumpMetadata>()
            .Register <ConfigurationErrorsException, ConfigurationErrorsExceptionDumpMetadata>()
            ;

            var container = DIContainer.Initialize();

            lock (container)
            {
                var registrations = DIContainer.Root.GetRegistrationsSnapshot();
                var interception  = container.Configure <Interception>();


                //container.AddNewExtension<Interception>();

                interception
                .AddPolicy("test")
                .AddMatchingRule <TagAttributeMatchingRule>(
                    new InjectionConstructor("test", false))
                //.AddMatchingRule<MemberNameMatchingRule>(
                //    new InjectionConstructor(new[] { "Get*", "Save*" }, true))
                .AddCallHandler <CachingCallHandler>(
                    new ContainerControlledLifetimeManager())
                .AddCallHandler <LoggingCallHandler>(
                    new ContainerControlledLifetimeManager())
                .AddCallHandler <TrackCallHandler>(
                    new ContainerControlledLifetimeManager())
                .AddCallHandler <CallTraceCallHandler>()
                ;

                //container.Configure<Interception>()
                //    .AddPolicy("caching")
                //    .AddMatchingRule<TagAttributeMatchingRule>(
                //        new InjectionConstructor("test", false))
                //    .AddMatchingRule<MemberNameMatchingRule>(
                //        new InjectionConstructor(new[] { "Get*", "Save*" }, true))
                //    .AddCallHandler<CachingCallHandler>(
                //        new ContainerControlledLifetimeManager(),
                //        first);

                //container.Configure<Interception>()
                //    .AddPolicy("logging")
                //    .AddMatchingRule<TagAttributeMatchingRule>(
                //        new InjectionConstructor("test", false))
                //    .AddCallHandler<LoggingCallHandler>(
                //        new ContainerControlledLifetimeManager(),
                //        second);

                //container.Configure<Interception>()
                //    .AddPolicy("tracking")
                //    .AddMatchingRule<TagAttributeMatchingRule>(
                //        new InjectionConstructor("test", false))
                //    .AddCallHandler<TrackCallHandler>(
                //        new ContainerControlledLifetimeManager(),
                //        third);

                container
                .Register(Facility.Registrar, true)

                .RegisterTypeIfNot <ITenantStore, TenantStore>(
                    registrations,
                    "test",
                    new InterceptionBehavior <PolicyInjectionBehavior>(),
                    new Interceptor <TransparentProxyInterceptor>());
            }

            DIContainer.Root.DebugDump();

            var store = container.Resolve <ITenantStore>("test");

            store.SaveTenant(new Tenant {
                Name = "gogo"
            });
            store.UploadLogo("gogo", new byte[] { 1, 2, 3, });

            var t = store.GetTenant("gogo");

            t.Logo = new byte[] { 11, 12, 13, };

            Debug.WriteLine(
                string.Format("\n{0}\nThat's it Val!", Facility.LogWriter.GetTestLogText()));
        }