Пример #1
0
        public void TestAttributeCopy()
        {
            var res = ProxyGenerator.GetInterfaceProxyType <IUser>();

            Assert.Equal(2, res.GetProperty(nameof(IUser.Id)).GetCustomAttributes(true).Count());
            Assert.Equal(3, res.GetProperty(nameof(IUser.Name)).GetCustomAttributes(true).Count());
            var haveDummyAttribute = false;

            foreach (var a in res.GetProperty(nameof(IUser.Name)).GetCustomAttributes(true))
            {
                if (a is NoConstructorAttribute)
                {
                    haveDummyAttribute = true;
                }
                else if (a is SimpleConstructorAttribute d2a)
                {
                    Assert.Equal("abc", d2a.Value);
                }
                else if (a is ComplexAttrAttribute mca)
                {
                    Assert.Equal("stringName", mca.StringValue);
                    Assert.Equal("propName", mca.PropertyValue);
                    Assert.Equal("fieldName", mca.FieldValue);
                    Assert.Null(mca.IntValue);
                    Assert.Equal(4.2, mca.DoubleValue);
                }
            }
            Assert.True(haveDummyAttribute);

            haveDummyAttribute = false;
            foreach (var a in res.GetProperty(nameof(IUser.Id)).GetCustomAttributes(true))
            {
                if (a is NoConstructorAttribute)
                {
                    haveDummyAttribute = true;
                }
                if (a is ComplexAttrAttribute mca)
                {
                    Assert.Equal(123, mca.IntValue);
                    Assert.Equal("propId", mca.PropertyValue);
                    Assert.Equal("fieldId", mca.FieldValue);
                    Assert.Equal(4.2, mca.DoubleValue);
                    Assert.Null(mca.StringValue);
                }
            }
            Assert.True(haveDummyAttribute);
        }