Пример #1
0
        public void CanTraverseFuncitonFollowedByProperty()
        {
            //-- Arrange

            StaticTargetOne.ResetTimesCalled();
            StaticTargetOne.SetMe = "ABC";

            DeriveClassFrom <object>()
            .DefaultConstructor()
            .ImplementInterface <AncestorRepository.ITargetObjectCaller>()
            .Method <object, object>(intf => intf.CallTheTarget).Implement((m, value) => {
                var temp1 = m.Local <string>(initialValue: Static.Prop(() => StaticTargetOne.SetMe));
                var temp2 = m.Local <string>();
                temp2.Assign(temp1.Func <Type>(x => x.GetType).Prop <string>(x => x.FullName));
                m.Return(temp2);
            });

            //-- Act

            var obj    = CreateClassInstanceAs <AncestorRepository.ITargetObjectCaller>().UsingDefaultConstructor();
            var result = obj.CallTheTarget(null);

            //-- Assert

            Assert.That(result, Is.EqualTo("System.String"));
        }
Пример #2
0
        public void CanCallStaticVoidMethod()
        {
            //-- Arrange

            StaticTargetOne.ResetTimesCalled();

            DeriveClassFrom <object>()
            .DefaultConstructor()
            .ImplementInterface <AncestorRepository.ITargetObjectCaller>()
            .Method <object, object>(intf => intf.CallTheTarget).Implement((m, value) => {
                Static.Void(StaticTargetOne.CallMe);
                m.Return(null);
            });

            //-- Act

            var obj = CreateClassInstanceAs <AncestorRepository.ITargetObjectCaller>().UsingDefaultConstructor();

            obj.CallTheTarget(null);
            obj.CallTheTarget(null);

            //-- Assert

            Assert.That(StaticTargetOne.TimesCalled, Is.EqualTo(2));
        }
Пример #3
0
        public void CanGetStaticPropertyValue()
        {
            //-- Arrange

            StaticTargetOne.ResetTimesCalled();

            DeriveClassFrom <object>()
            .DefaultConstructor()
            .ImplementInterface <AncestorRepository.ITargetObjectCaller>()
            .Method <object, object>(intf => intf.CallTheTarget).Implement((m, value) => {
                m.Return(Static.Prop(() => StaticTargetOne.TimesCalled).CastTo <object>());
            });

            //-- Act

            var obj = CreateClassInstanceAs <AncestorRepository.ITargetObjectCaller>().UsingDefaultConstructor();

            StaticTargetOne.IncrementMe(123);

            var propertyValue = (int)obj.CallTheTarget(null);

            //-- Assert

            Assert.That(propertyValue, Is.EqualTo(123));
            Assert.That(StaticTargetOne.TimesCalled, Is.EqualTo(123));
        }
Пример #4
0
        public void CanCallStaticNonVoidFunctionWithArguments()
        {
            //-- Arrange

            StaticTargetOne.ResetTimesCalled();

            DeriveClassFrom <object>()
            .DefaultConstructor()
            .ImplementInterface <AncestorRepository.ITargetValueTypeCaller>()
            .Method <int, object>(intf => intf.CallTheTarget).Implement((m, value) => {
                m.Return(Static.Func(StaticTargetOne.IncrementMe, value).CastTo <object>());
            });

            //-- Act

            var obj = CreateClassInstanceAs <AncestorRepository.ITargetValueTypeCaller>().UsingDefaultConstructor();

            var value1 = (int)obj.CallTheTarget(111);
            var value2 = (int)obj.CallTheTarget(222);

            //-- Assert

            Assert.That(StaticTargetOne.TimesCalled, Is.EqualTo(333));
            Assert.That(value1, Is.EqualTo(0));
            Assert.That(value2, Is.EqualTo(111));
        }
Пример #5
0
        public void CanSetStaticPropertyValue()
        {
            //-- Arrange

            StaticTargetOne.ResetTimesCalled();

            DeriveClassFrom <object>()
            .DefaultConstructor()
            .ImplementInterface <AncestorRepository.ITargetValueTypeCaller>()
            .Method <int, object>(intf => intf.CallTheTarget).Implement((m, value) => {
                Static.Prop(() => StaticTargetOne.SetMe).Assign(value.Func <string>(x => x.ToString));
                m.Return(null);
            });

            //-- Act

            var obj = CreateClassInstanceAs <AncestorRepository.ITargetValueTypeCaller>().UsingDefaultConstructor();

            obj.CallTheTarget(98765);

            //-- Assert

            Assert.That(StaticTargetOne.SetMe, Is.EqualTo("98765"));
        }