public async Task TestGet_CheckProperties()
        {
            var moneyFlowSourceRecipientType = new MoneyFlowSourceRecipientType
            {
                MoneyFlowSourceRecipientTypeId = 1,
                TypeName = "type"
            };

            context.MoneyFlowSourceRecipientTypes.Add(moneyFlowSourceRecipientType);
            Action <PagedQueryResults <MoneyFlowSourceRecipientTypeDTO> > tester = (results) =>
            {
                Assert.AreEqual(1, results.Total);
                Assert.AreEqual(1, results.Results.Count);

                var firstResult = results.Results.First();
                Assert.AreEqual(moneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeId, firstResult.Id);
                Assert.AreEqual(moneyFlowSourceRecipientType.TypeName, firstResult.Name);
            };
            var defaultSorter = new ExpressionSorter <MoneyFlowSourceRecipientTypeDTO>(x => x.Id, SortDirection.Ascending);
            var queryOperator = new QueryableOperator <MoneyFlowSourceRecipientTypeDTO>(0, 10, defaultSorter);

            var serviceResults      = service.Get(queryOperator);
            var serviceResultsAsync = await service.GetAsync(queryOperator);

            tester(serviceResults);
            tester(serviceResultsAsync);
        }
        public async Task TestGetSourceMoneyFlowTypes_NoSettings()
        {
            var moneyFlowSourceRecipientType = new MoneyFlowSourceRecipientType
            {
                MoneyFlowSourceRecipientTypeId = 1,
                TypeName = "type"
            };
            var peerMoneyFlowSourceRecipientType = new MoneyFlowSourceRecipientType
            {
                MoneyFlowSourceRecipientTypeId = 2,
                TypeName = "peer type"
            };

            context.MoneyFlowSourceRecipientTypes.Add(moneyFlowSourceRecipientType);
            context.MoneyFlowSourceRecipientTypes.Add(peerMoneyFlowSourceRecipientType);

            Action <List <MoneyFlowSourceRecipientTypeDTO> > tester = (results) =>
            {
                Assert.AreEqual(0, results.Count);
            };

            var serviceResults      = service.GetSourceMoneyFlowTypes(moneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeId);
            var serviceResultsAsync = await service.GetSourceMoneyFlowTypesAsync(moneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeId);

            tester(serviceResults);
            tester(serviceResultsAsync);
        }
 /// <summary>
 /// Creates a new SimpleMoneyFlow.
 /// </summary>
 /// <param name="id">The id of the money flow.</param>
 /// <param name="sourceOrRecipientEntityId">The id of the source or recipient entity.</param>
 /// <param name="sourceOrRecipientEntityTypeId">The type id of the source or recipient money flow.</param>
 public EditedMoneyFlow(int id, int sourceOrRecipientEntityId, int sourceOrRecipientEntityTypeId)
 {
     this.Id = id;
     this.SourceOrRecipientEntityId = sourceOrRecipientEntityId;
     if (MoneyFlowSourceRecipientType.GetStaticLookup(sourceOrRecipientEntityTypeId) == null)
     {
         throw new UnknownStaticLookupException(String.Format("The money flow source or recipient entity type id [{0}] is not recognized.", sourceOrRecipientEntityTypeId));
     }
     this.SourceOrRecipientEntityTypeId = sourceOrRecipientEntityTypeId;
 }
        /// <summary>
        /// Creates a new AdditionalMoneyFlow object that can be used to add Money Flow to the ECA system.
        /// </summary>
        /// <param name="createdBy">The creator.</param>
        /// <param name="description">The description.</param>
        /// <param name="value">The value.</param>
        /// <param name="moneyFlowStatusId">The money flow status id.</param>
        /// <param name="transactionDate">The transaction date.</param>
        /// <param name="fiscalYear">The fiscal year.</param>
        /// <param name="parentMoneyFlowId">The parent money flow id.  This is the line item that this money flow is getting money from.</param>
        /// <param name="sourceEntityId">The source entity id.</param>
        /// <param name="recipientEntityId">The recipient entity id.</param>
        /// <param name="sourceEntityTypeId">The source entity type id.</param>
        /// <param name="recipientEntityTypeId">The recipient entity type id.</param>
        /// <param name="grantNumber">The money flow grant number.</param>
        public AdditionalMoneyFlow(
            User createdBy,
            int?parentMoneyFlowId,
            string description,
            string grantNumber,
            decimal value,
            int moneyFlowStatusId,
            DateTimeOffset transactionDate,
            int fiscalYear,
            int?sourceEntityId,
            int?recipientEntityId,
            int sourceEntityTypeId,
            int recipientEntityTypeId,
            bool isDirect)
        {
            Contract.Requires(createdBy != null, "The created by user must not be null.");
            var moneyFlowStatus = MoneyFlowStatus.GetStaticLookup(moneyFlowStatusId);

            if (moneyFlowStatus == null)
            {
                throw new UnknownStaticLookupException(String.Format("The money flow status [{0}] is not supported.", moneyFlowStatusId));
            }
            var recipientEntityType = MoneyFlowSourceRecipientType.GetStaticLookup(recipientEntityTypeId);

            if (recipientEntityType == null)
            {
                throw new UnknownStaticLookupException(String.Format("The recipient type [{0}] is not supported.", recipientEntityTypeId));
            }
            var sourceEntityType = MoneyFlowSourceRecipientType.GetStaticLookup(sourceEntityTypeId);

            if (sourceEntityType == null)
            {
                throw new UnknownStaticLookupException(String.Format("The source type [{0}] is not supported.", sourceEntityTypeId));
            }

            this.Audit                 = new Create(createdBy);
            this.Description           = description;
            this.ParentMoneyFlowId     = parentMoneyFlowId;
            this.Value                 = value;
            this.MoneyFlowStatusId     = moneyFlowStatusId;
            this.TransactionDate       = transactionDate;
            this.FiscalYear            = fiscalYear;
            this.SourceEntityId        = sourceEntityId;
            this.SourceEntityTypeId    = sourceEntityTypeId;
            this.RecipientEntityId     = recipientEntityId;
            this.RecipientEntityTypeId = recipientEntityTypeId;
            this.MoneyFlowTypeId       = MoneyFlowType.Incoming.Id;
            this.GrantNumber           = grantNumber;
            this.IsDirect              = isDirect;
        }
        public async Task TestGetRecipientMoneyFlowTypes_CheckProperties()
        {
            var moneyFlowSourceRecipientType = new MoneyFlowSourceRecipientType
            {
                MoneyFlowSourceRecipientTypeId = 1,
                TypeName = "type"
            };
            var peerMoneyFlowSourceRecipientType = new MoneyFlowSourceRecipientType
            {
                MoneyFlowSourceRecipientTypeId = 2,
                TypeName = "peer type"
            };
            var setting = new MoneyFlowSourceRecipientTypeSetting
            {
                Id          = 1,
                IsRecipient = true,
                MoneyFlowSourceRecipientType       = moneyFlowSourceRecipientType,
                MoneyFlowSourceRecipientTypeId     = moneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeId,
                PeerMoneyFlowSourceRecipientType   = peerMoneyFlowSourceRecipientType,
                PeerMoneyFlowSourceRecipientTypeId = peerMoneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeId
            };

            moneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeSettings.Add(setting);
            context.MoneyFlowSourceRecipientTypes.Add(moneyFlowSourceRecipientType);
            context.MoneyFlowSourceRecipientTypes.Add(peerMoneyFlowSourceRecipientType);
            context.MoneyFlowSourceRecipientTypeSettings.Add(setting);

            Action <List <MoneyFlowSourceRecipientTypeDTO> > tester = (results) =>
            {
                Assert.AreEqual(1, results.Count);
                var firstResult = results.First();
                Assert.AreEqual(peerMoneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeId, firstResult.Id);
                Assert.AreEqual(peerMoneyFlowSourceRecipientType.TypeName, firstResult.Name);
            };

            var serviceResults      = service.GetRecipientMoneyFlowTypes(moneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeId);
            var serviceResultsAsync = await service.GetRecipientMoneyFlowTypesAsync(moneyFlowSourceRecipientType.MoneyFlowSourceRecipientTypeId);

            tester(serviceResults);
            tester(serviceResultsAsync);
        }
        public void TestCreateGetProgramBudgetByYearQuery()
        {
            var sourceId    = 1;
            var recipientId = 2;
            MoneyFlowSourceRecipientType programType;
            MoneyFlowSourceRecipientType projectType;
            MoneyFlowStatus actual;

            programType = new MoneyFlowSourceRecipientType
            {
                MoneyFlowSourceRecipientTypeId = MoneyFlowSourceRecipientType.Program.Id,
                TypeName = MoneyFlowSourceRecipientType.Program.Value
            };
            projectType = new MoneyFlowSourceRecipientType
            {
                MoneyFlowSourceRecipientTypeId = MoneyFlowSourceRecipientType.Project.Id,
                TypeName = MoneyFlowSourceRecipientType.Project.Value
            };
            actual = new MoneyFlowStatus
            {
                MoneyFlowStatusId   = MoneyFlowStatus.Actual.Id,
                MoneyFlowStatusName = MoneyFlowStatus.Actual.Value
            };

            var endDate = DateTime.UtcNow;

            var program = new Program
            {
                ProgramId = sourceId,
                Name      = "program"
            };
            var project = new Project
            {
                ProjectId = recipientId,
                Name      = "project",
                ProgramId = program.ProgramId,
                EndDate   = endDate
            };
            var moneyFlow = new MoneyFlow
            {
                SourceProgramId    = sourceId,
                RecipientProjectId = recipientId,
                SourceProgram      = program,
                RecipientProject   = project,
                SourceType         = programType,
                SourceTypeId       = programType.MoneyFlowSourceRecipientTypeId,
                RecipientType      = projectType,
                RecipientTypeId    = projectType.MoneyFlowSourceRecipientTypeId,
                MoneyFlowStatus    = actual,
                MoneyFlowStatusId  = actual.MoneyFlowStatusId,
                TransactionDate    = DateTimeOffset.UtcNow,
                Value             = 100.00m,
                Description       = "desc",
                FiscalYear        = 2013,
                MoneyFlowId       = 10,
                ParentMoneyFlowId = 100
            };
            var moneyFlow2 = new MoneyFlow
            {
                SourceProgramId    = sourceId,
                RecipientProjectId = recipientId,
                SourceProgram      = program,
                RecipientProject   = project,
                SourceType         = programType,
                SourceTypeId       = programType.MoneyFlowSourceRecipientTypeId,
                RecipientType      = projectType,
                RecipientTypeId    = projectType.MoneyFlowSourceRecipientTypeId,
                MoneyFlowStatus    = actual,
                MoneyFlowStatusId  = actual.MoneyFlowStatusId,
                TransactionDate    = DateTimeOffset.UtcNow,
                Value             = 150.00m,
                Description       = "desc",
                FiscalYear        = 2014,
                MoneyFlowId       = 11,
                ParentMoneyFlowId = 110
            };

            project.RecipientProjectMoneyFlows.Add(moneyFlow);
            project.RecipientProjectMoneyFlows.Add(moneyFlow2);
            program.Projects.Add(project);
            context.Programs.Add(program);
            context.Projects.Add(project);
            context.MoneyFlows.Add(moneyFlow);
            context.MoneyFlows.Add(moneyFlow2);

            List <int> programIds = new List <int>();

            programIds.Add(program.ProgramId);
            var results = SnapshotQueries.CreateGetProgramBudgetByYearQuery(context, programIds);

            Assert.AreEqual(0, results.Result.Sum(x => x.Value));
            Assert.AreEqual(results.Result.Where(y => y.Key == 2013).Select(v => v.Value).FirstOrDefault(), 0);
            Assert.AreEqual(results.Result.Where(y => y.Key == 2014).Select(v => v.Value).FirstOrDefault(), 0);
        }