Exemple #1
0
        public void UnwrappedView_ShouldUnwrapSimpleViews()
        {
            Type unwrapped = UnwrappedView <View2> .Type;

            typeof(View2)
            .GetProperties()
            .ForEach(prop =>
            {
                ColumnSelectionAttribute originalAttr = prop.GetCustomAttribute <ColumnSelectionAttribute>();
                PropertyInfo queried = unwrapped.GetProperty(prop.Name);

                if (originalAttr == null)
                {
                    Assert.That(queried, Is.Null);
                }
                else
                {
                    Assert.That(queried, Is.Not.Null);
                    Assert.That(queried.PropertyType, Is.EqualTo(prop.PropertyType));

                    ColumnSelectionAttribute queriedAttr = queried.GetCustomAttribute <ColumnSelectionAttribute>();

                    Assert.That(originalAttr.GetType(), Is.EqualTo(queriedAttr.GetType()));
                    originalAttr
                    .GetType()
                    .GetProperties()
                    .ForEach(p => Assert.That(p.FastGetValue(originalAttr), Is.EqualTo(p.FastGetValue(queriedAttr))));
                }
            });
        }
Exemple #2
0
        public void UnwrappedView_ShouldBeRecursive()
        {
            Type unwrapped = UnwrappedView <WrappedView4_Complex> .Type;

            typeof(WrappedView4_Complex)
            .GetProperties()
            .Where(prop => prop.GetCustomAttribute <WrappedAttribute>() == null)
            .Concat(typeof(WrappedView1).GetProperties().Where(prop => prop.GetCustomAttribute <WrappedAttribute>() == null))
            .Concat(typeof(View3).GetProperties())
            .ForEach(prop =>
            {
                ColumnSelectionAttribute originalAttr = prop.GetCustomAttribute <ColumnSelectionAttribute>();
                PropertyInfo queried = unwrapped.GetProperty(prop.Name);

                Assert.That(queried, Is.Not.Null);
                Assert.That(queried.PropertyType, Is.EqualTo(prop.PropertyType));

                ColumnSelectionAttribute queriedAttr = queried.GetCustomAttribute <ColumnSelectionAttribute>();

                Assert.That(originalAttr.GetType(), Is.EqualTo(queriedAttr.GetType()));
                originalAttr
                .GetType()
                .GetProperties()
                .ForEach(p => Assert.That(p.FastGetValue(originalAttr), Is.EqualTo(p.FastGetValue(queriedAttr))));
            });
        }
Exemple #3
0
        public void UnwrappedView_ShouldUnwrapMoreComplexViewHavingMultipleWrappedProperties()
        {
            Type unwrapped = UnwrappedView <WrappedView2> .Type;

            typeof(WrappedView2)
            .GetProperties()
            .Where(prop => prop.GetCustomAttribute <WrappedAttribute>() == null)
            .Concat(typeof(WrappedView2).GetProperty(nameof(WrappedView2.ViewList)).PropertyType.GetGenericArguments().Single().GetProperties())
            .Concat(typeof(WrappedView2).GetProperty(nameof(WrappedView2.ViewList2)).PropertyType.GetGenericArguments().Single().GetProperties())
            .ForEach(prop =>
            {
                ColumnSelectionAttribute originalAttr = prop.GetCustomAttribute <ColumnSelectionAttribute>();
                PropertyInfo queried = unwrapped.GetProperty(prop.Name);

                if (originalAttr == null)
                {
                    Assert.That(queried, Is.Null);
                }
                else
                {
                    Assert.That(queried, Is.Not.Null);
                    Assert.That(queried.PropertyType, Is.EqualTo(prop.PropertyType));

                    ColumnSelectionAttribute queriedAttr = queried.GetCustomAttribute <ColumnSelectionAttribute>();

                    Assert.That(originalAttr.GetType(), Is.EqualTo(queriedAttr.GetType()));
                    originalAttr
                    .GetType()
                    .GetProperties()
                    .ForEach(p => Assert.That(p.FastGetValue(originalAttr), Is.EqualTo(p.FastGetValue(queriedAttr))));
                }
            });
        }
Exemple #4
0
        public void UnwrappedView_ShouldUnwrapComplexViews(Type view, string wrappedProp)
        {
            Type unwrapped = (Type)typeof(UnwrappedView <>)
                             .MakeGenericType(view)
                             .GetProperty(nameof(UnwrappedView <object> .Type), BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
                             .GetValue(null);

            view
            .GetColumnSelectionsDeep()
            .ForEach(sel =>
            {
                ColumnSelectionAttribute originalAttr = sel.Reason;
                PropertyInfo queried = unwrapped.GetProperty(sel.ViewProperty.Name);

                if (originalAttr == null)
                {
                    Assert.That(queried, Is.Null);
                }
                else
                {
                    Assert.That(queried, Is.Not.Null);
                    Assert.That(queried.PropertyType, Is.EqualTo(sel.ViewProperty.PropertyType));

                    ColumnSelectionAttribute queriedAttr = queried.GetCustomAttribute <ColumnSelectionAttribute>();

                    Assert.That(originalAttr.GetType(), Is.EqualTo(queriedAttr.GetType()));
                    originalAttr
                    .GetType()
                    .GetProperties()
                    .ForEach(p => Assert.That(p.FastGetValue(originalAttr), Is.EqualTo(p.FastGetValue(queriedAttr))));
                }
            });
        }
Exemple #5
0
        public ColumnSelection(PropertyInfo viewProperty, SelectionKind kind, ColumnSelectionAttribute reason)
        {
            if (!viewProperty.PropertyType.IsValueTypeOrString())
            {
                throw new NotSupportedException(Resources.CANT_SELECT);
            }

            ViewProperty = viewProperty;
            Kind         = kind;
            Reason       = reason;
        }
Exemple #6
0
        public static ColumnSelection?AsColumnSelection(this PropertyInfo prop, bool baseRequired)
        {
            Debug.Assert(!prop.IsWrapped());

            ColumnSelectionAttribute csa = prop.GetCustomAttribute <ColumnSelectionAttribute>();

            if (csa is not null)
            {
                return(new ColumnSelection
                       (
                           viewProperty: prop,
                           kind: SelectionKind.Explicit,
                           reason: csa
                       ));
            }

            //
            // - Ha a nezet egy mar meglevo adattabla leszarmazottja akkor azon property-ket
            //   is kivalasztjuk melyek az os entitashoz tartoznak.
            //
            // - Az h ignoralva van e a property csak adatbazis entitasnal kell vizsgaljuk (nezetnel
            //   ha nincs ColumnSelectionAttribute rajt akkor automatikusan ignoralt).
            //

            Type?databaseEntity = prop.ReflectedType.GetBaseDataTable();

            if (databaseEntity is not null && !Config.Instance.IsIgnored(prop) && prop.DeclaringType.IsAssignableFrom(databaseEntity))
            {
                return(new ColumnSelection
                       (
                           viewProperty: prop,
                           kind: SelectionKind.Implicit,
                           reason: new BelongsToAttribute(databaseEntity, baseRequired)
                       ));
            }

            //
            // Hat ez nem sikerult...
            //

            return(null);
        }
Exemple #7
0
        public void UnwrappedView_ShouldUnwrapViewsHavingWrappedPropertyWithTypeOfDataTableDescendant()
        {
            Type unwrapped = UnwrappedView <WrappedView3_Extesnion> .Type;

            typeof(Extension1)
            .GetProperties()
            .Concat(typeof(WrappedView3_Extesnion).GetProperty(nameof(WrappedView3_Extesnion.ViewList)).PropertyType.GetGenericArguments().Single().GetProperties())
            .ForEach(prop =>
            {
                PropertyInfo queried = unwrapped.GetProperty(prop.Name);
                if (prop.GetCustomAttribute <IgnoreAttribute>() != null)
                {
                    Assert.That(queried, Is.Null);
                }
                else
                {
                    Assert.That(queried, Is.Not.Null);
                    Assert.That(queried.PropertyType, Is.EqualTo(prop.PropertyType));

                    ColumnSelectionAttribute
                    originalAttr = prop.GetCustomAttribute <ColumnSelectionAttribute>(),
                    queriedAttr  = queried.GetCustomAttribute <ColumnSelectionAttribute>();

                    if (originalAttr == null)
                    {
                        Assert.That(queriedAttr.GetType(), Is.EqualTo(typeof(BelongsToAttribute)));
                        Assert.That(queriedAttr.OrmType, Is.EqualTo(typeof(Extension1).GetBaseDataTable()));
                    }
                    else
                    {
                        Assert.That(originalAttr.GetType(), Is.EqualTo(queriedAttr.GetType()));
                        originalAttr
                        .GetType()
                        .GetProperties()
                        .ForEach(p => Assert.That(p.FastGetValue(originalAttr), Is.EqualTo(p.FastGetValue(queriedAttr))));
                    }
                }
            });
        }
Exemple #8
0
        public void UnwrappedView_ShouldUnwrapSimpleViewsDescendingFromDataTable()
        {
            Type unwrapped = UnwrappedView <Extension1> .Type;

            typeof(Extension1)
            .GetProperties()
            .ForEach(prop =>
            {
                PropertyInfo queried = unwrapped.GetProperty(prop.Name);
                if (prop.GetCustomAttribute <IgnoreAttribute>() != null)
                {
                    Assert.That(queried, Is.Null);
                }
                else
                {
                    Assert.That(queried, Is.Not.Null);
                    Assert.That(queried.PropertyType, Is.EqualTo(prop.PropertyType));

                    ColumnSelectionAttribute
                    originalAttr = prop.GetCustomAttribute <ColumnSelectionAttribute>(),
                    queriedAttr  = queried.GetCustomAttribute <ColumnSelectionAttribute>();

                    if (originalAttr == null)
                    {
                        Assert.That(queriedAttr.GetType(), Is.EqualTo(typeof(BelongsToAttribute)));
                        Assert.That(queriedAttr.OrmType, Is.EqualTo(typeof(Extension1).GetBaseDataTable()));
                    }
                    else
                    {
                        Assert.That(originalAttr.GetType(), Is.EqualTo(queriedAttr.GetType()));
                        originalAttr
                        .GetType()
                        .GetProperties()
                        .ForEach(p => Assert.That(p.FastGetValue(originalAttr), Is.EqualTo(p.FastGetValue(queriedAttr))));
                    }
                }
            });
        }