public void ThenIfChildIsNullDontAddItToTheParentAsAChild(ParentChildrenMapper <Parent, Child> sut)
        {
            var lookup = new Dictionary <int, Parent>();

            var parent = new Parent {
                Id = 2, Children = new List <Child>()
            };
            Child child = null;

            sut.Map(lookup, x => x.Id, x => x.Children)(parent, child);

            lookup.Values.Single().Children.Count.Should().Be(0);
        }
        public void ThenIfLookupIsEmptyShouldAddParentObjectAndWithChild(ParentChildrenMapper <Parent, Child> sut)
        {
            var lookup = new Dictionary <int, Parent>();
            var parent = new Parent {
                Id = 2, Children = new List <Child>()
            };
            var child = new Child();

            var result = sut.Map(lookup, x => x.Id, x => x.Children)(parent, child);

            result.Should().Be(parent);
            result.Children.Should().Contain(child);
            lookup.Values.Should().Contain(parent);
        }
        public async Task <List <Framework> > GetAllFrameworks()
        {
            var lookup = new Dictionary <object, Framework>();
            var mapper = new ParentChildrenMapper <Framework, FundingPeriod>();

            return(await WithConnection(async connection =>
            {
                var results = await connection.QueryAsync(
                    sql: $"[dbo].[GetFrameworks]",
                    commandType: CommandType.StoredProcedure,
                    map: mapper.Map(lookup, x => x.Id, x => x.FundingPeriods),
                    splitOn: "Id"
                    );

                return results.GroupBy(c => c.Id).Select(item => item.First()).ToList();
            }));
        }
        private static async Task <Commitment> GetCommitment(long commitmentId, IDbConnection connection, IDbTransaction transation = null)
        {
            var lookup = new Dictionary <object, Commitment>();
            var mapper = new ParentChildrenMapper <Commitment, Apprenticeship>();

            var parameters = new DynamicParameters();

            parameters.Add("@commitmentId", commitmentId);

            var results = await connection.QueryAsync(
                sql : $"[dbo].[GetCommitment]",
                param : parameters,
                transaction : transation,
                commandType : CommandType.StoredProcedure,
                map : mapper.Map(lookup, x => x.Id, x => x.Apprenticeships));

            return(lookup.Values.SingleOrDefault());
        }
Пример #5
0
        private Task <IList <CommitmentSummary> > GetCommitmentsByIdentifier(string identifierName, long identifierValue)
        {
            var lookup = new Dictionary <object, CommitmentSummary>();
            var mapper = new ParentChildrenMapper <CommitmentSummary, Message>();

            return(WithConnection <IList <CommitmentSummary> >(async c =>
            {
                var parameters = new DynamicParameters();
                parameters.Add($"@id", identifierValue);

                var results = await c.QueryAsync(
                    sql: $"SELECT * FROM [dbo].[CommitmentSummaryWithMessages] WHERE {identifierName} = @id AND CommitmentStatus <> {(int)CommitmentStatus.Deleted} ORDER BY CreatedOn DESC;",
                    param: parameters,
                    map: mapper.Map(lookup, x => x.Id, x => x.Messages),
                    splitOn: "CommitmentId");

                return lookup.Values.ToList();
            }));
        }
        public void ThenIfLookupAlreadyContainsEntryWithIdOfParentShouldAddNewChildToExistingParent(
            ParentChildrenMapper <Parent, Child> sut)
        {
            var lookup        = new Dictionary <int, Parent>();
            var existingEntry = new Parent {
                Id = 2, Children = new List <Child> {
                    new Child()
                }
            };

            lookup.Add(existingEntry.Id, existingEntry);

            var parent = new Parent {
                Id = 2, Children = new List <Child>()
            };
            var child = new Child();

            sut.Map(lookup, x => x.Id, x => x.Children)(parent, child);

            lookup.Values.Count.Should().Be(1);
            lookup.Values.Single().Children.Count.Should().Be(2);
        }
        public void ThenANullLookupParameterThrowsAnArgumentNullException(ParentChildrenMapper <Parent, Child> sut)
        {
            Action act = () => sut.Map(null, x => x, x => new List <Child>());

            act.ShouldThrow <ArgumentNullException>();
        }