public async Task CreateFileData_Always_CreatesFileData() { // Arrange CustomerFile customerFile = new CustomerFile("WEE", (ulong)12345); var customerFileGeneratorResult = new IbisFileGeneratorResult <CustomerFile>(customerFile, A.Dummy <List <Exception> >()); IIbisCustomerFileGenerator customerFileGenerator = A.Fake <IIbisCustomerFileGenerator>(); A.CallTo(() => customerFileGenerator.CreateAsync(A <ulong> ._, A <InvoiceRun> ._)) .Returns(customerFileGeneratorResult); TransactionFile transactionFile = new TransactionFile("WEE", (ulong)12345); var ibisFileGeneratorResult = new IbisFileGeneratorResult <TransactionFile>(transactionFile, A.Dummy <List <Exception> >()); IIbisTransactionFileGenerator transactionFileGenerator = A.Fake <IIbisTransactionFileGenerator>(); A.CallTo(() => transactionFileGenerator.CreateAsync(A <ulong> ._, A <InvoiceRun> ._)) .Returns(ibisFileGeneratorResult); IIbisFileDataErrorTranslator errorTranslator = A.Dummy <IIbisFileDataErrorTranslator>(); IbisFileDataGenerator generator = new IbisFileDataGenerator( customerFileGenerator, transactionFileGenerator, errorTranslator); // Act var result = await generator.CreateFileDataAsync(A.Dummy <ulong>(), A.Dummy <InvoiceRun>()); var ibistFileData = result.IbisFileData; // Assert Assert.NotNull(ibistFileData); Assert.False(string.IsNullOrEmpty(ibistFileData.CustomerFileData)); Assert.False(string.IsNullOrEmpty(ibistFileData.TransactionFileData)); }
/// <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)); }
public async Task CreateFileData_WithFileID_CreatesFilesWithCorrectFileNames() { // Arrange ulong fileID = 123; CustomerFile customerFile = new CustomerFile("WEE", (ulong)12345); var customerFileGeneratorResult = new IbisFileGeneratorResult <CustomerFile>(customerFile, A.Dummy <List <Exception> >()); IIbisCustomerFileGenerator customerFileGenerator = A.Fake <IIbisCustomerFileGenerator>(); A.CallTo(() => customerFileGenerator.CreateAsync(A <ulong> ._, A <InvoiceRun> ._)) .Returns(customerFileGeneratorResult); TransactionFile transactionFile = new TransactionFile("WEE", (ulong)12345); var ibisFileGeneratorResult = new IbisFileGeneratorResult <TransactionFile>(transactionFile, A.Dummy <List <Exception> >()); IIbisTransactionFileGenerator transactionFileGenerator = A.Fake <IIbisTransactionFileGenerator>(); A.CallTo(() => transactionFileGenerator.CreateAsync(A <ulong> ._, A <InvoiceRun> ._)) .Returns(ibisFileGeneratorResult); IIbisFileDataErrorTranslator errorTranslator = A.Dummy <IIbisFileDataErrorTranslator>(); IbisFileDataGenerator generator = new IbisFileDataGenerator( customerFileGenerator, transactionFileGenerator, errorTranslator); // Act var result = await generator.CreateFileDataAsync(fileID, A.Dummy <InvoiceRun>()); var ibistFileData = result.IbisFileData; // Assert Assert.NotNull(ibistFileData); Assert.Equal("WEEHC00123.dat", ibistFileData.CustomerFileName); Assert.Equal("WEEHI00123.dat", ibistFileData.TransactionFileName); }