Exemplo n.º 1
0
        public void UpdateOrderFeeValidationTests()
        {
            _webContainerFixture.ExecuteScope(serviceProvider =>
            {
                var actionStepService             = new TestActionstepService();
                var mediator                      = serviceProvider.GetService <IMediator>();
                var dbContext                     = serviceProvider.GetService <WCADbContext>();
                var telemetryLogger               = serviceProvider.GetService <ITelemetryLogger>();
                var mapper                        = serviceProvider.GetService <IMapper>();
                var infoTrackCredentialRepository = new TestInfoTrackCredentialRepository();
                var loggerFactory                 = serviceProvider.GetService <ILoggerFactory>();
                var appSettings                   = serviceProvider.GetService <IOptions <WCACoreSettings> >();
                var tokenSetRepository            = serviceProvider.GetService <ITokenSetRepository>();

                var handler = new UpdateOrder.Handler(
                    actionStepService,
                    mediator,
                    dbContext,
                    mapper,
                    telemetryLogger,
                    infoTrackCredentialRepository,
                    loggerFactory,
                    appSettings,
                    tokenSetRepository);

                var updateMessage = new InfoTrackOrderUpdateMessage
                {
                    InfoTrackRetailerFee      = 1.0m,
                    InfoTrackRetailerFeeGST   = 1.0m,
                    InfoTrackRetailerFeeTotal = 2.0m,
                    InfoTrackSupplierFee      = 1.5m,
                    InfoTrackSupplierFeeGST   = 1.0m,
                    InfoTrackSupplierFeeTotal = 2.5m,
                    InfoTrackTotalFee         = 2.5m,
                    InfoTrackTotalFeeGST      = 2.0m,
                    InfoTrackTotalFeeTotal    = 4.5m
                };

                var handleMethod = handler.GetType().GetMethod("ValidateFees", BindingFlags.NonPublic | BindingFlags.Instance);

                // Initial data valid
                Assert.True(InvokeFeeValidation(handleMethod, handler, updateMessage));

                updateMessage.InfoTrackRetailerFeeTotal = 2.1m;
                Assert.False(InvokeFeeValidation(handleMethod, handler, updateMessage));

                updateMessage.InfoTrackRetailerFeeTotal = 2.0m;
                updateMessage.InfoTrackSupplierFeeTotal = 2.4m;
                Assert.False(InvokeFeeValidation(handleMethod, handler, updateMessage));

                updateMessage.InfoTrackSupplierFeeTotal = 2.5m;
                updateMessage.InfoTrackTotalFeeTotal    = 4.6m;
                Assert.False(InvokeFeeValidation(handleMethod, handler, updateMessage));

                // Reverted all values, should be valid again
                updateMessage.InfoTrackTotalFeeTotal = 4.5m;
                Assert.True(InvokeFeeValidation(handleMethod, handler, updateMessage));
            });
        }
Exemplo n.º 2
0
            private static dynamic PrepareSplitDisbursements(InfoTrackOrderUpdateMessage message, int matterId, int?gstTaxCodeId, int?nonGstTaxCodeId)
            {
                var    disbursements             = new List <dynamic>();
                string cleanInfoTrackDescription = GetCleanInfoTrackDescription(message);

                if (message.InfoTrackSupplierFeeTotal != 0)
                {
                    disbursements.Add(
                        new
                    {
                        description          = $"InfoTrack order {message.InfoTrackOrderId}{cleanInfoTrackDescription} (supplier fee)",
                        quantity             = 1,
                        unitPrice            = message.InfoTrackSupplierFeeTotal,
                        unitPriceIncludesTax = message.InfoTrackSupplierFeeGST != 0 ? "T" : "F",
                        links = new
                        {
                            action  = matterId,
                            taxCode = message.InfoTrackSupplierFeeGST != 0 ? gstTaxCodeId : nonGstTaxCodeId
                        }
                    });
                }

                if (message.InfoTrackRetailerFeeTotal != 0)
                {
                    disbursements.Add(
                        new
                    {
                        description          = $"InfoTrack order {message.InfoTrackOrderId}{cleanInfoTrackDescription} (retailer fee)",
                        quantity             = 1,
                        unitPrice            = message.InfoTrackRetailerFeeTotal,
                        unitPriceIncludesTax = message.InfoTrackRetailerFeeGST != 0 ? "T" : "F",
                        links = new
                        {
                            action  = matterId,
                            taxCode = message.InfoTrackRetailerFeeGST != 0 ? gstTaxCodeId : nonGstTaxCodeId
                        }
                    });
                }

                if (disbursements.Count < 1)
                {
                    return(null);
                }

                return(new
                {
                    disbursements = disbursements.ToArray()
                });
            }
Exemplo n.º 3
0
            /// <summary>
            /// Helper to clean up the InfoTrack description. Because we prepend this with our own descriptor,
            /// this avoids "InfoTrack" appearing twice as sometimes the description contains "InfoTrack" in it as well.
            /// </summary>
            /// <param name="message"></param>
            /// <returns></returns>
            private static string GetCleanInfoTrackDescription(InfoTrackOrderUpdateMessage message)
            {
                var cleanInfoTrackDescription = message.InfoTrackDescription?.Trim() ?? string.Empty;
                var stripPrefix = "InfoTrack: ";

                if (cleanInfoTrackDescription.StartsWith(stripPrefix, StringComparison.InvariantCulture))
                {
                    cleanInfoTrackDescription = cleanInfoTrackDescription.Substring(stripPrefix.Length);
                }

                if (cleanInfoTrackDescription.Length > 0)
                {
                    cleanInfoTrackDescription = ": " + cleanInfoTrackDescription;
                }

                return(cleanInfoTrackDescription);
            }
Exemplo n.º 4
0
            private void ValidateFees(InfoTrackOrderUpdateMessage infoTrack)
            {
                var errors = new List <string>();

                if (infoTrack.InfoTrackRetailerFee + infoTrack.InfoTrackRetailerFeeGST != infoTrack.InfoTrackRetailerFeeTotal)
                {
                    errors.Add($"Retailer Fee ({infoTrack.InfoTrackRetailerFee}) "
                               + $" + Retailer Fee GST ({infoTrack.InfoTrackRetailerFeeGST}) "
                               + $"is not equal to Retailer Fee Total ({infoTrack.InfoTrackRetailerFeeTotal})");
                }

                if (infoTrack.InfoTrackSupplierFee + infoTrack.InfoTrackSupplierFeeGST != infoTrack.InfoTrackSupplierFeeTotal)
                {
                    errors.Add($"Supplier Fee ({infoTrack.InfoTrackSupplierFee}) "
                               + $" + Supplier Fee GST ({infoTrack.InfoTrackSupplierFeeGST}) "
                               + $"is not equal to Supplier Fee Total ({infoTrack.InfoTrackSupplierFeeTotal})");
                }

                if (infoTrack.InfoTrackTotalFee + infoTrack.InfoTrackTotalFeeGST != infoTrack.InfoTrackTotalFeeTotal)
                {
                    errors.Add($"Total Fee ({infoTrack.InfoTrackTotalFee}) "
                               + $" + Total Fee GST ({infoTrack.InfoTrackTotalFeeGST}) "
                               + $"is not equal to Total Fee Total ({infoTrack.InfoTrackTotalFeeTotal})");
                }

                if (infoTrack.InfoTrackRetailerFeeTotal + infoTrack.InfoTrackSupplierFeeTotal != infoTrack.InfoTrackTotalFeeTotal)
                {
                    errors.Add($"Retailer Fee Total ({infoTrack.InfoTrackRetailerFeeTotal}) "
                               + $" + Supplier Fee Total ({infoTrack.InfoTrackSupplierFeeTotal}) "
                               + $"is not equal to Total Fee Total ({infoTrack.InfoTrackTotalFeeTotal})");
                }

                if (errors.Count > 0)
                {
                    var message = new StringBuilder();
                    message.Append($"There was a problem validating the fees for InfoTrack Order ID {infoTrack.InfoTrackOrderId} <br/>");
                    errors.ForEach(e => message.Append(e + "<br/>"));

                    var ex = new ApplicationException("A problem was encountered validating the InfoTrack fees");
                    ex.Data.Add("message", message.ToString());
                    ex.Data.Add("contentType", "text/html");
                    throw ex;
                }
            }
Exemplo n.º 5
0
 private static dynamic PrepareSingleDisbursement(InfoTrackOrderUpdateMessage message, int matterId, int?gstTaxCodeId, int?nonGstTaxCodeId)
 {
     return(new
     {
         disbursements = new dynamic[] {
             new
             {
                 description = $"InfoTrack order {message.InfoTrackOrderId}{GetCleanInfoTrackDescription(message)}",
                 quantity = 1,
                 unitPrice = message.InfoTrackTotalFeeTotal,
                 unitPriceIncludesTax = message.InfoTrackTotalFeeGST != 0 ? "T" : "F",
                 links = new
                 {
                     action = matterId,
                     taxCode = message.InfoTrackTotalFeeGST != 0 ? gstTaxCodeId : nonGstTaxCodeId
                 }
             }
         }
     });
 }
Exemplo n.º 6
0
        private Boolean InvokeFeeValidation(MethodInfo methodInfo, UpdateOrder.Handler handler, InfoTrackOrderUpdateMessage message)
        {
            try
            {
                methodInfo.Invoke(handler, new object[] { message });
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                return(false);
            }

            return(true);
        }