public void Equals_GenericMethodFromBaseType_NonGenericOverloadInType()
        {
            var methodFromBaseType = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(Proxied), "OverloadedGenericToString", 2);
            var method             = ScriptingHelper.GetInstanceMethod(typeof(ProxiedChildChild), "OverloadedGenericToString", new[] { typeof(int), typeof(int) });

            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, method), Is.False);
        }
        public static ObjectChangeHistoryData CreateFromScript(string username, SqlConnection conn, string script)
        {
            if (ConfigHelper.Current == null || !ConfigHelper.Current.PragmaSql_ObjectChangeHistoryLogEnabled)
            {
                return(null);
            }

            if (conn == null)
            {
                return(null);
            }

            int    ObjectType = DBObjectType.None;
            bool   isAlter    = false;
            string objectName = String.Empty;

            objectName = ScriptingHelper.GetObjectNameFromScript(script, ref ObjectType, ref isAlter);
            if (String.IsNullOrEmpty(objectName) || ObjectType == DBObjectType.None)
            {
                return(null);
            }

            ObjectChangeHistoryData result = new ObjectChangeHistoryData();

            result.ServerName   = conn.DataSource;
            result.DatabaseName = conn.Database;
            result.ObjectName   = objectName;
            result.ObjectScript = script;
            result.ObjectType   = DBConstants.GetObjectTypeAbb(ObjectType);
            result.Comment      = String.Empty;
            result.CreatedBy    = username;

            return(result);
        }
        public void Equals_GenericClass_MethodWithGenericClassArgumentsFromBaseType()
        {
            var methodFromBaseType = ScriptingHelper.GetInstanceMethod(typeof(ProxiedChildGeneric <int, string>), "ProxiedChildGenericToString", new[] { typeof(int), typeof(string) });
            var method             = ScriptingHelper.GetInstanceMethod(typeof(ProxiedChildChildGeneric <int, string>), "ProxiedChildGenericToString", new[] { typeof(int), typeof(string) });

            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, method), Is.True);
        }
Example #4
0
    private void ModifyCurrentObject()
    {
      if (_bs.Current == null)
      {
        return;
      }

      DataRowView rw = _bs.Current as DataRowView;
      if (rw == null)
        return;


      int objId = (int)rw.Row.ItemArray[0];
      string objName = (string)rw.Row.ItemArray[2];
      string objType = (string)rw.Row.ItemArray[3];

      if (DBConstants.DoesObjectTypeHasScript(objType))
      {
        int type = DBConstants.GetDBObjectType(objType);
        string script = ScriptingHelper.GetAlterScript(_connParams.ConnectionString, _connParams.Database, objId, type);
        frmScriptEditor editor = ScriptEditorFactory.Create(objName, script, objId, type, _connParams, _connParams.Database);
        ScriptEditorFactory.ShowScriptEditor(editor);
      }

    }
        public void SimplePropertyAccess_GetCustomMember2()
        {
            const string scriptFunctionSourceCode = @"
import clr
def PropertyPathAccess(cascade) :
  return cascade.Child.Child.Child.Child.Child.Child.Child.Child.Child.Name
";

            const int numberChildren                = 10;
            var       cascade                       = new Cascade(numberChildren);
            var       cascadeStableBinding          = new CascadeStableBinding(numberChildren);
            var       cascadeStableBindingFromMixin = ObjectFactory.Create <CascadeStableBindingFromMixin> (ParamList.Create(numberChildren));

            var privateScriptEnvironment = ScriptEnvironment.Create();

            privateScriptEnvironment.Import(typeof(TestDomain.Cascade).Assembly.GetName().Name, typeof(TestDomain.Cascade).Namespace, typeof(TestDomain.Cascade).Name);

            var propertyPathAccessScript = new ScriptFunction <Cascade, string> (
                _scriptContext, ScriptLanguageType.Python,
                scriptFunctionSourceCode, privateScriptEnvironment, "PropertyPathAccess"
                );

            var nrLoopsArray = new[] { 1, 1, 100000 };

            ScriptingHelper.ExecuteAndTime("SimplePropertyAccess_GetCustomMember2 (No StableBinding)", nrLoopsArray, () => propertyPathAccessScript.Execute(cascade));
            ScriptingHelper.ExecuteAndTime("SimplePropertyAccess_GetCustomMember2 (StableBinding from Mixin)", nrLoopsArray, () => propertyPathAccessScript.Execute(cascadeStableBindingFromMixin));
            ScriptingHelper.ExecuteAndTime("SimplePropertyAccess_GetCustomMember2 (StableBinding)", nrLoopsArray, () => propertyPathAccessScript.Execute(cascadeStableBinding));
        }
        public void SimplePropertyAccess_GetCustomMember()
        {
            const string scriptFunctionSourceCode = @"
import clr
def PropertyPathAccess(cascade) :
  return cascade.Child.Child.Child.Child.Child.Child.Child.Child.Child.Name
";

            const int numberChildren = 10;
            var       cascadeWithoutStableBinding = new Cascade(numberChildren);
            var       cascadeStableBinding        = new CascadeStableBinding(numberChildren);

            var privateScriptEnvironment = ScriptEnvironment.Create();

            privateScriptEnvironment.Import(typeof(TestDomain.Cascade).Assembly.GetName().Name, typeof(TestDomain.Cascade).Namespace, typeof(TestDomain.Cascade).Name);

            var propertyPathAccessScript = new ScriptFunction <Cascade, string> (
                _scriptContext, ScriptLanguageType.Python,
                scriptFunctionSourceCode, privateScriptEnvironment, "PropertyPathAccess"
                );

            //var nrLoopsArray = new[] { 1, 1, 10000 };
            var nrLoopsArray = new[] { 1, 1, 100000 };

            // Warm up
            ScriptingHelper.ExecuteAndTime(nrLoopsArray, () => propertyPathAccessScript.Execute(cascadeStableBinding)).Last();

            double timingStableBinding        = ScriptingHelper.ExecuteAndTime(nrLoopsArray, () => propertyPathAccessScript.Execute(cascadeStableBinding)).Last();
            double timingWithoutStableBinding = ScriptingHelper.ExecuteAndTime(nrLoopsArray, () => propertyPathAccessScript.Execute(cascadeWithoutStableBinding)).Last();

            //To.ConsoleLine.e (() => timingStableBinding).e (() => timingWithoutStableBinding);
            //To.ConsoleLine.e ("timingStableBinding / timingWithoutStableBinding = ", timingStableBinding / timingWithoutStableBinding);

            Assert.That(timingStableBinding / timingWithoutStableBinding, Is.LessThan(7.0));
        }
        public void IsMethodEqualToBaseTypeMethod()
        {
            var moduleScopeStub = MockRepository.GenerateStub <ModuleScope> ();

            var baseType    = typeof(ProxiedChildGeneric <int, string>);
            var proxiedType = typeof(ProxiedChildChildGeneric <int, string>);

            var typeFilter = new TypeLevelTypeFilter(new[] { baseType });
            var stableBindingProxyBuilder = new StableBindingProxyBuilder(proxiedType, typeFilter, moduleScopeStub);

            var methodFromBaseType = ScriptingHelper.GetInstanceMethod(baseType, "ProxiedChildGenericToString", new[] { typeof(int), typeof(string) });
            var method             = ScriptingHelper.GetInstanceMethod(proxiedType, "ProxiedChildGenericToString", new[] { typeof(int), typeof(string) });

            Assert.That(methodFromBaseType, Is.Not.EqualTo(method));

            // Shows methodInfo.GetBaseDefinition()-bug: Results should be equal.
            Assert.That(methodFromBaseType.GetBaseDefinition(), Is.Not.EqualTo(method.GetBaseDefinition()));

            Assert.That(methodFromBaseType.ReflectedType, Is.EqualTo(baseType));

            Assert.That(stableBindingProxyBuilder.IsMethodEqualToBaseTypeMethod(method, method), Is.True);
            Assert.That(stableBindingProxyBuilder.IsMethodEqualToBaseTypeMethod(method, methodFromBaseType), Is.True);

            var sumMethod = proxiedType.GetMethod("Sum", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            Assert.That(stableBindingProxyBuilder.IsMethodEqualToBaseTypeMethod(sumMethod, methodFromBaseType), Is.False);
        }
Example #8
0
    private void PerformActionOnCurrentRow()
    {
      if (_bs.Current == null)
      {
        return;
      }

      DataRowView rw = _bs.Current as DataRowView;
      if (rw == null)
        return;

      int objId = (int)rw.Row.ItemArray[0];
      string objType = (string)rw.Row.ItemArray[3];
      string objName = (string)rw.Row.ItemArray[2];

      if (DBConstants.DoesObjectTypeHasScript(objType))
      {
        int type = DBConstants.GetDBObjectType(objType);
        string script = ScriptingHelper.GetAlterScript(_connParams, _connParams.Database, objId, type);
        frmScriptEditor editor = ScriptEditorFactory.Create(objName, script, objId, type, _connParams, _connParams.Database);
        ScriptEditorFactory.ShowScriptEditor(editor);
      }
      else if (DBConstants.DoesObjectTypeHoldsData(objType))
      {
        int type = DBConstants.GetDBObjectType(objType);
        string caption = objName + "{" + _connParams.InfoDbServer + "}";
        string script = " select * from [" + objName + "]";
        bool isReadOnly = (type == DBObjectType.View) ? true : false;

        frmDataViewer viewer = DataViewerFactory.CreateDataViewer(_connParams, _connParams.Database, objName, caption, script, isReadOnly, true);
        DataViewerFactory.ShowDataViewer(viewer);
      }

    }
        public void IsMethodKnownInClass_MethodNotHiddenThroughNew()
        {
            //var moduleScopeStub = MockRepository.GenerateStub<ModuleScope> ();
            var baseType = typeof(Proxied);
            //var typeFilter = new TypeLevelTypeFilter (new[] { baseType });
            var proxiedType = typeof(ProxiedChildChild);
            //var stableBindingProxyBuilder = new StableBindingProxyBuilder (proxiedType, typeFilter, moduleScopeStub);

            var methodFromBaseType = GetAnyInstanceMethod(baseType, "Sum");
            var method             = GetAnyInstanceMethod(proxiedType, "Sum");

            Assert.That(methodFromBaseType, Is.Not.EqualTo(method));

            // Shows methodInfo.GetBaseDefinition()-bug: Results should be equal.
            Assert.That(methodFromBaseType.GetBaseDefinition(), Is.Not.EqualTo(method.GetBaseDefinition()));

            // "Sum" is defined in Proxied
            AssertIsMethodKnownInBaseType(baseType, GetAnyInstanceMethod(baseType, "Sum"), Is.True);
            AssertIsMethodKnownInBaseType(baseType, GetAnyInstanceMethod(typeof(ProxiedChild), "Sum"), Is.True);
            AssertIsMethodKnownInBaseType(baseType, method, Is.True);

            // "OverrideMe" is overridden in ProxiedChild
            AssertIsMethodKnownInBaseType(baseType, GetAnyInstanceMethod(baseType, "OverrideMe"), Is.True);
            AssertIsMethodKnownInBaseType(baseType, GetAnyInstanceMethod(typeof(ProxiedChild), "OverrideMe"), Is.True);
            AssertIsMethodKnownInBaseType(baseType, GetAnyInstanceMethod(proxiedType, "OverrideMe"), Is.True);

            // "PrependName" is redefined with new in ProxiedChildChild
            AssertIsMethodKnownInBaseType(baseType, GetAnyInstanceMethod(baseType, "PrependName"), Is.True);
            //AssertIsMethodKnownInClass (baseType, GetAnyInstanceMethod (typeof (ProxiedChild), "PrependName"), Is.True);
            //AssertIsMethodKnownInClass (baseType, GetAnyInstanceMethod (proxiedType, "PrependName"), Is.False);
            AssertIsMethodKnownInBaseType(baseType,
                                          ScriptingHelper.GetInstanceMethod(typeof(ProxiedChild), "PrependName", new[] { typeof(String) }), Is.True);
            AssertIsMethodKnownInBaseType(baseType,
                                          ScriptingHelper.GetInstanceMethod(proxiedType, "PrependName", new[] { typeof(String) }), Is.False);
        }
Example #10
0
        public void GetAttributeProxy_IsCached()
        {
            var provider = new StableBindingProxyProvider(
                new TypeLevelTypeFilter(new[] { typeof(ProxiedChild) }), CreateModuleScope("GetTypeMemberProxy"));

            var proxied0 = new ProxiedChildChildChild("ABCccccccccccccccccc");
            var proxied1 = new ProxiedChildChildChild("xyzzzzzzzzz");

            const string attributeName       = "PrependName";
            var          typeMemberProxy0    = provider.GetAttributeProxy(proxied0, attributeName);
            var          customMemberTester0 = new GetCustomMemberTester(typeMemberProxy0);
            var          result0             = ScriptingHelper.ExecuteScriptExpression <string> ("p0.XYZ('simsalbum',2)", customMemberTester0);

            Assert.That(result0, Is.EqualTo("ProxiedChild ProxiedChild: ABCccccccccccccccccc simsalbum, THE NUMBER=2"));


            var typeMemberProxy1 = provider.GetAttributeProxy(proxied1, attributeName);

            Assert.That(typeMemberProxy0, Is.SameAs(typeMemberProxy1));

            var customMemberTester1 = new GetCustomMemberTester(typeMemberProxy1);
            var result1             = ScriptingHelper.ExecuteScriptExpression <string> ("p0.ABCDEFG('Schlaf')", customMemberTester1);

            Assert.That(result1, Is.EqualTo("xyzzzzzzzzz Schlaf"));
        }
        public void Equals_GenericClass_GenericMethodFromBaseType()
        {
            var methodFromBaseType = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(ProxiedChildGeneric <int, string>), "ProxiedChildGenericToString", 1);
            var method             = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(ProxiedChildChildGeneric <int, string>), "ProxiedChildGenericToString", 1);

            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, method), Is.True);
        }
Example #12
0
        private void PerformActionOnFirstSelectedRow( )
        {
            if (grd.SelectedRows.Count == 0)
            {
                return;
            }

            int    objId   = -1;
            string objType = String.Empty;
            string objName = String.Empty;


            DataGridViewRow row = grd.SelectedRows[0];

            DataGridViewCell cellName  = row.Cells[0];
            DataGridViewCell cellType  = row.Cells[1];
            DataGridViewCell cellObjid = row.Cells[2];

            if (cellName.ValueType != typeof(string) || cellName.Value == null)
            {
                return;
            }

            if (cellType.ValueType != typeof(string) || cellType.Value == null)
            {
                return;
            }

            if (cellObjid.ValueType != typeof(int) || cellObjid.Value == null)
            {
                return;
            }

            objId   = (int)cellObjid.Value;
            objType = (string)cellType.Value;
            objName = (string)cellName.Value;

            if (DBConstants.DoesObjectTypeHasScript(objType))
            {
                int    type   = DBConstants.GetDBObjectType(objType);
                string script = String.Empty;
                using (SqlConnection conn = _connParams.CreateSqlConnection(true, false))
                {
                    script = ScriptingHelper.GetAlterScript(conn, objId, type);
                }
                frmScriptEditor editor = ScriptEditorFactory.Create(objName, script, objId, type, _connParams, _dbName);
                ScriptEditorFactory.ShowScriptEditor(editor);
            }
            else if (DBConstants.DoesObjectTypeHoldsData(objType))
            {
                int    type       = DBConstants.GetDBObjectType(objType);
                string caption    = objName + "{" + _dbName + " on " + _connParams.Server + "}";
                string script     = " select * from [" + objName + "]";
                bool   isReadOnly = (type == DBObjectType.View) ? true : false;

                frmDataViewer viewer = DataViewerFactory.CreateDataViewer(_connParams, _dbName, objName, caption, script, isReadOnly, true);
                DataViewerFactory.ShowDataViewer(viewer);
            }
        }
        public void Equals_DifferingArgumentsMethodFromBaseType()
        {
            var methodFromBaseType = ScriptingHelper.GetInstanceMethod(typeof(ProxiedChild), "BraKet", new[] { typeof(string), typeof(int) });
            var method             = ScriptingHelper.GetInstanceMethod(typeof(ProxiedChildChild), "BraKet", new Type[0]);

            Assert.That(methodFromBaseType, Is.Not.EqualTo(method));
            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, method), Is.False);
        }
        public void Equals_MethodFromBaseType()
        {
            var methodFromBaseType = ScriptingHelper.GetInstanceMethod(typeof(Proxied), "Sum");
            var method             = ScriptingHelper.GetInstanceMethod(typeof(ProxiedChildChild), "Sum");

            Assert.That(methodFromBaseType, Is.Not.EqualTo(method));
            Assert.That(methodFromBaseType.GetBaseDefinition(), Is.Not.EqualTo(method.GetBaseDefinition()));
            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, method), Is.True);
        }
        public void Equals_OverloadedGenericMethodFromBaseType()
        {
            var methodFromBaseType = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(Proxied), "OverloadedGenericToString", 2);
            var method             = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(ProxiedChildChild), "OverloadedGenericToString", 2);

            Assert.That(methodFromBaseType, Is.Not.EqualTo(method));
            Assert.That(methodFromBaseType.GetBaseDefinition(), Is.Not.EqualTo(method.GetBaseDefinition()));
            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, method), Is.True);
        }
        public void Equals_MixedArgumentGenericMethodFromNonRelatedTypes()
        {
            var method = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(Test1), "MixedArgumentsTest", 2);
            var methodWithSameSignature           = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(Test2), "MixedArgumentsTest", 2);
            var methodWithSwappedGenericArguments = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(Test3), "MixedArgumentsTest", 2);

            Assert.That(MethodInfoEqualityComparer.Get.Equals(method, methodWithSameSignature), Is.True);
            Assert.That(MethodInfoEqualityComparer.Get.Equals(method, methodWithSwappedGenericArguments), Is.False);
        }
        protected void AssertHasSameExplicitInterfaceMethod(Type interfaceType, Type type0, Type type1, string methodName, params Type[] parameterTypes)
        {
            var methodFromType0 = ScriptingHelper.GetExplicitInterfaceMethod(interfaceType, type0, methodName, parameterTypes);

            Assert.That(methodFromType0, Is.Not.Null);
            var methodFromType1 = ScriptingHelper.GetExplicitInterfaceMethod(interfaceType, type1, methodName, parameterTypes);

            Assert.That(methodFromType1, Is.Not.Null);
            Assert.That(_methodInfoEqualityComparerIgnoreVirtual.Equals(methodFromType0, methodFromType1), Is.True);
        }
Example #18
0
        private void ModifySelectedObjects( )
        {
            if (grd.SelectedRows.Count == 0)
            {
                return;
            }

            int    objId   = -1;
            string objType = String.Empty;
            string objName = String.Empty;
            IList <frmScriptEditor> editors = new List <frmScriptEditor>();

            foreach (DataGridViewRow row in grd.SelectedRows)
            {
                DataGridViewCell cellName  = row.Cells[0];
                DataGridViewCell cellType  = row.Cells[1];
                DataGridViewCell cellObjid = row.Cells[2];

                if (cellName.ValueType != typeof(string) || cellName.Value == null)
                {
                    continue;
                }

                if (cellType.ValueType != typeof(string) || cellType.Value == null)
                {
                    continue;
                }

                if (cellObjid.ValueType != typeof(int) || cellObjid.Value == null)
                {
                    continue;
                }

                objId   = (int)cellObjid.Value;
                objType = (string)cellType.Value;
                objName = (string)cellName.Value;

                if (DBConstants.DoesObjectTypeHasScript(objType))
                {
                    int    type   = DBConstants.GetDBObjectType(objType);
                    string script = String.Empty;
                    using (SqlConnection conn = _connParams.CreateSqlConnection(true, false))
                    {
                        script = ScriptingHelper.GetAlterScript(conn, objId, type);
                    }
                    frmScriptEditor editor = ScriptEditorFactory.Create(objName, script, objId, type, _connParams, _dbName);
                    editors.Add(editor);
                }
            }

            foreach (frmScriptEditor editor in editors)
            {
                ScriptEditorFactory.ShowScriptEditor(editor);
            }
        }
        public void BuildProxyType_AmbigousExplicitInterfaceProperties_With_PublicInterfaceImplementation()
        {
            var knownBaseTypes            = new[] { typeof(ProxiedChildChild) };
            var knownInterfaceTypes       = new[] { typeof(IProperty), typeof(IPropertyAmbigous2) };
            var knownTypes                = knownBaseTypes.Union(knownInterfaceTypes).ToArray();
            var typeFilter                = new TypeLevelTypeFilter(knownTypes);
            var proxiedType               = typeof(ProxiedChildChildChild);
            var stableBindingProxyBuilder = new StableBindingProxyBuilder(proxiedType, typeFilter, CreateModuleScope("BuildProxyType_ExplicitInterfaceProperty"));
            var proxyType = stableBindingProxyBuilder.BuildProxyType();

            Assert.That(proxyType.GetInterface("IPropertyAmbigous2"), Is.Not.Null);
            Assert.That(proxyType.GetInterface("IPropertyAmbigous1"), Is.Null);

            // Create proxy instance, initializing it with class to be proxied
            var proxied = new ProxiedChildChildChild("PC");

            object proxy = Activator.CreateInstance(proxyType, proxied);

            const string expectedPropertyValue = "ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous PC";

            Assert.That(((IPropertyAmbigous2)proxied).PropertyAmbigous, Is.EqualTo(expectedPropertyValue));

            //To.ConsoleLine.e ("proxyType.GetAllProperties()", proxyType.GetAllProperties ()).nl ().e (proxyType.GetAllProperties ().Select(pi => pi.Attributes)).nl (2).e ("proxyType.GetAllMethods()", proxyType.GetAllMethods ());


            var proxyPropertyInfoPublicProperty = proxyType.GetProperty("PropertyAmbigous", _publicInstanceFlags);

            Assert.That(proxyPropertyInfoPublicProperty, Is.Not.Null);

            Assert.That(ScriptingHelper.ExecuteScriptExpression <string> ("p0.PropertyAmbigous", proxy), Is.EqualTo("ProxiedChildChild::PropertyAmbigous PC"));

            var proxyPropertyInfo = proxyType.GetProperty(
                "Remotion.Scripting.UnitTests.TestDomain.ProxiedChild.Remotion.Scripting.UnitTests.TestDomain.IPropertyAmbigous2.PropertyAmbigous", _nonPublicInstanceFlags);

            Assert.That(proxyPropertyInfo, Is.Not.Null);
            Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo(expectedPropertyValue));
            //AssertPropertyInfoEqual (proxyPropertyInfo, propertyInfo);

            ((IPropertyAmbigous2)proxied).PropertyAmbigous = "aBc";
            const string expectedPropertyValue2 = "ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous aBc-ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous";

            Assert.That(((IPropertyAmbigous2)proxied).PropertyAmbigous, Is.EqualTo(expectedPropertyValue2));
            Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo(expectedPropertyValue2));

            proxyPropertyInfo.SetValue(proxy, "XXyyZZ", null);
            const string expectedPropertyValue3 = "ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous XXyyZZ-ProxiedChildChild::IPropertyAmbigous2::PropertyAmbigous";

            Assert.That(((IPropertyAmbigous2)proxied).PropertyAmbigous, Is.EqualTo(expectedPropertyValue3));
            Assert.That(proxyPropertyInfo.GetValue(proxy, null), Is.EqualTo(expectedPropertyValue3));

            var proxyPropertyInfo2 = proxyType.GetProperty(
                "Remotion.Scripting.UnitTests.TestDomain.ProxiedChild.Remotion.Scripting.UnitTests.TestDomain.IPropertyAmbigous1.PropertyAmbigous", _nonPublicInstanceFlags);

            Assert.That(proxyPropertyInfo2, Is.Null);
        }
 private void SessionSendSuccess(string followUpUrl)
 {
     Execute.OnUIThread(() =>
     {
         browser.LoadCompleted += (s, e) => uiMode = UIMode.form;
         browser.Navigate(followUpUrl);
         ScriptingHelper helper = new ScriptingHelper();
         //browser.ContextMenu = false;
         browser.ObjectForScripting = helper;
         helper.OnCanceled         += Helper_OnCanceled;
         helper.OnCompleted        += Helper_OnCompleted;
     });
 }
Example #21
0
        public void Compare_NewMethods()
        {
            var          comparer                     = MethodInfoFromRelatedTypesEqualityComparer.Get;
            const string methodName                   = "PrependName";
            var          proxiedMethod                = ScriptingHelper.GetAnyPublicInstanceMethodArray(typeof(Proxied), methodName).Last();
            var          proxiedChildMethod           = ScriptingHelper.GetAnyPublicInstanceMethodArray(typeof(ProxiedChild), methodName).Last();
            var          proxiedChildChildChildMethod = ScriptingHelper.GetAnyPublicInstanceMethodArray(typeof(ProxiedChildChildChild), methodName).Last();

            Assert.That(comparer.Equals(proxiedMethod, proxiedMethod), Is.True);
            Assert.That(comparer.Equals(proxiedMethod, proxiedChildMethod), Is.True);
            Assert.That(comparer.Equals(proxiedChildMethod, proxiedMethod), Is.True);
            Assert.That(comparer.Equals(proxiedChildMethod, proxiedChildMethod), Is.True);
            Assert.That(comparer.Equals(proxiedChildChildChildMethod, proxiedChildChildChildMethod), Is.True);
            Assert.That(comparer.Equals(proxiedChildMethod, proxiedChildChildChildMethod), Is.True);
        }
Example #22
0
        public void GetTypeMemberProxy()
        {
            var provider = new StableBindingProxyProvider(
                new TypeLevelTypeFilter(new[] { typeof(ProxiedChild) }), CreateModuleScope("GetTypeMemberProxy"));

            var          proxied       = new ProxiedChildChildChild("abrakadava");
            const string attributeName = "PrependName";

            var typeMemberProxy = provider.GetAttributeProxy(proxied, attributeName);

            var customMemberTester = new GetCustomMemberTester(typeMemberProxy);

            var result = ScriptingHelper.ExecuteScriptExpression <string> ("p0.XYZ('simsalbum',2)", customMemberTester);

            Assert.That(result, Is.EqualTo("ProxiedChild ProxiedChild: abrakadava simsalbum, THE NUMBER=2"));
        }
Example #23
0
        public void IProxy()
        {
            var  proxyBuilder = new ForwardingProxyBuilder("IProxy", ModuleScope, typeof(Proxied), new Type[0]);
            Type proxyType    = proxyBuilder.BuildProxyType();

            var    proxied = new Proxied("AAA");
            object proxy   = Activator.CreateInstance(proxyType, proxied);

            Assert.That(ScriptingHelper.GetProxiedFieldValue(proxy), Is.SameAs(proxied));

            var proxied2 = new Proxied("BBB");

            ((IProxy)proxy).SetProxied(proxied2);

            Assert.That(ScriptingHelper.GetProxiedFieldValue(proxy), Is.SameAs(proxied2));
        }
        public void Equals_MethodFromBaseTypeHiddenByInterfaceMethod()
        {
            var methodFromBaseType = ScriptingHelper.GetInstanceMethod(typeof(Proxied), "PrependName", new[] { typeof(string) });
            var method             = ScriptingHelper.GetInstanceMethod(typeof(ProxiedChildChild), "PrependName", new[] { typeof(string) });

            Assert.That(methodFromBaseType, Is.Not.EqualTo(method));
            Assert.That(methodFromBaseType.GetBaseDefinition(), Is.Not.EqualTo(method.GetBaseDefinition()));

            // Default comparison taking all method attributes into account fails, since IPrependName adds the Final, Virtual and
            // VtableLayoutMask attributes.
            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, method), Is.False);

            // Comparing ignoring method attributes coming from IPrependName works.
            var comparerNoVirtualNoFinal = new MethodInfoEqualityComparer(~(MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.VtableLayoutMask));

            Assert.That(comparerNoVirtualNoFinal.Equals(methodFromBaseType, method), Is.True);
        }
Example #25
0
        public void BuildProxy()
        {
            var provider = new StableBindingProxyProvider(
                new TypeLevelTypeFilter(new[] { typeof(ProxiedChild) }), CreateModuleScope("BuildProxy"));

            var proxied = new ProxiedChildChildChild("abrakadava");

            var proxy = provider.BuildProxy(proxied);

            // Necessary since a newly built proxy has an empty proxied field
            // TODO: Introduce BuildProxyFromType(proxiedType)
            ScriptingHelper.SetProxiedFieldValue(proxy, proxied);

            Assert.That(proxy, Is.Not.Null);

            var result = ScriptingHelper.ExecuteScriptExpression <string> ("p0.PrependName('simsalbum',2)", proxy);

            Assert.That(result, Is.EqualTo("ProxiedChild ProxiedChild: abrakadava simsalbum, THE NUMBER=2"));
        }
Example #26
0
        public void GetProxy_IsCachedAndProxiedIsSet()
        {
            var provider = new StableBindingProxyProvider(
                new TypeLevelTypeFilter(new[] { typeof(GetProxyTypeIsCachedTest) }), CreateModuleScope("GetProxy_IsCachedAndProxiedSet"));

            var proxied0 = new GetProxyTypeIsCachedTest("abrakadava");
            var proxied1 = new GetProxyTypeIsCachedTest("simsalsabum");

            var proxy0 = provider.GetProxy(proxied0);

            Assert.That(proxy0, Is.Not.Null);

            var proxiedFieldValue0 = ScriptingHelper.GetProxiedFieldValue(proxy0);

            Assert.That(proxiedFieldValue0, Is.SameAs(proxied0));
            var proxy1 = provider.GetProxy(proxied1);

            Assert.That(proxy0, Is.SameAs(proxy1));
            Assert.That(ScriptingHelper.GetProxiedFieldValue(proxy1), Is.SameAs(proxied1));
        }
Example #27
0
    private void SendCurrentObjectToTextDiff(bool isSource)
    {
      if (_bs.Current == null)
      {
        return;
      }

      DataRowView rw = _bs.Current as DataRowView;
      if (rw == null)
        return;

      int objId = (int)rw.Row.ItemArray[0];
      string objType = (string)rw.Row.ItemArray[3];
      string objName = (string)rw.Row.ItemArray[2];
      
      if (DBConstants.DoesObjectTypeHasScript(objType))
      {
        int type = DBConstants.GetDBObjectType(objType);
        string script = ScriptingHelper.GetAlterScript(_connParams, _connParams.Database, objId, type);

        frmTextDiff diffForm = frmTextDiff.ActiveTextDiff;
        if (diffForm == null)
        {
          diffForm = TextDiffFactory.CreateDiff();
        }

        if (isSource)
        {
          diffForm.diffControl.SourceText = script;
          diffForm.diffControl.SourceHeaderText = objName;
        }
        else
        {
          diffForm.diffControl.DestText = script;
          diffForm.diffControl.DestHeaderText = objName;
        }
        diffForm.Show();
        diffForm.BringToFront();
      }
    }
Example #28
0
        public void ModifySelectedObjects( )
        {
            string error = String.Empty;

            IList <frmScriptEditor> editors = new List <frmScriptEditor>();

            foreach (TreeNode node in tv.SelectedNodes)
            {
                ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node);
                if (data == null)
                {
                    continue;
                }

                ObjectInfo objInfo = ProgrammabilityHelper.GetObjectInfo(_connParams, String.Empty, data.Name);
                if (objInfo == null)
                {
                    error += " - " + data.Name + "\r\n";
                    continue;
                }

                if (!DBConstants.DoesObjectTypeHasScript(data.Type ?? -1))
                {
                    continue;
                }
                string          script = ScriptingHelper.GetAlterScript(_connParams, _connParams.Database, objInfo.ObjectID, objInfo.ObjectType);
                frmScriptEditor editor = ScriptEditorFactory.Create(objInfo.ObjectName, script, objInfo.ObjectID, objInfo.ObjectType, _connParams, cmbDatabases.Text);
                editors.Add(editor);
            }

            foreach (frmScriptEditor editor in editors)
            {
                ScriptEditorFactory.ShowScriptEditor(editor);
            }

            if (!String.IsNullOrEmpty(error))
            {
                MessageService.ShowError("Objects listed below do not exist in the database!\r\n" + error);
            }
        }
        public void Ctor_Mask()
        {
            var method      = ScriptingHelper.GetInstanceMethod(typeof(CtorTest), "Foo", new[] { typeof(string) });
            var childMethod = ScriptingHelper.GetInstanceMethod(typeof(CtorTestChild), "Foo", new[] { typeof(string) });

            Assert.That(method.Attributes, Is.EqualTo(MethodAttributes.PrivateScope | MethodAttributes.Public | MethodAttributes.HideBySig));
            const MethodAttributes childMethodAdditionalAttributes = MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.VtableLayoutMask;

            Assert.That(childMethod.Attributes, Is.EqualTo(method.Attributes | childMethodAdditionalAttributes));

            var comparerDefault = new MethodInfoEqualityComparer();

            Assert.That(comparerDefault.Equals(method, childMethod), Is.False);

            var comparerNoVirtualNoFinal = new MethodInfoEqualityComparer(~childMethodAdditionalAttributes);

            Assert.That(comparerNoVirtualNoFinal.Equals(method, childMethod), Is.True);

            var comparerMethodFromBaseTypeAttributes = new MethodInfoEqualityComparer(method.Attributes);

            Assert.That(comparerMethodFromBaseTypeAttributes.Equals(method, childMethod), Is.True);
        }
        public void Equals_GenericClass_GenericMethodFromBaseType2()
        {
            var methodFromBaseType = ScriptingHelper.GetAnyGenericInstanceMethod(typeof(ProxiedChildGeneric <int, string>), "ProxiedChildGenericToString", 2);
            var methods            = ScriptingHelper.GetAnyGenericInstanceMethodArray(typeof(ProxiedChildChildGeneric <int, string>), "ProxiedChildGenericToString", 2);

            Assert.That(methods.Length, Is.EqualTo(2));

            Console.WriteLine(methods[0].Name);
            Console.WriteLine(methods[1].Name);
            Console.WriteLine(methodFromBaseType.Name);

            Console.WriteLine(methods[0].ReturnType);
            Console.WriteLine(methods[1].ReturnType);
            Console.WriteLine(methodFromBaseType.ReturnType);

            Console.WriteLine(methods[0].Attributes);
            Console.WriteLine(methods[1].Attributes);
            Console.WriteLine(methodFromBaseType.Attributes);

            Console.WriteLine("{" + string.Join(",", methods[0].GetParameters().Select(pi => pi.Attributes)) + "}");
            Console.WriteLine("{" + string.Join(",", methods[1].GetParameters().Select(pi => pi.Attributes)) + "}");
            Console.WriteLine("{" + string.Join(",", methodFromBaseType.GetParameters().Select(pi => pi.Attributes)) + "}");

            Console.WriteLine("{" + string.Join(",", methods[0].GetParameters().Select(pi => pi.ParameterType)) + "}");
            Console.WriteLine("{" + string.Join(",", methods[1].GetParameters().Select(pi => pi.ParameterType)) + "}");
            Console.WriteLine("{" + string.Join(",", methodFromBaseType.GetParameters().Select(pi => pi.ParameterType)) + "}");

            var a0 = methods[0].GetParameters()[2];
            var a1 = methods[1].GetParameters()[2];
            var ax = methodFromBaseType.GetParameters()[2];

            var x = methods[0].GetParameters()[2];

            Assert.That(methodFromBaseType, Is.Not.EqualTo(methods[0]));
            Assert.That(methodFromBaseType, Is.Not.EqualTo(methods[1]));
            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, methods[1]), Is.True);
            Assert.That(MethodInfoEqualityComparer.Get.Equals(methodFromBaseType, methods[0]), Is.True);
        }