示例#1
0
        public void TestBuiltIntTypes()
        {
            var typeModel     = ProtobufTypeModel.Create(_connection, new Type[0]);
            var expectedTypes = new[]
            {
                typeof(string),
                typeof(float),
                typeof(double),
                typeof(byte),
                typeof(sbyte),
                typeof(short),
                typeof(ushort),
                typeof(int),
                typeof(uint),
                typeof(long),
                typeof(object),
                typeof(IPAddress),
                typeof(byte[])
            };

            foreach (var type in expectedTypes)
            {
                typeModel.IsRegistered(type).Should().BeTrue("because we expect the type model to intrinsically know this type");
                typeModel.GetTypeId(type).Should().BeGreaterThan(0, "because we expect the type model to intrinsically know this type");
            }
        }
示例#2
0
        public void TestRegisterCustomType()
        {
            var typeModel = ProtobufTypeModel.Create(_connection, new[] { typeof(IPolymorphicCustomKey) });

            typeModel.IsRegistered(typeof(IPolymorphicCustomKey)).Should().BeTrue();
            var id = typeModel.GetTypeId(typeof(IPolymorphicCustomKey));

            typeModel.GetType(id).Should().Be <IPolymorphicCustomKey>();
        }
示例#3
0
        public void TestRegisterUnsupportedSetup()
        {
            TypeModel.Read(_connection, new TypeResolver(new Type[0])).Types.Should().BeEmpty();

            new Action(() => ProtobufTypeModel.Create(_connection, new[] { typeof(Thread) }))
            .Should().Throw <ArgumentException>("because the Thread type simply cannot be serialized");

            TypeModel.Read(_connection, new TypeResolver(new Type[0])).Types.Should().BeEmpty();
        }
示例#4
0
        public void TestUnavailableType()
        {
            var typeModel        = ProtobufTypeModel.Create(_connection, new[] { typeof(CustomKey), typeof(IPolymorphicCustomKey) });
            var customKeyId      = typeModel.GetTypeId(typeof(CustomKey));
            var polymorphicKeyId = typeModel.GetTypeId(typeof(IPolymorphicCustomKey));

            typeModel = ProtobufTypeModel.Create(_connection, new[] { typeof(IPolymorphicCustomKey) });
            typeModel.GetType(customKeyId).Should().BeNull("because the type couldn't be resolved anymore");
            typeModel.GetType(polymorphicKeyId).Should().Be <IPolymorphicCustomKey>(
                "because types which can be resolved should still be presented");
        }
示例#5
0
        public void TestRegisterSurrogateType()
        {
            var typeModel = ProtobufTypeModel.Create(_connection, new[] { typeof(IPAddressSurrogate) });

            typeModel.IsRegistered(typeof(IPAddressSurrogate)).Should().BeTrue();
            typeModel.IsRegistered(typeof(IPAddress)).Should().BeTrue();

            var id = typeModel.GetTypeId(typeof(IPAddressSurrogate));

            typeModel.GetType(id).Should().Be <IPAddressSurrogate>();
        }
示例#6
0
        public CollectionsTable(SQLiteConnection connection,
                                IReadOnlyList <Type> supportedTypes,
                                bool isReadOnly)
        {
            _connection = connection;
            _isReadOnly = isReadOnly;

            _typeModel         = ProtobufTypeModel.Create(connection, supportedTypes, isReadOnly);
            _serializer        = new Serializer(_typeModel);
            _collections       = new System.Collections.Generic.HashSet <IInternalCollection>();
            _collectionsByName = new System.Collections.Generic.Dictionary <string, IInternalCollection>();

            CreateCollections();
        }