Пример #1
0
        public void InvalidSaveAttribute()
        {
            Setup();

            Assert.ThrowsException <InvalidAttributeToVerException>(() =>
                                                                    IntermediateMapper.CreateIntermediateObjectInfo(typeof(InvalidSaveAttributeClass), SaveMembersMode.Properties, out var members));
        }
Пример #2
0
        public void Properties_Unordered()
        {
            Setup();

            uint highestVersion =
                IntermediateMapper.CreateIntermediateObjectInfo(typeof(UnorderedClass), SaveMembersMode.Properties, out var members);

            Assert.AreEqual(0u, highestVersion);

            for (int i = 0; i < members.Members.Length; i++)
            {
                Assert.IsFalse(members.Members[i].IsProcessed);
                Assert.IsInstanceOfType(members.Members[i].Details.Unprocessed, typeof(PropertyInfo));

                Type expectedType = i switch
                {
                    0 => typeof(bool),
                    1 => typeof(string),
                    _ => throw new Exception("Invalid key")
                };

                Assert.AreEqual(expectedType, ((PropertyInfo)members.Members[i].Details.Unprocessed).PropertyType);
                i++;
            }
        }
Пример #3
0
        public void FillMainInfo_CorrectValues()
        {
            IntermediateItem info = new IntermediateItem();

            IntermediateMapper.FillMainInfo(info, 3, 6, uint.MaxValue);

            Assert.AreEqual(3, info.Order);
            Assert.AreEqual(6u, info.StartVer);
            Assert.AreEqual(uint.MaxValue, info.EndVer);
        }
Пример #4
0
        public void FillMainInfo_CorrectHighestVersion_CustomHighs()
        {
            var ctx = new IntermediateMappingContext();

            IntermediateItem info = new IntermediateItem();

            IntermediateMapper.FillMainInfo(info, 3, 6, 7);
            IntermediateMapper.UpdateContextFromItem(ref ctx, info);

            IntermediateMapper.FillMainInfo(info, 5, 8, 34);
            IntermediateMapper.UpdateContextFromItem(ref ctx, info);

            IntermediateMapper.FillMainInfo(info, 9, 11, 59);
            IntermediateMapper.UpdateContextFromItem(ref ctx, info);

            Assert.AreEqual(9, ctx.TranslationCurrentOrderInfo);
            Assert.AreEqual(59u, ctx.HighestVersion);
        }
Пример #5
0
        public void FillMainInfo_CorrectOrderInfo_Ordered()
        {
            Setup();

            var ctx = new IntermediateMappingContext();

            IntermediateItem info = new IntermediateItem();

            IntermediateMapper.FillMainInfo(info, 3, 0, uint.MaxValue);
            IntermediateMapper.UpdateContextFromItem(ref ctx, info);

            IntermediateMapper.FillMainInfo(info, 5, 0, uint.MaxValue);
            IntermediateMapper.UpdateContextFromItem(ref ctx, info);

            IntermediateMapper.FillMainInfo(info, 9, 0, uint.MaxValue);
            IntermediateMapper.UpdateContextFromItem(ref ctx, info);

            Assert.AreEqual(9, ctx.TranslationCurrentOrderInfo);
        }
        static bool FillItemFromAttributes(IntermediateItem dest, MemberInfo info, object[] attributes)
        {
            dest.Details.Unprocessed = info;

            bool loadedSaveAttribute = false;

            for (int i = 0; i < attributes.Length; i++)
            {
                // TODO: Add more attributes
                switch (attributes[i])
                {
                case SaveAttribute save:
                    IntermediateMapper.FillMainInfo(dest, save.Order, save.FromVer, save.ToVer);
                    loadedSaveAttribute = true;
                    break;
                }
            }

            return(loadedSaveAttribute);
        }
        internal static IntermediateItem?GetItemForMember(ref IntermediateMappingContext ctx, MemberInfo info)
        {
            // Get the attributes - skip this item if there are none
            object[]? attributes = info.GetCustomAttributes(typeof(SaveAttribute), false);
            if (attributes.Length == 0)
            {
                return(null);
            }

            var newItem = new IntermediateItem();

            // Create the item.
            bool successful = FillItemFromAttributes(newItem, info, attributes);

            if (!successful)
            {
                throw new IncompleteDetailsException(info);
            }

            IntermediateMapper.UpdateContextFromItem(ref ctx, newItem);
            return(newItem);
        }
Пример #8
0
        void TestFields(bool isValueTypeParent)
        {
            var highestVersion = IntermediateMapper.CreateIntermediateObjectInfo(
                isValueTypeParent ? typeof(FieldStruct) : typeof(FieldClass), SaveMembersMode.Fields, out var members);

            Assert.AreEqual(0u, highestVersion);
            Assert.AreEqual(2, members.Members.Length);

            for (int i = 0; i < members.Members.Length; i++)
            {
                Assert.IsFalse(members.Members[i].IsProcessed);
                Assert.IsInstanceOfType(members.Members[i].Details.Unprocessed, typeof(FieldInfo));

                Type expectedType = i switch
                {
                    0 => typeof(string),
                    1 => typeof(bool),
                    _ => throw new Exception("Incorrect key")
                };

                Assert.AreEqual(expectedType, ((FieldInfo)members.Members[i].Details.Unprocessed).FieldType);
            }
        }
Пример #9
0
        void TestProperties(bool isValueTypeParent)
        {
            var highestVersion = IntermediateMapper.CreateIntermediateObjectInfo(
                isValueTypeParent ? typeof(AllPrimitiveStruct) : typeof(AllPrimitiveClass), SaveMembersMode.Properties, out var members);

            Assert.AreEqual(0u, highestVersion);
            Assert.AreEqual(3, members.Members.Length);

            for (int i = 0; i < members.Members.Length; i++)
            {
                Assert.IsFalse(members.Members[i].IsProcessed);
                Assert.IsInstanceOfType(members.Members[i].Details.Unprocessed, typeof(PropertyInfo));

                Type expectedType = i switch
                {
                    0 => typeof(bool),
                    1 => typeof(int),
                    2 => typeof(string),
                    _ => throw new Exception("Invalid key")
                };

                Assert.AreEqual(expectedType, ((PropertyInfo)members.Members[i].Details.Unprocessed) !.PropertyType);
            }
        }
Пример #10
0
 public override uint Initialize(InitializeInfo info)
 {
     return(IntermediateMapper.CreateIntermediateObjectInfo(info.Type, _saveMode, out _intermediateInfo));
 }