コード例 #1
0
ファイル: Execute.cs プロジェクト: gitter-badger/Drapper
        public void DistributedTransactionIsSuccessfulAndReturnsResult()
        {
            const string tableName = "DistributedTransaction";

            CreateTable(tableName);
            var pocoA = new PocoA {
                Name = Guid.NewGuid().ToString(), Value = 1
            };
            var pocoB = new PocoB {
                Name = Guid.NewGuid().ToString(), Value = 2
            };

            using (var commander = CreateCommander())
            {
                var record = commander.Execute(() =>
                {
                    var t1 = commander.Execute(pocoA, typeof(Execute), tableName) ? pocoA : null;
                    var t2 = commander.Execute(pocoB, typeof(Execute), tableName) ? pocoB : null;
                    return(new MultiMapPocoB
                    {
                        PocoA = t1,
                        PocoB = t2
                    });
                });

                Same(pocoA, record.PocoA);
                Same(pocoB, record.PocoB);
            }
        }
コード例 #2
0
ファイル: ExecuteAsync.cs プロジェクト: gitter-badger/Drapper
        public async Task AsynchronousDistributedTransactionIsSuccessfulAndReturnsResult()
        {
            const string tableName = "DistributedTransactionAsync";

            CreateTable(tableName);
            var pocoA = new PocoA {
                Name = Guid.NewGuid().ToString(), Value = 1
            };
            var pocoB = new PocoB {
                Name = Guid.NewGuid().ToString(), Value = 2
            };

            using (var commander = CreateCommander())
            {
                var record = await commander.ExecuteAsync(() =>
                {
                    var t1 = commander.Execute(pocoA, typeof(Execute), method: tableName) ? pocoA : null;
                    var t2 = commander.Execute(pocoB, typeof(Execute), method: tableName) ? pocoB : null;
                    return(new MultiMapPocoB
                    {
                        PocoA = t1,
                        PocoB = t2
                    });
                });

                ReferenceEquals(pocoA, record.PocoA);
                ReferenceEquals(pocoB, record.PocoB);
            }

            // now query.
            using (var commander = CreateCommander())
            {
                var result = commander.Query <MultiMapPocoB>(type: typeof(ExecuteAsync), method: "DistributedTransactionAsync.Query");
                NotNull(result);
                True(result.Any());
                Equal(2, result.Count());

                // confirm the result corresponds to the poco's passed
                True(result.Any(x => x.Name == pocoA.Name));
                True(result.Any(x => x.Name == pocoB.Name));
            }
        }