예제 #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))));
                }
            });
        }
예제 #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))));
            });
        }
예제 #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))));
                }
            });
        }
예제 #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))));
                }
            });
        }
예제 #5
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))));
                    }
                }
            });
        }
예제 #6
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))));
                    }
                }
            });
        }