예제 #1
0
        public void MapChangeOfChargesMessageToCharge_WhenMessageWithProperties_ThenReturnsChargeWithPropertiesSet()
        {
            // Arrange
            var changeOfChargesMessage = GetValidChangeOfChargesMessage();

            changeOfChargesMessage !.MktActivityRecord !.ValidityEndDate = Instant.MaxValue;
            var chargeType = new ChargeType {
                Code = changeOfChargesMessage.Type, Id = 1, Name = "Name"
            };
            var chargeTypeOwnerMRid = new MarketParticipant {
                Id = 1, MRid = changeOfChargesMessage.ChargeTypeOwnerMRid
            };
            var resolutionType = new ResolutionType {
                Id = 1, Name = changeOfChargesMessage.Period?.Resolution
            };
            var vatPayerType = new VatPayerType {
                Id = 1, Name = changeOfChargesMessage.MktActivityRecord?.ChargeType?.VatPayer
            };

            // When
            var result = ChangeOfChargesMapper.MapChangeOfChargesTransactionToCharge(changeOfChargesMessage, chargeType, chargeTypeOwnerMRid, resolutionType, vatPayerType);

            var properties = result.GetType().GetProperties();

            foreach (var property in properties)
            {
                var value = property.GetValue(result);
                Assert.NotNull(value);
            }
        }
예제 #2
0
        public static Charge MapChangeOfChargesTransactionToCharge(
            [NotNull] ChangeOfChargesTransaction changeOfChargeTransaction,
            ChargeType chargeType,
            MarketParticipant chargeTypeOwnerMRid,
            ResolutionType resolutionType,
            VatPayerType vatPayerType)
        {
            if (changeOfChargeTransaction == null)
            {
                throw new ArgumentNullException(nameof(changeOfChargeTransaction));
            }
            if (string.IsNullOrWhiteSpace(changeOfChargeTransaction.ChargeTypeMRid))
            {
                throw new ArgumentException($"{nameof(changeOfChargeTransaction.ChargeTypeMRid)} must have value");
            }
            if (string.IsNullOrWhiteSpace(changeOfChargeTransaction.CorrelationId))
            {
                throw new ArgumentException($"{nameof(changeOfChargeTransaction.CorrelationId)} must have value");
            }
            if (string.IsNullOrWhiteSpace(changeOfChargeTransaction.LastUpdatedBy))
            {
                throw new ArgumentException($"{nameof(changeOfChargeTransaction.LastUpdatedBy)} must have value");
            }
            if (changeOfChargeTransaction.MktActivityRecord?.ChargeType == null)
            {
                throw new ArgumentException($"{nameof(changeOfChargeTransaction.MktActivityRecord.ChargeType)} can't be null");
            }
            if (string.IsNullOrWhiteSpace(changeOfChargeTransaction.MktActivityRecord.ChargeType.Name))
            {
                throw new ArgumentException($"{nameof(changeOfChargeTransaction.MktActivityRecord.ChargeType.Name)} must have value");
            }
            if (string.IsNullOrWhiteSpace(changeOfChargeTransaction.MktActivityRecord.ChargeType.Description))
            {
                throw new ArgumentException($"{nameof(changeOfChargeTransaction.MktActivityRecord.ChargeType.Description)} must have value");
            }
            if (changeOfChargeTransaction.Period == null)
            {
                throw new ArgumentException($"{nameof(changeOfChargeTransaction.Period)} can't be null");
            }
            if (changeOfChargeTransaction.Period.Points == null)
            {
                throw new ArgumentException($"{nameof(changeOfChargeTransaction.Period.Points)} can't be null");
            }

            var charge = new Charge
            {
                ChargeType                 = chargeType,
                ChargeTypeOwner            = chargeTypeOwnerMRid,
                Description                = changeOfChargeTransaction.MktActivityRecord.ChargeType.Description,
                LastUpdatedBy              = changeOfChargeTransaction.LastUpdatedBy,
                LastUpdatedByCorrelationId = changeOfChargeTransaction.CorrelationId,
                LastUpdatedByTransactionId = changeOfChargeTransaction.MRid,
                Name                 = changeOfChargeTransaction.MktActivityRecord.ChargeType.Name,
                RequestDateTime      = changeOfChargeTransaction.RequestDate.ToUnixTimeTicks(),
                ResolutionType       = resolutionType,
                StartDate            = changeOfChargeTransaction.MktActivityRecord.ValidityStartDate.ToUnixTimeTicks(),
                EndDate              = changeOfChargeTransaction.MktActivityRecord.ValidityEndDate?.ToUnixTimeTicks(),
                Status               = (int)changeOfChargeTransaction.MktActivityRecord.Status,
                TaxIndicator         = changeOfChargeTransaction.MktActivityRecord.ChargeType.TaxIndicator,
                TransparentInvoicing = changeOfChargeTransaction.MktActivityRecord.ChargeType.TransparentInvoicing,
                VatPayer             = vatPayerType,
                MRid                 = changeOfChargeTransaction.ChargeTypeMRid,
                Currency             = "DKK",
            };

            foreach (var point in changeOfChargeTransaction.Period.Points)
            {
                var newChargePrice = new ChargePrice
                {
                    Time   = point.Time.ToUnixTimeTicks(),
                    Amount = point.PriceAmount,
                    LastUpdatedByCorrelationId = changeOfChargeTransaction.CorrelationId,
                    LastUpdatedByTransactionId = changeOfChargeTransaction.MRid,
                    LastUpdatedBy   = changeOfChargeTransaction.LastUpdatedBy,
                    RequestDateTime = changeOfChargeTransaction.RequestDate.ToUnixTimeTicks(),
                };

                charge.ChargePrices.Add(newChargePrice);
            }

            return(charge);
        }