예제 #1
0
        [Fact] // TODO: Need to consider the new services we have added.
        public void Get_CallsGetOnAssessmentEventService_ReceivesAssessmentEventServiceDomainDTOAndRevenueObjectDomainAndLegalPartyRolesDomainDTO()
        {
            var          assessmentEventId             = 1;
            var          assessmentEventDate           = DateTime.Now;
            const int    asmtRevnEventId               = 2;
            const int    asmtRevnId                    = 6;
            const int    nonPrimeLegalPartyRoleId      = 3;
            const int    primeLegalPartyRoleId         = 4;
            const string primeLegalPartyDisplayName    = "Prime Dude";
            const string nonPrimeLegalPartyDisplayName = "Nonprime Dude";
            const string tagDescription                = "some TAG description";
            const string firstName  = "UnitTestFirstName";
            const string middleName = "UnitTestMiddleName";
            const string lastName   = "UnitTestLastName";
            const string nameSfx    = "UnitTestNameSfx";
            const int    legalPartyRoleObjectType = 9999;

            var assessmentEventDto = new AssessmentEventDto
            {
                Id                       = assessmentEventId,
                EventDate                = assessmentEventDate,
                AsmtEventType            = 999,
                AsmtEventTypeDescription = "Annual",
                RevObjId                 = 888,
                DynCalcStepTrackingId    = 777,
                TaxYear                  = 2017,
                TranId                   = 99999999999,
                PrimaryBaseYear          = 2015,
                PrimaryBaseYearMultipleOrSingleDescription = "M"
            };
            var assessmentEventTranDto = new AssessmentEventTransactionDto
            {
                AsmtEventStateDescription = "Review Required",
                AsmtEventId     = assessmentEventId,
                AsmtEventState  = 1,
                AsmtRevnEventId = asmtRevnEventId,
                Id = 4
            };

            assessmentEventDto.AssessmentEventTransactions.Add(assessmentEventTranDto);

            var assessmentRevnDto = new AssessmentRevisionDto
            {
                Id = asmtRevnId
            };

            var revenueObjectDto = new RevenueObjectDto
            {
                Id = 333
            };

            var tagDto = new TAGDto
            {
                Description = tagDescription
            };

            var legalPartyRoleDtos = new List <LegalPartyRoleDto>()
            {
                new LegalPartyRoleDto()
                {
                    Id = nonPrimeLegalPartyRoleId,
                    PrimeLegalParty = 0,
                    LegalParty      = new LegalPartyDto()
                    {
                        DisplayName = nonPrimeLegalPartyDisplayName,
                    }
                },
                new LegalPartyRoleDto()
                {
                    Id = primeLegalPartyRoleId,
                    PrimeLegalParty = 1,
                    LegalParty      = new LegalPartyDto()
                    {
                        Id          = 100,
                        DisplayName = primeLegalPartyDisplayName,
                        FirstName   = firstName,
                        MiddleName  = middleName,
                        LastName    = lastName,
                        NameSfx     = nameSfx,
                    },
                    ObjectType = legalPartyRoleObjectType
                }
            };
            var bvsTran1 = new BaseValueSegmentTransactionDto()
            {
                Id = 1,
                BaseValueSegmentTransactionTypeId = 3,
                BaseValueSegmentTransactionType   = new BaseValueSegmentTransactionTypeDto()
                {
                    Name        = "Conversion",
                    Description = "Conversion"
                }
            };
            var bvsTran2 = new BaseValueSegmentTransactionDto()
            {
                Id = 2,
                BaseValueSegmentTransactionTypeId = 2,
                BaseValueSegmentTransactionType   = new BaseValueSegmentTransactionTypeDto()
                {
                    Name        = "User",
                    Description = "User"
                }
            };
            var baseValueSegmentDto = new BaseValueSegmentDto()
            {
                AsOf            = assessmentEventDate,
                RevenueObjectId = 888,
                BaseValueSegmentTransactions = new List <BaseValueSegmentTransactionDto>()
                {
                    bvsTran1,
                    bvsTran2
                }
            };
            var statutoryReferenceDto = new StatutoryReferenceDto()
            {
                Description = "Test Statuatory Reference"
            };

            var httpClientWrapperMock = new Mock <IHttpClientWrapper>();

            httpClientWrapperMock.Setup(x => x.Get <AssessmentEventDto>(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(assessmentEventDto);

            httpClientWrapperMock.Setup(x => x.Get <AssessmentRevisionDto>(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(assessmentRevnDto);
            httpClientWrapperMock.Setup(x => x.Get <RevenueObjectDto>(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(revenueObjectDto);
            httpClientWrapperMock.Setup(x => x.Get <TAGDto>(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(tagDto);
            httpClientWrapperMock.Setup(x => x.Get <IList <LegalPartyRoleDto> >(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(legalPartyRoleDtos);
            httpClientWrapperMock.Setup(x => x.Get <BaseValueSegmentDto>(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(baseValueSegmentDto);
            httpClientWrapperMock.Setup(x => x.Get <StatutoryReferenceDto>(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(statutoryReferenceDto);

            var applicationSettingsHelper = new Mock <IApplicationSettingsHelper>();

            applicationSettingsHelper.Setup(x => x.AssessmentEventServiceApiUrl).Returns("");
            applicationSettingsHelper.Setup(x => x.RevenueObjectServiceApiUrl).Returns("");
            applicationSettingsHelper.Setup(x => x.LegalPartyServiceApiUrl).Returns("");
            applicationSettingsHelper.Setup(x => x.BaseValueSegmentServiceApiUrl).Returns("");

            var domain = new AssessmentHeaderDomain(httpClientWrapperMock.Object, applicationSettingsHelper.Object);
            var assessmentHeaderModel = domain.Get(assessmentEventId).Result;

            assessmentHeaderModel.ShouldNotBeNull();
            assessmentHeaderModel.ShouldBeOfType <Models.V1.AssessmentHeader>();
            assessmentHeaderModel.AssessmentEvent.AssessmentEventId.ShouldBe(assessmentEventDto.Id);
            assessmentHeaderModel.AssessmentEvent.EventDate.ShouldBe(assessmentEventDto.EventDate);
            assessmentHeaderModel.AssessmentEvent.AssessmentEventType.ShouldBe(assessmentEventDto.AsmtEventType);
            assessmentHeaderModel.AssessmentEvent.AssessmentEventTypeDescription.ShouldBe(assessmentEventDto.AsmtEventTypeDescription);
            assessmentHeaderModel.AssessmentEvent.RevenueObjectId.ShouldBe(assessmentEventDto.RevObjId);
            assessmentHeaderModel.AssessmentEvent.TaxYear.ShouldBe(assessmentEventDto.TaxYear);
            assessmentHeaderModel.AssessmentEvent.EventState.ShouldBe(assessmentEventDto.AssessmentEventTransactions[0].AsmtEventStateDescription);
            assessmentHeaderModel.AssessmentEvent.RevisionId.ShouldBe(assessmentRevnDto.Id);
            assessmentHeaderModel.AssessmentEvent.BVSTranType.ShouldBe("User");
            assessmentHeaderModel.AssessmentEvent.TransactionId.ShouldBe(4);
            assessmentHeaderModel.AssessmentEvent.Note.ShouldBeNull();
            assessmentHeaderModel.AssessmentEvent.ReferenceNumber.ShouldBeNull();
            assessmentHeaderModel.AssessmentEvent.ChangeReason.ShouldBeNull();
            assessmentHeaderModel.AssessmentEvent.RevenueAndTaxCode.ShouldBe("Test Statuatory Reference");
            assessmentHeaderModel.AssessmentEvent.PrimaryBaseYear.ShouldBe(assessmentEventDto.PrimaryBaseYear);
            assessmentHeaderModel.AssessmentEvent.PrimaryBaseYearMultipleOrSingleDescription.ShouldBe(assessmentEventDto.PrimaryBaseYearMultipleOrSingleDescription);
            assessmentHeaderModel.RevenueObject.TAG.ShouldBe(tagDto.Description);
            assessmentHeaderModel.RevenueObject.Id.ShouldBe(333);
            assessmentHeaderModel.RevenueObject.Ain.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.AreaCd.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.BeginEffectiveDate.ShouldBe(DateTime.MinValue);
            assessmentHeaderModel.RevenueObject.CensusBlock.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.CensusTrack.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.ClassCd.ShouldBe(0);
            assessmentHeaderModel.RevenueObject.ClassCodeDescription.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.CountyCd.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.Description.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.EffectiveStatus.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.GeoCd.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.Pin.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.PropertyType.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.RelatedPins.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.RevenueCode.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.RightDescription.ShouldBe(0);
            assessmentHeaderModel.RevenueObject.RightEstate.ShouldBe(0);
            assessmentHeaderModel.RevenueObject.RightType.ShouldBe(0);
            assessmentHeaderModel.RevenueObject.SitusAddress.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.SubType.ShouldBe(0);
            assessmentHeaderModel.RevenueObject.TaxCode.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.Type.ShouldBe(0);
            assessmentHeaderModel.RevenueObject.UnformattedPin.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.XCoordinate.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.YCoordinate.ShouldBeNull();
            assessmentHeaderModel.RevenueObject.ZCoordinate.ShouldBeNull();
            assessmentHeaderModel.LegalParty.DisplayName.ShouldBe(primeLegalPartyDisplayName);
            assessmentHeaderModel.LegalParty.LegalPartyId.ShouldBe(100);
            assessmentHeaderModel.LegalParty.FirstName.ShouldBe(firstName);
            assessmentHeaderModel.LegalParty.MiddleName.ShouldBe(middleName);
            assessmentHeaderModel.LegalParty.LastName.ShouldBe(lastName);
            assessmentHeaderModel.LegalParty.NameSfx.ShouldBe(nameSfx);
            assessmentHeaderModel.LegalParty.RevenueAcct.ShouldBe(0);
            assessmentHeaderModel.LegalParty.LegalPartyRoleObjectType.ShouldBe(legalPartyRoleObjectType);
        }
        public async Task <Models.V1.AssessmentHeader> Get(int assessmentEventId)
        {
            if (assessmentEventId < 1)
            {
                throw new BadRequestException("Invalid AssessmentEventId");
            }

            var assessmentEventDto = await _httpClientWrapper.Get <AssessmentEventDto>(_applicationSettingsHelper.AssessmentEventServiceApiUrl, $"{Version}/assessmentevents/{assessmentEventId}");

            if (assessmentEventDto == null)
            {
                return(null);
            }

            var assessmentEventTran = assessmentEventDto.AssessmentEventTransactions.OrderByDescending(aet => aet.Id).FirstOrDefault();

            BaseValueSegmentTransactionDto currentBaseValueSegmentTransaction = null;

            BaseValueSegmentDto baseValueSegmentDto = null;

            try
            {
                baseValueSegmentDto = await _httpClientWrapper.Get <BaseValueSegmentDto>(_applicationSettingsHelper.BaseValueSegmentServiceApiUrl,
                                                                                         $"{Version}/basevaluesegments/RevenueObjectId/{assessmentEventDto.RevObjId}/AssessmentEventDate/{assessmentEventDto.EventDate:yyyy-MM-dd}");
            }
            catch (NotFoundException)
            {
                // no records found
            }

            if (baseValueSegmentDto != null)
            {
                var baseValueSegmentTransactions = baseValueSegmentDto.BaseValueSegmentTransactions.OrderByDescending(x => x.Id);
                if (baseValueSegmentTransactions.Any())
                {
                    currentBaseValueSegmentTransaction = baseValueSegmentTransactions.First();
                }
            }

            var assessmentHeader = new Models.V1.AssessmentHeader
            {
                AssessmentEvent = new AssessmentEvent
                {
                    AssessmentEventId              = assessmentEventDto.Id,
                    AssessmentEventType            = assessmentEventDto.AsmtEventType,
                    AssessmentEventTypeDescription = assessmentEventDto.AsmtEventTypeDescription,
                    RevenueObjectId = assessmentEventDto.RevObjId,
                    EventDate       = assessmentEventDto.EventDate,
                    TaxYear         = assessmentEventDto.TaxYear,
                    EventState      = assessmentEventTran?.AsmtEventStateDescription,
                    TransactionId   = assessmentEventTran?.Id ?? null,
                    BVSTranType     = (currentBaseValueSegmentTransaction != null) ? currentBaseValueSegmentTransaction.BaseValueSegmentTransactionType.Description : string.Empty,
                    PrimaryBaseYear = assessmentEventDto.PrimaryBaseYear,
                    PrimaryBaseYearMultipleOrSingleDescription = assessmentEventDto.PrimaryBaseYearMultipleOrSingleDescription
                }
            };
            RevenueObjectDto revenueObjectDto = null;

            try
            {
                revenueObjectDto = await _httpClientWrapper.Get <RevenueObjectDto>(_applicationSettingsHelper.RevenueObjectServiceApiUrl,
                                                                                   $"{Version}/revenueobjects/{assessmentEventDto.RevObjId}/EffectiveDate/{assessmentEventDto.EventDate:yyyy-MM-dd}");
            }
            catch (NotFoundException)
            {
                //if not found it could be because the PIN is inactive so send back a user-friendly message
                throw new NotFoundException("BVS data is unavailable.  This may be because the PIN is no longer active.");
            }
            catch
            {
                throw new NotFoundException("Unable to look up the Revenue Object.  This may be the result of an inactive record.");
            }

            var legalPartyRoleDtos = await _httpClientWrapper.Get <IList <LegalPartyRoleDto> >(_applicationSettingsHelper.LegalPartyServiceApiUrl,
                                                                                               $"{Version}/LegalParties/LegalPartyRoles/RevenueObjectId/{assessmentEventDto.RevObjId}/EffectiveDate/{assessmentEventDto.EventDate:O}");

            AssessmentRevisionDto assessmentRevisionDto = null;

            if (assessmentEventTran != null)
            {
                assessmentRevisionDto = await _httpClientWrapper.Get <AssessmentRevisionDto>(_applicationSettingsHelper.AssessmentEventServiceApiUrl,
                                                                                             $"{Version}/AssessmentEvents/AssessmentRevisionEventId/{assessmentEventTran.AsmtRevnEventId}/AssessmentEventDate/{assessmentEventDto.EventDate:yyyy-MM-dd}/AssessmentRevision");
            }

            var tagDto = await _httpClientWrapper.Get <TAGDto>(_applicationSettingsHelper.RevenueObjectServiceApiUrl,
                                                               $"{Version}/revenueobjects/RevenueObjectId/{assessmentEventDto.RevObjId}/EffectiveDate/{assessmentEventDto.EventDate:yyyy-MM-dd}/TAG");

            StatutoryReferenceDto statutoryReferenceDto = null;

            if (assessmentEventTran != null)
            {
                statutoryReferenceDto = await _httpClientWrapper.Get <StatutoryReferenceDto>(_applicationSettingsHelper.AssessmentEventServiceApiUrl,
                                                                                             $"{Version}/StatutoryReference/{assessmentEventTran.Id}");
            }

            if (statutoryReferenceDto != null)
            {
                assessmentHeader.AssessmentEvent.RevenueAndTaxCode = statutoryReferenceDto.Description;
            }

            if (revenueObjectDto != null)
            {
                assessmentHeader.RevenueObject = new RevenueObject
                {
                    Id = revenueObjectDto.Id,
                    BeginEffectiveDate = revenueObjectDto.BeginEffectiveDate,
                    EffectiveStatus    = revenueObjectDto.EffectiveStatus,
                    Pin              = revenueObjectDto.Pin,
                    UnformattedPin   = revenueObjectDto.UnformattedPin,
                    Ain              = revenueObjectDto.Ain,
                    GeoCd            = revenueObjectDto.GeoCd,
                    ClassCd          = revenueObjectDto.ClassCd,
                    AreaCd           = revenueObjectDto.AreaCd,
                    CountyCd         = revenueObjectDto.CountyCd,
                    CensusTrack      = revenueObjectDto.CensusTrack,
                    CensusBlock      = revenueObjectDto.CensusBlock,
                    XCoordinate      = revenueObjectDto.XCoordinate,
                    YCoordinate      = revenueObjectDto.YCoordinate,
                    ZCoordinate      = revenueObjectDto.ZCoordinate,
                    RightEstate      = revenueObjectDto.RightEstate,
                    RightType        = revenueObjectDto.RightType,
                    RightDescription = revenueObjectDto.RightDescription,
                    Type             = revenueObjectDto.Type,
                    SubType          = revenueObjectDto.SubType,
                    TAG              = tagDto.Description,
                    SitusAddress     = revenueObjectDto.SitusAddress != null
                                                            ? new SitusAddress
                    {
                        FreeFormAddress = revenueObjectDto.SitusAddress.FreeFormAddress,
                        City            = revenueObjectDto.SitusAddress.City,
                        StateCode       = revenueObjectDto.SitusAddress.StateCode,
                        PostalCode      = revenueObjectDto.SitusAddress.PostalCode
                    }
                                                            : null,
                    Description          = revenueObjectDto.Description,
                    PropertyType         = revenueObjectDto.PropertyType,
                    RelatedPins          = revenueObjectDto.RelatedPins,
                    ClassCodeDescription = revenueObjectDto.ClassCodeDescription,
                    //TODO Remove hard coding of TotalBaseValue once true source is determined
                    TotalBaseValue = 345000m
                };
            }
            if (legalPartyRoleDtos != null && legalPartyRoleDtos.Count > 0)
            {
                var primeLegalPartyRole = GetPrimeLegalPartyRole(legalPartyRoleDtos);
                if (primeLegalPartyRole != null)
                {
                    var primeLegalParty = primeLegalPartyRole.LegalParty;
                    assessmentHeader.LegalParty = new LegalParty
                    {
                        LegalPartyId             = primeLegalParty.Id,
                        DisplayName              = primeLegalParty.DisplayName,
                        FirstName                = primeLegalParty.FirstName,
                        MiddleName               = primeLegalParty.MiddleName,
                        LastName                 = primeLegalParty.LastName,
                        NameSfx                  = primeLegalParty.NameSfx,
                        RevenueAcct              = primeLegalPartyRole.AcctId,
                        LegalPartyRoleObjectType = primeLegalPartyRole.ObjectType
                    };
                }
            }

            if (assessmentRevisionDto != null)
            {
                assessmentHeader.AssessmentEvent.RevisionId      = assessmentRevisionDto.Id;
                assessmentHeader.AssessmentEvent.ReferenceNumber = assessmentRevisionDto.ReferenceNumber;
                assessmentHeader.AssessmentEvent.ChangeReason    = assessmentRevisionDto.ChangeReason;
                assessmentHeader.AssessmentEvent.Note            = assessmentRevisionDto.Note;
            }

            return(assessmentHeader);
        }