Exemple #1
0
        public void Respect_generic_settings()
        {
            const string behaviorName = "behaviorWithSettings";

            BehaviorExtender.Register <BehaviorWithSettings>(behaviorName);
            try
            {
                var sut = new NZazuFieldBehaviorFactory();
                var behaviorDefinition = new BehaviorDefinition
                {
                    Name     = behaviorName,
                    Settings = new Dictionary <string, string>
                    {
                        { "AnInt", "42" },
                        { "AString", "AString" },
                        { "ADouble", "42.42" },
                        { "ABool", "True" }
                    }
                };
                var behavior = (BehaviorWithSettings)sut.CreateFieldBehavior(behaviorDefinition);

                behavior.AnInt.Should().Be(42);
                behavior.AString.Should().Be("AString");
                behavior.ADouble.Should().Be(42.42);
                behavior.ABool.Should().BeTrue();
            }
            finally
            {
                BehaviorExtender.Unregister(behaviorName);
            }
        }
 public void Support_type_safe_generic_registration()
 {
     lock (new object())
     {
         const string name = "dummy";
         BehaviorExtender.IsRegistered(name).Should().BeFalse();
         BehaviorExtender.Register <DummyFieldBehavior>(name);
         try
         {
             BehaviorExtender.IsRegistered(name).Should().BeTrue();
         }
         finally
         {
             BehaviorExtender.Unregister(name);
         }
     }
 }
        public void Registration_And_Unregistration_Through_Public_Method()
        {
            const string name = "Mock For a Static Thing Which Stays Forever In List";
            var          type = typeof(DummyFieldBehavior);

            // thread-safe?
            lock (new object())
            {
                BehaviorExtender.Register(name, type);
                try
                {
                    var behaviors = BehaviorExtender.GetBehaviors().ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                    behaviors[name].Should().Be(type);
                    behaviors["Empty"].Should().Be(typeof(EmptyNZazuFieldBehavior));
                }
                finally
                {
                    BehaviorExtender.Unregister(name);
                }
            }
        }
Exemple #4
0
        public void Handle_Interface_Implementations()
        {
            const string behaviorName = "IfaceImpl";

            BehaviorExtender.Register <SimpleInterfaceImplementation>(behaviorName);
            try
            {
                var sut      = new NZazuFieldBehaviorFactory();
                var behavior = sut.CreateFieldBehavior(new BehaviorDefinition {
                    Name = behaviorName
                });
                behavior.Should().BeAssignableTo <SimpleInterfaceImplementation>();

                // just to get code coverage
                behavior.AttachTo(null, null);
                behavior.Detach();
            }
            finally
            {
                BehaviorExtender.Unregister(behaviorName);
            }
        }