Пример #1
0
        public void Can_access_ModelWithComplexTypes()
        {
            var idAccessor = TypeProperties <ModelWithComplexTypes> .GetAccessor("Id");

            var stringListAccessor = TypeProperties <ModelWithComplexTypes> .GetAccessor("StringList");

            var intListAccessor = TypeProperties <ModelWithComplexTypes> .GetAccessor("IntList");

            var stringMapAccessor = TypeProperties <ModelWithComplexTypes> .GetAccessor("StringMap");

            var intMapAccessor = TypeProperties <ModelWithComplexTypes> .GetAccessor("IntMap");

            var childAccessor = TypeProperties <ModelWithComplexTypes> .GetAccessor("Child");

            var original = ModelWithComplexTypesFactory.Instance.CreateInstance(1);

            Assert.That(idAccessor.PublicGetter(original), Is.EqualTo(original.Id));
            Assert.That(stringListAccessor.PublicGetter(original), Is.EqualTo(original.StringList));
            Assert.That(intListAccessor.PublicGetter(original), Is.EqualTo(original.IntList));
            Assert.That(stringMapAccessor.PublicGetter(original), Is.EqualTo(original.StringMap));
            Assert.That(intMapAccessor.PublicGetter(original), Is.EqualTo(original.IntMap));
            Assert.That(childAccessor.PublicGetter(original), Is.EqualTo(original.Child));

            var to = ModelWithComplexTypesFactory.Instance.CreateInstance(2);

            idAccessor.PublicSetter(original, to.Id);
            stringListAccessor.PublicSetter(original, to.StringList);
            intListAccessor.PublicSetter(original, to.IntList);
            stringMapAccessor.PublicSetter(original, to.StringMap);
            intMapAccessor.PublicSetter(original, to.IntMap);
            childAccessor.PublicSetter(original, to.Child);

            ModelWithComplexTypesFactory.Instance.AssertIsEqual(original, to);
        }
Пример #2
0
        public void Can_access_ModelWithFieldsOfDifferentTypes()
        {
            var idAccessor = TypeProperties <ModelWithFieldsOfDifferentTypes> .GetAccessor("Id");

            var nameAccessor = TypeProperties <ModelWithFieldsOfDifferentTypes> .GetAccessor("Name");

            var longIdAccessor = TypeProperties <ModelWithFieldsOfDifferentTypes> .GetAccessor("LongId");

            var guidAccessor = TypeProperties <ModelWithFieldsOfDifferentTypes> .GetAccessor("Guid");

            var boolAccessor = TypeProperties <ModelWithFieldsOfDifferentTypes> .GetAccessor("Bool");

            var dateTimeAccessor = TypeProperties <ModelWithFieldsOfDifferentTypes> .GetAccessor("DateTime");

            var original = ModelWithFieldsOfDifferentTypesFactory.Instance.CreateInstance(1);

            Assert.That(idAccessor.PublicGetter(original), Is.EqualTo(original.Id));
            Assert.That(nameAccessor.PublicGetter(original), Is.EqualTo(original.Name));
            Assert.That(longIdAccessor.PublicGetter(original), Is.EqualTo(original.LongId));
            Assert.That(guidAccessor.PublicGetter(original), Is.EqualTo(original.Guid));
            Assert.That(boolAccessor.PublicGetter(original), Is.EqualTo(original.Bool));
            Assert.That(dateTimeAccessor.PublicGetter(original), Is.EqualTo(original.DateTime));

            var to = ModelWithFieldsOfDifferentTypesFactory.Instance.CreateInstance(2);

            idAccessor.PublicSetter(original, to.Id);
            nameAccessor.PublicSetter(original, to.Name);
            longIdAccessor.PublicSetter(original, to.LongId);
            guidAccessor.PublicSetter(original, to.Guid);
            boolAccessor.PublicSetter(original, to.Bool);
            dateTimeAccessor.PublicSetter(original, to.DateTime);

            ModelWithFieldsOfDifferentTypesFactory.Instance.AssertIsEqual(original, to);
        }
Пример #3
0
        void UpdateSessionKey(IAuthSession session, IUserAuth userAuth)
        {
            var keyProp = UserAuthProps.GetAccessor(UserAuthIdentifier);

            if (keyProp != null)
            {
                session.UserAuthId = (string)keyProp.PublicGetter(userAuth);
            }
        }
Пример #4
0
        public static void Init()
        {
            // Use reflection to avoid tfm builds and binary dependency on .NET Framework v4.7.2+
            sameSiteFn = TypeProperties <HttpCookie> .GetAccessor("SameSite")?.PublicSetter;

            if (sameSiteFn != null)
            {
                var sameSiteMode = typeof(HttpCookie).Assembly.GetType("System.Web.SameSiteMode");
                if (sameSiteMode != null)
                {
                    sameSiteNone   = (Enum)Enum.Parse(sameSiteMode, "None");
                    sameSiteStrict = (Enum)Enum.Parse(sameSiteMode, "Strict");
                }
            }
        }
Пример #5
0
        public void Can_access_ModelWithFieldsOfDifferentAndNullableTypes()
        {
            var idAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("Id");

            var idNAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NId");

            var longIdAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NLongId");

            var guidAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NGuid");

            var boolAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NBool");

            var dateTimeAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NDateTime");

            var floatAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NFloat");

            var doubleAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NDouble");

            var decimalAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NDecimal");

            var timespanAccessor = TypeProperties <ModelWithFieldsOfNullableTypes> .GetAccessor("NTimeSpan");

            var original = ModelWithFieldsOfNullableTypesFactory.Instance.CreateInstance(1);

            Assert.That(idAccessor.PublicGetter(original), Is.EqualTo(original.Id));
            Assert.That(idNAccessor.PublicGetter(original), Is.EqualTo(original.NId));
            Assert.That(longIdAccessor.PublicGetter(original), Is.EqualTo(original.NLongId));
            Assert.That(guidAccessor.PublicGetter(original), Is.EqualTo(original.NGuid));
            Assert.That(boolAccessor.PublicGetter(original), Is.EqualTo(original.NBool));
            Assert.That(dateTimeAccessor.PublicGetter(original), Is.EqualTo(original.NDateTime));
            Assert.That(floatAccessor.PublicGetter(original), Is.EqualTo(original.NFloat));
            Assert.That(doubleAccessor.PublicGetter(original), Is.EqualTo(original.NDouble));
            Assert.That(decimalAccessor.PublicGetter(original), Is.EqualTo(original.NDecimal));
            Assert.That(timespanAccessor.PublicGetter(original), Is.EqualTo(original.NTimeSpan));

            var to = ModelWithFieldsOfNullableTypesFactory.Instance.CreateInstance(2);

            idAccessor.PublicSetter(original, to.Id);
            idNAccessor.PublicSetter(original, to.NId);
            longIdAccessor.PublicSetter(original, to.NLongId);
            guidAccessor.PublicSetter(original, to.NGuid);
            boolAccessor.PublicSetter(original, to.NBool);
            dateTimeAccessor.PublicSetter(original, to.NDateTime);
            floatAccessor.PublicSetter(original, to.NFloat);
            doubleAccessor.PublicSetter(original, to.NDouble);
            decimalAccessor.PublicSetter(original, to.NDecimal);
            timespanAccessor.PublicSetter(original, to.NTimeSpan);

            ModelWithFieldsOfNullableTypesFactory.Instance.AssertIsEqual(original, to);

            //Can handle nulls
            original = new ModelWithFieldsOfNullableTypes();

            Assert.That(idAccessor.PublicGetter(original), Is.EqualTo(original.Id));
            Assert.That(idNAccessor.PublicGetter(original), Is.EqualTo(original.NId));
            Assert.That(longIdAccessor.PublicGetter(original), Is.EqualTo(original.NLongId));
            Assert.That(guidAccessor.PublicGetter(original), Is.EqualTo(original.NGuid));
            Assert.That(boolAccessor.PublicGetter(original), Is.EqualTo(original.NBool));
            Assert.That(dateTimeAccessor.PublicGetter(original), Is.EqualTo(original.NDateTime));
            Assert.That(floatAccessor.PublicGetter(original), Is.EqualTo(original.NFloat));
            Assert.That(doubleAccessor.PublicGetter(original), Is.EqualTo(original.NDouble));
            Assert.That(decimalAccessor.PublicGetter(original), Is.EqualTo(original.NDecimal));
            Assert.That(timespanAccessor.PublicGetter(original), Is.EqualTo(original.NTimeSpan));
        }