コード例 #1
0
        public async Task <ParentModel> GetOnlyParentByNameAsync(string name)
        {
            object      theParams = new { theName = name };
            ParentModel model     = await QuerySingleAsync <ParentModel>($"{SELECT_ALL} where {SELECT_BY_NAME}", theParams);

            return(model);
        }
コード例 #2
0
        public ParentModel GetOnlyParentByName(string name)
        {
            object      theParams = new { theName = name };
            ParentModel model     = QuerySingle <ParentModel>($"{SELECT_ALL} where {SELECT_BY_NAME}", theParams);

            return(model);
        }
コード例 #3
0
ファイル: Tests.cs プロジェクト: pthibodeaux/Scaffolding_2
        public async Task GetParentByGuidAsync_Should_Return_Parent()
        {
            ParentModel parent = await _repo.GetOnlyParentByNameAsync("crm");

            parent = await _repo.GetParentByIdAsync(parent.Id);

            parent.Should().NotBeNull();
            parent.Children.Should().NotBeNullOrEmpty();
        }
コード例 #4
0
ファイル: Tests.cs プロジェクト: pthibodeaux/Scaffolding_2
        public void GetParentByGuid_Should_Return_Parent()
        {
            ParentModel parent = _repo.GetOnlyParentByName("crm");

            parent = _repo.GetParentById(parent.Id);

            parent.Should().NotBeNull();
            parent.Children.Should().NotBeNullOrEmpty();
        }
コード例 #5
0
        public ParentModel GetParentById(int unique)
        {
            object      theParams = new { theId = unique };
            ParentModel model     = QuerySingle <ParentModel>($"{SELECT_ALL} where {SELECT_ONE}", theParams);
            IEnumerable <ClientRedirectUri> children = Query <ClientRedirectUri>(SELECT_CHILDREN_FOR_PARENT, theParams);

            model.Children = children;

            return(model);
        }
コード例 #6
0
ファイル: Tests.cs プロジェクト: pthibodeaux/Scaffolding_2
        public async Task Basic_Transaction_Management_Async()
        {
            ParentModel initial = null;
            ParentModel intrans = null;
            ParentModel outside = null;
            int         id;

            TestHarnessRepository repo2 = new TestHarnessRepository(_provider);
            TestHarnessRepository repo3 = new TestHarnessRepository(_provider);

            IAsyncUnitOfWork uow = await _repo.CreateAsyncUnitOfWork(new[] { _repo, repo2, repo3 });

            using (uow)
            {
                try
                {
                    initial = await _repo.GetOnlyParentByNameAsync("crm");

                    id = initial.Id;

                    initial = await _repo.GetParentByIdAsync(id);

                    await repo2.InsertChildAsync(new ClientRedirectUri
                    {
                        ClientId = id,
                        Uri      = "asdfasdf"
                    });

                    await repo3.InsertChildAsync(new ClientRedirectUri
                    {
                        ClientId = id,
                        Uri      = "fdsafdsa"
                    });

                    intrans = await _repo.GetParentByIdAsync(id);

                    await _repo.DbOperationAsync("crm");
                }
                finally
                {
                    uow.RollbackTransaction();
                }
            }

            outside = await _repo.GetParentByIdAsync(id);

            initial.Should().NotBeNull();
            intrans.Should().NotBeNull();
            outside.Should().NotBeNull();
            initial.Children.Should().NotBeNullOrEmpty();
            intrans.Children.Should().NotBeNullOrEmpty();
            outside.Children.Should().NotBeNullOrEmpty();
            initial.Children.Count().Should().Be(intrans.Children.Count() - 2);
            initial.Children.Count().Should().Be(outside.Children.Count());
        }
コード例 #7
0
ファイル: Tests.cs プロジェクト: pthibodeaux/Scaffolding_2
        public async Task Get_Should_Load_Object_By_Identity_Async()
        {
            ParentModel parent = await _repo.GetOnlyParentByNameAsync("crm");

            parent = _repo.GetParentById(parent.Id);
            ClientRedirectUri uri = await _repo.GetAsync <ClientRedirectUri>(parent.Children.First().ClientRedirectUriId);

            parent.Should().NotBeNull();
            parent.Children.Should().NotBeNullOrEmpty();
            uri.Should().NotBeNull();
        }
コード例 #8
0
ファイル: Tests.cs プロジェクト: pthibodeaux/Scaffolding_2
        public void Get_Should_Load_Object_By_Identity()
        {
            ParentModel parent = _repo.GetOnlyParentByName("crm");

            parent = _repo.GetParentById(parent.Id);
            ClientRedirectUri uri = _repo.Get <ClientRedirectUri>(parent.Children.First().ClientRedirectUriId);

            parent.Should().NotBeNull();
            parent.Children.Should().NotBeNullOrEmpty();
            uri.Should().NotBeNull();
        }
コード例 #9
0
        public (IEnumerable <ParentModel> list, ParentModel single, ParentModel full) DbOperation(string clientName)
        {
            IEnumerable <ParentModel> list = null;
            ParentModel single             = null;
            ParentModel full = null;

            UseConnection((db, tran) =>
            {
                list = db.Query <ParentModel>(new CommandDefinition(SELECT_ALL, null, tran));

                object nameParams = new { theName = list.First(c => c.Name == clientName).Name };
                single            = db.QuerySingle <ParentModel>($"{SELECT_ALL} where {SELECT_BY_NAME}", nameParams, tran);
                full = GetParentById(single.Id);
            });

            return(list, single, full);
        }
コード例 #10
0
ファイル: Tests.cs プロジェクト: pthibodeaux/Scaffolding_2
        public async Task Multiple_Get_Operations_Should_All_Work()
        {
            ParentModel parent = await _repo.GetOnlyParentByNameAsync("crm");

            List <Task <ParentModel> > gets = new List <Task <ParentModel> >();

            for (int i = 0; i < 10; i++)
            {
                gets.Add(_repo.GetParentByIdAsync(parent.Id));
            }

            await Task.WhenAll(gets);

            foreach (Task <ParentModel> task in gets)
            {
                task.Result.Should().NotBeNull();
            }
        }
コード例 #11
0
        public async Task <(IEnumerable <ParentModel> list, ParentModel single, ParentModel full)> DbOperationAsync(string clientName)
        {
            IEnumerable <ParentModel> list = null;
            ParentModel single             = null;
            ParentModel full = null;

            await UseConnectionAsync(async (db, tran) =>
            {
                list = await db.QueryAsync <ParentModel>(new CommandDefinition(SELECT_ALL, null, tran));

                ParentModel model = list.First(c => c.Name == clientName);
                object nameParams = new { theName = model.Name };

                single = await db.QuerySingleAsync <ParentModel>($"{SELECT_ALL} where {SELECT_BY_NAME}", nameParams, tran);
                full   = await GetParentByIdAsync(model.Id);
            });

            return(list, single, full);
        }
コード例 #12
0
ファイル: Tests.cs プロジェクト: pthibodeaux/Scaffolding_2
        public void Basic_Transaction_Management()
        {
            ParentModel initial = null;
            ParentModel intrans = null;

            TestHarnessRepository repo2 = new TestHarnessRepository(_provider);
            TestHarnessRepository repo3 = new TestHarnessRepository(_provider);

            IUnitOfWork uow = _repo.CreateUnitOfWork(new[] { _repo, repo2, repo3 });

            using (uow)
            {
                try
                {
                    initial = _repo.GetOnlyParentByName("crm");
                    initial = _repo.GetParentById(initial.Id);
                    repo2.InsertChild(new ClientRedirectUri
                    {
                        ClientId = initial.Id,
                        Uri      = "asdfasdf"
                    });
                    repo3.InsertChild(new ClientRedirectUri
                    {
                        ClientId = initial.Id,
                        Uri      = "fdsafdsa"
                    });
                    intrans = _repo.GetParentById(initial.Id);
                }
                finally
                {
                    uow.RollbackTransaction();
                }
            }

            initial.Should().NotBeNull();
            intrans.Should().NotBeNull();
            initial.Children.Should().NotBeNullOrEmpty();
            intrans.Children.Should().NotBeNullOrEmpty();
            initial.Children.Count().Should().Be(intrans.Children.Count() - 2);
        }