Exemple #1
0
        public void ConfigurationRegistersHookPointsCorrectly()
        {
            var configuration = new DomainConfiguration();

            Assert.False(configuration.HasHookPoint(typeof(object)));
            Assert.Null(configuration.GetHookPoint <object>());
            Assert.False(configuration.HasHookPoints(typeof(object)));
            Assert.False(configuration.GetHookPoints <object>().Any());

            var singletonHookPoint = new object();

            configuration.SetHookPoint(typeof(object), singletonHookPoint);
            Assert.True(configuration.HasHookPoint(typeof(object)));
            Assert.Same(singletonHookPoint,
                        configuration.GetHookPoint <object>());
            Assert.False(configuration.HasHookPoints(typeof(object)));
            Assert.False(configuration.GetHookPoints <object>().Any());

            var multiCastHookPoint1 = new object();

            configuration.AddHookPoint(typeof(object), multiCastHookPoint1);
            Assert.Same(singletonHookPoint,
                        configuration.GetHookPoint <object>());
            Assert.True(configuration.HasHookPoints(typeof(object)));
            Assert.True(configuration.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPoint1 }));

            var multiCastHookPoint2 = new object();

            configuration.AddHookPoint(typeof(object), multiCastHookPoint2);
            Assert.True(configuration.HasHookPoints(typeof(object)));
            Assert.True(configuration.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPoint1, multiCastHookPoint2 }));
        }
Exemple #2
0
        public void EmptyConfigurationIsConfiguredCorrectly()
        {
            var configuration = new DomainConfiguration();

            Assert.Null(configuration.Key);
            Assert.NotNull(configuration.BaseConfiguration);
            Assert.Null(configuration.BaseConfiguration.Key);
            Assert.Null(configuration.BaseConfiguration.BaseConfiguration);
            Assert.True(configuration.BaseConfiguration.IsCommitted);
            Assert.False(configuration.IsCommitted);

            Assert.True(configuration.GetHookPoint <IModelHandler>() is DefaultModelHandler);
            Assert.True(configuration.GetHookPoint <IQueryHandler>() is DefaultQueryHandler);
            Assert.True(configuration.GetHookPoint <ISubmitHandler>() is DefaultSubmitHandler);
        }
Exemple #3
0
        public void ConfigurationWithProfilerReturnsProfiledHookPoints()
        {
            var configuration = new DomainConfiguration();
            var profiler      = new TestDomainProfiler();

            configuration.AddHookPoint(typeof(IDomainProfiler), profiler);

            // Profilers are not themselves profiled
            Assert.Same(profiler, configuration
                        .GetHookPoints <IDomainProfiler>().Single());

            var singletonHookPoint         = new object();
            var singletonHookPointProfiled = new object();

            profiler.RegisterProfiledInstance(
                singletonHookPoint, singletonHookPointProfiled);
            configuration.SetHookPoint(typeof(object), singletonHookPoint);
            Assert.Same(singletonHookPointProfiled,
                        configuration.GetHookPoint <object>());

            var multiCastHookPoint         = new object();
            var multiCastHookPointProfiled = new object();

            profiler.RegisterProfiledInstance(
                multiCastHookPoint, multiCastHookPointProfiled);
            configuration.AddHookPoint(typeof(object), multiCastHookPoint);
            Assert.True(configuration.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPointProfiled }));
        }
Exemple #4
0
        public void DerivedConfigurationIsConfiguredCorrectly()
        {
            var baseConfig    = new DomainConfiguration();
            var derivedConfig = new DomainConfiguration(baseConfig);

            Assert.Same(baseConfig, derivedConfig.BaseConfiguration);

            Assert.False(derivedConfig.HasProperty("Test"));
            Assert.Null(derivedConfig.GetProperty <string>("Test"));

            baseConfig.SetProperty("Test", "Test");
            Assert.True(derivedConfig.HasProperty("Test"));
            Assert.Equal("Test", derivedConfig.GetProperty <string>("Test"));

            derivedConfig.SetProperty("Test", "Test2");
            Assert.True(derivedConfig.HasProperty("Test"));
            Assert.Equal("Test2", derivedConfig.GetProperty <string>("Test"));
            Assert.Equal("Test", baseConfig.GetProperty <string>("Test"));

            derivedConfig.ClearProperty("Test");
            Assert.True(derivedConfig.HasProperty("Test"));
            Assert.Equal("Test", derivedConfig.GetProperty <string>("Test"));

            var singletonHookPoint = new object();

            baseConfig.SetHookPoint(typeof(object), singletonHookPoint);
            Assert.True(derivedConfig.HasHookPoint(typeof(object)));
            Assert.Same(singletonHookPoint,
                        derivedConfig.GetHookPoint <object>());

            var derivedSingletonHookPoint = new object();

            derivedConfig.SetHookPoint(typeof(object), derivedSingletonHookPoint);
            Assert.True(derivedConfig.HasHookPoint(typeof(object)));
            Assert.Same(derivedSingletonHookPoint,
                        derivedConfig.GetHookPoint <object>());
            Assert.Same(singletonHookPoint,
                        baseConfig.GetHookPoint <object>());

            var multiCastHookPoint1 = new object();

            baseConfig.AddHookPoint(typeof(object), multiCastHookPoint1);
            Assert.True(derivedConfig.HasHookPoints(typeof(object)));
            Assert.True(derivedConfig.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPoint1 }));

            var multiCastHookPoint2 = new object();

            derivedConfig.AddHookPoint(typeof(object), multiCastHookPoint2);
            Assert.True(derivedConfig.HasHookPoints(typeof(object)));
            Assert.True(derivedConfig.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPoint1, multiCastHookPoint2 }));
            Assert.True(baseConfig.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPoint1 }));

            var multiCastHookPoint3 = new object();

            baseConfig.AddHookPoint(typeof(object), multiCastHookPoint3);
            Assert.True(derivedConfig.HasHookPoints(typeof(object)));
            Assert.True(derivedConfig.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPoint1, multiCastHookPoint3, multiCastHookPoint2 }));
            Assert.True(baseConfig.GetHookPoints <object>()
                        .SequenceEqual(new object[] { multiCastHookPoint1, multiCastHookPoint3 }));
        }