public void Write_WithOneCustomer_GeneratesCorrectOutput()
        {
            // Arrange
            Address address = new Address("1 High Street", "Flat 123", "Business Park", "Newtown", "Nr Oldtown", "Testshire", "AA1 1AA");
            Customer customer = new Customer("WEE0001", "Test customer", address);

            CustomerFile file = new CustomerFile("WEE", 0);

            file.AddCustomer(customer);

            // Act
            string result = file.Write();

            // Assert
            string expectedDate = DateTime.UtcNow.Date.ToString("dd-MMM-yyyy").ToUpperInvariant();
            string expectedOutput =
                "\"H\",\"0000000\",\"WEE\",\"H\",\"C\",\"00000\",\"" + expectedDate + "\"" + Environment.NewLine +
                "\"D\",\"0000001\",\"WEE0001\",\"Test customer\",\"1 High Street\",\"Flat 123\",\"Business Park\",\"Newtown\",\"Nr Oldtown\",\"Testshire\",\"AA1 1AA\"" + Environment.NewLine +
                "\"T\",\"0000002\",\"0000003\"" + Environment.NewLine;

            Assert.Equal(expectedOutput, result);
        }
Example #2
0
        public void Write_WithOneCustomer_GeneratesCorrectOutput()
        {
            // Arrange
            Address  address  = new Address("1 High Street", "Flat 123", "Business Park", "Newtown", "Nr Oldtown", "Testshire", "AA1 1AA");
            Customer customer = new Customer("WEE0001", "Test customer", address);

            CustomerFile file = new CustomerFile("WEE", 0);

            file.AddCustomer(customer);

            // Act
            string result = file.Write();

            // Assert
            string expectedDate   = DateTime.UtcNow.Date.ToString("dd-MMM-yyyy").ToUpperInvariant();
            string expectedOutput =
                "\"H\",\"0000000\",\"WEE\",\"H\",\"C\",\"00000\",\"" + expectedDate + "\"" + Environment.NewLine +
                "\"D\",\"0000001\",\"WEE0001\",\"Test customer\",\"1 High Street\",\"Flat 123\",\"Business Park\",\"Newtown\",\"Nr Oldtown\",\"Testshire\",\"AA1 1AA\"" + Environment.NewLine +
                "\"T\",\"0000002\",\"0000003\"" + Environment.NewLine;

            Assert.Equal(expectedOutput, result);
        }
Example #3
0
        /// <summary>
        /// Creates the data representing 1B1S customer and transaction files for the specified list
        /// of member uploads.
        /// </summary>
        /// <param name="fileID">The ID that the 1B1S files will use. This must be unique for every pair of 1B1S files
        /// and must be in the range of 0 to 99999. To avoid clashes with IDs used by the incumbent system, a seed
        /// value may need to be used.</param>
        /// <param name="invoiceRun">The invoice run specifying the list of member uploads to be included.</param>
        /// <returns>Returns an <see cref="IbisFileDataGeneratorResult"/> which provides the data and file names of the
        /// generated 1B1S customer and transaction files or a list of error which occurred during the process.</returns>
        public async Task <IbisFileDataGeneratorResult> CreateFileDataAsync(ulong fileID, InvoiceRun invoiceRun)
        {
            var customerFileGeneratorResult = await ibisCustomerFileGenerator.CreateAsync(fileID, invoiceRun);

            var ibisTransactionFileGeneratorResult = await ibisTransactionFileGenerator.CreateAsync(fileID, invoiceRun);

            IbisFileData ibisFileData = null;
            var          errors       = new List <string>();

            if (customerFileGeneratorResult.Errors.Count == 0 &&
                ibisTransactionFileGeneratorResult.Errors.Count == 0)
            {
                CustomerFile    customerFile    = customerFileGeneratorResult.IbisFile;
                TransactionFile transactionFile = ibisTransactionFileGeneratorResult.IbisFile;

                string customerFileName    = string.Format("WEEHC{0:D5}.dat", fileID);
                string transactionFileName = string.Format("WEEHI{0:D5}.dat", fileID);

                string customerFileData    = customerFile.Write();
                string transactionFileData = transactionFile.Write();

                ibisFileData = new IbisFileData(
                    fileID,
                    customerFileName,
                    customerFileData,
                    transactionFileName,
                    transactionFileData);
            }
            else
            {
                errors = ibisFileDataErrorTranslator
                         .MakeFriendlyErrorMessages(customerFileGeneratorResult
                                                    .Errors
                                                    .Union(ibisTransactionFileGeneratorResult.Errors)
                                                    .ToList());
            }

            return(new IbisFileDataGeneratorResult(ibisFileData, errors));
        }