public async Task CreateTableNoSchema()
        {
            using (var conn = CreateConnection())
            {
                // 如果实体的 Schema 没有配置表名,则使用类名
                await conn.ExecuteAsync("drop table if exists createtableentity1;");

                {
                    var storage  = CreateStorage(StorageMode.Insert);
                    var dfc      = new DataContext(null, null, null, null);
                    var typeName = typeof(CreateTableEntity1);
                    var entity   = new CreateTableEntity1();

                    var items = new List <CreateTableEntity1> {
                        entity
                    };
                    dfc.AddData(typeName, items);
                    await storage.HandleAsync(dfc);

                    var list = (await conn.QueryAsync <CreateTableEntity1>("SELECT * FROM createtableentity1")).ToList();
                    Assert.Single(list);
                    entity = list.First();
                    Assert.Equal("xxx", entity.Str1);
                    Assert.Equal("yyy", entity.Str2);
                    Assert.Equal(655, entity.Required);
                    Assert.Equal(0, entity.Decimal);
                    Assert.Equal(600, entity.Long);
                    Assert.Equal(400, entity.Double);
                    Assert.Equal(200.0F, entity.Float);
                    await conn.ExecuteAsync("drop table if exists createtableentity1;");
                }
            }
        }
        public async Task CreateTableWhenNoSchema()
        {
            using var conn = CreateConnection();
            // 如果实体的 Schema 没有配置表名,则使用类名
            await conn.ExecuteAsync($"drop table if exists createtableentity1;");

            var storage = CreateStorage(StorageMode.Insert);
            var context = new DataFlowContext(null, new SpiderOptions(),
                                              new Request(), new Response());
            var typeName = typeof(CreateTableEntity1);
            var entity   = new CreateTableEntity1();

            context.AddData(typeName, new List <CreateTableEntity1> {
                entity
            });
            await storage.HandleAsync(context);

            var list = (await conn.QueryAsync <CreateTableEntity1>($"SELECT * FROM createtableentity1")).ToList();

            Assert.Single(list);
            entity = list.First();
            Assert.Equal("xxx", entity.Str1);
            Assert.Equal("yyy", entity.Str2);
            Assert.Equal(655, entity.Required);
            Assert.Equal(0, entity.Decimal);
            Assert.Equal(600, entity.Long);
            Assert.Equal(400, entity.Double);
            Assert.Equal(200.0F, entity.Float);
            await conn.ExecuteAsync($"drop table if exists createtableentity1;");
        }
Exemplo n.º 3
0
        public async Task CreateTableNoSchema()
        {
            using (var conn = CreateConnection())
            {
                // 如果实体的 Schema 没有配置表名,则使用类名
                await conn.ExecuteAsync("drop table if exists createtableentity1;");

                var services = SpiderProvider.Value.CreateScopeServiceProvider();
                var storage  = CreateStorage(StorageType.Insert);
                var dfc      = new DataFlowContext(null, services);
                var typeName = typeof(CreateTableEntity1).FullName;
                var entity   = new CreateTableEntity1();
                dfc.Add(typeName, entity.GetTableMetadata());
                var items = new ParseResult <CreateTableEntity1>
                {
                    entity
                };
                dfc.AddParseItem(typeName, items);
                await storage.HandleAsync(dfc);

                var list = (await conn.QueryAsync <CreateTableEntity1>("SELECT * FROM createtableentity1")).ToList();
                Assert.Single(list);
                entity = list.First();
                Assert.Equal("xxx", entity.Str1);
                Assert.Equal("yyy", entity.Str2);
                Assert.Equal(655, entity.Required);
                Assert.Equal(0, entity.Decimal);
                Assert.Equal(600, entity.Long);
                Assert.Equal(400, entity.Double);
                Assert.Equal(200.0F, entity.Float);
                await conn.ExecuteAsync("drop table if exists createtableentity1;");
            }
        }
        public async Task Store_Should_Success()
        {
            var serviceProvider = Mock.Of <IServiceProvider>();

            var mongoCollection = new Mock <IMongoCollection <BsonDocument> >();

            var mongoDatabase = new Mock <IMongoDatabase>();

            mongoDatabase.Setup(d =>
                                d.GetCollection <BsonDocument>(It.IsAny <string>(), It.IsAny <MongoCollectionSettings>()))
            .Returns(mongoCollection.Object);

            var mongoClient = new Mock <IMongoClient>();

            mongoClient.Setup(d => d.GetDatabase(It.IsAny <string>(), It.IsAny <MongoDatabaseSettings>()))
            .Returns(mongoDatabase.Object);

            var mongoEntityStorage = new MongoEntityStorage(mongoClient.Object);

            var dfc      = new DataFlowContext(null, serviceProvider);
            var typeName = typeof(CreateTableEntity1).FullName;
            var entity   = new CreateTableEntity1();

            dfc.Add(typeName, entity.GetTableMetadata());
            var items = new ParseResult <CreateTableEntity1>
            {
                entity
            };

            dfc.AddParseData(typeName, items);
            var result = await mongoEntityStorage.HandleAsync(dfc);

            Assert.Equal(DataFlowResult.Success, result);
        }
        public async Task Store_Should_Success()
        {
            var mongoCollection = new Mock <IMongoCollection <BsonDocument> >();

            var mongoDatabase = new Mock <IMongoDatabase>();

            mongoDatabase.Setup(d =>
                                d.GetCollection <BsonDocument>(It.IsAny <string>(), It.IsAny <MongoCollectionSettings>()))
            .Returns(mongoCollection.Object);

            var mongoClient = new Mock <IMongoClient>();

            mongoClient.Setup(d => d.GetDatabase(It.IsAny <string>(), It.IsAny <MongoDatabaseSettings>()))
            .Returns(mongoDatabase.Object);

            var mongoEntityStorage = new MongoEntityStorage(mongoClient.Object);

            var dfc      = new DataContext(null, null, null, null);
            var typeName = typeof(CreateTableEntity1);
            var entity   = new CreateTableEntity1();

            var items = new List <CreateTableEntity1>
            {
                entity
            };

            dfc.AddData(typeName, items);
            await mongoEntityStorage.HandleAsync(dfc);
        }
        public async Task Store_Empty_Should_Success()
        {
            var serviceProvider    = Mock.Of <IServiceProvider>();
            var mongoClient        = new Mock <IMongoClient>();
            var mongoEntityStorage = new MongoEntityStorage(mongoClient.Object);

            var dfc      = new DataFlowContext(null, serviceProvider);
            var typeName = typeof(CreateTableEntity1).FullName;
            var entity   = new CreateTableEntity1();

            dfc.Add(typeName, entity.GetTableMetadata());
            var items = new ParseResult <CreateTableEntity1>();

            dfc.AddParseData(typeName, items);

            var result = await mongoEntityStorage.HandleAsync(dfc);

            Assert.Equal(DataFlowResult.Success, result);
        }