public void GetBaseValueSegmentEventsByRevenueObjectId_MatchId_ValidateSortOrder() { //BVS Events shoulld be returned in Descending order based on AsOf Date // //Add another BVS with today's date. This BVS should be the first in returned listed // var testBvs = new Models.V1.BaseValueSegment { Id = BvsId - 1, AsOf = DateTime.Now, TransactionId = 0, RevenueObjectId = RevObjId, DynCalcInstanceId = 0, BaseValueSegmentTransactions = new List <BaseValueSegmentTransaction>() }; var testBvsTrans = new BaseValueSegmentTransaction { Id = BvsTranId + 1, BaseValueSegmentId = BvsId - 1, TransactionId = 0, EffectiveStatus = "A", BaseValueSegmentTransactionTypeId = 2, DynCalcStepTrackingId = -100, BaseValueSegmentOwners = new List <BaseValueSegmentOwner>(), BaseValueSegmentValueHeaders = new List <BaseValueSegmentValueHeader>() }; var testBvsOwner = new BaseValueSegmentOwner { Id = BvsOwnerId + 1, BaseValueSegmentTransactionId = BvsTranId - 1, LegalPartyRoleId = 0, BeneficialInterestPercent = 50, DynCalcStepTrackingId = 0, GRMEventId = EventId + 1, BaseValueSegmentOwnerValueValues = new List <BaseValueSegmentOwnerValue>() }; testBvsTrans.BaseValueSegmentOwners.Add(testBvsOwner); testBvs.BaseValueSegmentTransactions.Add(testBvsTrans); _context.BaseValueSegments.Add(testBvs); _context.SaveChanges(); IBaseValueSegmentRepository baseValueSegmentRepository = new BaseValueSegmentRepository(_context); var baseValueSegmentEvents = baseValueSegmentRepository.GetBvsEventsByRevenueObjectId(RevObjId).ToList(); baseValueSegmentEvents.Count.ShouldBeGreaterThan(1); DateTime date1 = baseValueSegmentEvents.First().BvsAsOf; DateTime date2 = baseValueSegmentEvents.Last().BvsAsOf; date1.ShouldBeGreaterThan(date2); }
public async Task <Models.V1.BaseValueSegment> CreateAsync(Models.V1.BaseValueSegment baseValueSegment, IEnumerable <BaseValueSegmentOwnerValue> baseValueSegmentOwnerValuesList) { using (var transaction = await _baseValueSegmentQueryContext.Database.BeginTransactionAsync()) { try { await _baseValueSegmentQueryContext.BaseValueSegments.AddAsync(baseValueSegment); await _baseValueSegmentQueryContext.SaveChangesAsync(); var baseValueSegmentOwnerValues = baseValueSegmentOwnerValuesList.ToList(); if (baseValueSegmentOwnerValues.Count > 0) { baseValueSegmentOwnerValues.ForEach(x => { if (x.Header == null) { // This allows us to determine in the DTO that was submitted. throw new NullReferenceException($"Header cannot be set for Base Value Segment Owner with Id: {x.Id}"); } x.Id = 0; x.BaseValueSegmentOwnerId = x.Owner.Id; x.BaseValueSegmentValueHeaderId = x.Header.Id; }); await _baseValueSegmentQueryContext.BaseValueSegmentOwnerValues.AddRangeAsync(baseValueSegmentOwnerValues); await _baseValueSegmentQueryContext.SaveChangesAsync(); } transaction.Commit(); return(baseValueSegment); } catch { transaction.Rollback(); throw; } } }
public BaseValueSegmentRepositoryTests() { var optionsBuilder = new DbContextOptionsBuilder <BaseValueSegmentQueryContext>(); optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString("N")); _context = new BaseValueSegmentQueryContext(optionsBuilder.Options); var baseValueSegmentTransaction = new BaseValueSegmentTransaction { Id = BvsTranId, BaseValueSegmentId = BvsId, TransactionId = 0, EffectiveStatus = "A", BaseValueSegmentTransactionTypeId = 2, DynCalcStepTrackingId = -100, BaseValueSegmentOwners = new List <BaseValueSegmentOwner>(), BaseValueSegmentValueHeaders = new List <BaseValueSegmentValueHeader>() }; var baseValueSegmentOwner = new BaseValueSegmentOwner { Id = BvsOwnerId, BaseValueSegmentTransactionId = BvsTranId, LegalPartyRoleId = 0, BeneficialInterestPercent = 50, DynCalcStepTrackingId = 0, GRMEventId = EventId, AlphaBVSOwnerId = null, BaseValueSegmentOwnerValueValues = new List <BaseValueSegmentOwnerValue>() }; var baseValueSegmentValueHeader = new BaseValueSegmentValueHeader { Id = BvsValueHeaderId, BaseValueSegmentTransactionId = BvsTranId, BaseYear = 2015, DynCalcStepTrackingId = 0, BaseValueSegmentValues = new List <BaseValueSegmentValue>() }; var baseValueSegmentValue = new BaseValueSegmentValue { Id = BvsValueId, BaseValueSegmentValueHeaderId = BvsValueHeaderId, SubComponent = 1, ValueAmount = 110000, PercentComplete = 75, FullValueAmount = 120000, DynCalcStepTrackingId = 0, }; var baseValueSegmentOwnerValue = new BaseValueSegmentOwnerValue { Id = BvsOwnerValueId, BaseValueSegmentOwnerId = BvsOwnerValueId, BaseValue = 100000, DynCalcStepTrackingId = 0, }; var baseValueSegment = new Models.V1.BaseValueSegment { Id = BvsId, AsOf = AssessmentEventDate, TransactionId = 0, RevenueObjectId = RevObjId, SequenceNumber = 1, DynCalcInstanceId = 0, DynCalcStepTrackingId = 0 }; baseValueSegmentOwner.BaseValueSegmentOwnerValueValues.Add(baseValueSegmentOwnerValue); baseValueSegmentValueHeader.BaseValueSegmentValues.Add(baseValueSegmentValue); baseValueSegmentTransaction.BaseValueSegmentOwners.Add(baseValueSegmentOwner); baseValueSegmentTransaction.BaseValueSegmentValueHeaders.Add(baseValueSegmentValueHeader); baseValueSegment.BaseValueSegmentTransactions.Add(baseValueSegmentTransaction); _context.Add(baseValueSegment); var userDeletedTransaction = new BaseValueSegmentTransactionType { Id = 1, Name = "User Deleted", Description = "User Deleted" }; _context.Add(userDeletedTransaction); var userTransactionType = new BaseValueSegmentTransactionType { Id = 2, Name = "User", Description = "User" }; _context.Add(userTransactionType); var beneficialInterestInfo = new BeneficialInterestInfo { LegalPartyId = 100, GrmEventId = 200, EventDate = new DateTime(2015, 1, 1), EventType = "Transfer", EffectiveDate = new DateTime(2015, 2, 1), DocNumber = "UnitTestDoc", DocType = "Deed", DocDate = new DateTime(2015, 3, 1), OwnerId = 300, OwnerName = "Unit Test Owner", LegalPartyRoleId = 400, BeneficialInterestPercentage = 50, PercentageInterestGain = 25 }; _context.Add(beneficialInterestInfo); _context.SaveChanges(); }