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); }
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)); }
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)); }
public async Task CreateFileData_WithErrorGeneratingIbisFile_TranslatesError_AndReturnNoIbisFileData() { // Arrange ulong fileID = 123; var customerFile = new CustomerFile("WEE", fileID); var customerFileGeneratorResult = new IbisFileGeneratorResult <CustomerFile>(customerFile, A.Dummy <List <Exception> >()); var customerFileGenerator = A.Fake <IIbisCustomerFileGenerator>(); A.CallTo(() => customerFileGenerator.CreateAsync(A <ulong> ._, A <InvoiceRun> ._)) .Returns(customerFileGeneratorResult); var transactionFile = new TransactionFile("WEE", (ulong)12345); var error = new Exception(); var transactionFileGeneratorResult = new IbisFileGeneratorResult <TransactionFile>(transactionFile, new List <Exception> { error }); var transactionFileGenerator = A.Fake <IIbisTransactionFileGenerator>(); A.CallTo(() => transactionFileGenerator.CreateAsync(A <ulong> ._, A <InvoiceRun> ._)) .Returns(transactionFileGeneratorResult); var errorTranslator = A.Fake <IIbisFileDataErrorTranslator>(); A.CallTo(() => errorTranslator.MakeFriendlyErrorMessages(A <List <Exception> > ._)) .Returns(new List <string> { "error" }); IbisFileDataGenerator generator = new IbisFileDataGenerator( customerFileGenerator, transactionFileGenerator, errorTranslator); // Act var result = await generator.CreateFileDataAsync(fileID, A.Dummy <InvoiceRun>()); // Assert Assert.NotEmpty(result.Errors); Assert.Null(result.IbisFileData); }
public Task<IbisFileGeneratorResult<CustomerFile>> CreateAsync(ulong fileID, InvoiceRun invoiceRun) { CustomerFile customerFile = new CustomerFile("WEE", fileID); var errors = new List<Exception>(); IEnumerable<Scheme> schemes = invoiceRun.MemberUploads .Select(mu => mu.Scheme) .Distinct(); foreach (Scheme scheme in schemes) { try { var postCode = GetIbisPostCode(scheme.Organisation.OrganisationAddress); Address address = new Address( scheme.Organisation.Contact.FullName, scheme.Organisation.OrganisationAddress.Address1, scheme.Organisation.OrganisationAddress.Address2, null, scheme.Organisation.OrganisationAddress.TownOrCity, scheme.Organisation.OrganisationAddress.CountyOrRegion, postCode); Customer customer = new Customer( scheme.IbisCustomerReference, scheme.Organisation.OrganisationName, address); customerFile.AddCustomer(customer); } catch (Exception ex) { errors.Add(new SchemeFieldException(scheme, ex)); } } var ibisFileGeneratorResult = new IbisFileGeneratorResult<CustomerFile>(errors.Count == 0 ? customerFile : null, errors); return Task.FromResult(ibisFileGeneratorResult); }
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); }
public async Task CreateFileData_WithErrorGeneratingCustomerFile_TranslatesError() { // Arrange ulong fileID = 123; var customerFile = new CustomerFile("WEE", fileID); var error = new Exception(); var customerFileGeneratorResult = new IbisFileGeneratorResult<CustomerFile>(customerFile, new List<Exception> { error }); var customerFileGenerator = A.Fake<IIbisCustomerFileGenerator>(); A.CallTo(() => customerFileGenerator.CreateAsync(A<ulong>._, A<InvoiceRun>._)) .Returns(customerFileGeneratorResult); var transactionFile = new TransactionFile("WEE", (ulong)12345); var transactionFileGeneratorResult = new IbisFileGeneratorResult<TransactionFile>(transactionFile, A.Dummy<List<Exception>>()); var transactionFileGenerator = A.Fake<IIbisTransactionFileGenerator>(); A.CallTo(() => transactionFileGenerator.CreateAsync(A<ulong>._, A<InvoiceRun>._)) .Returns(transactionFileGeneratorResult); var errorTranslator = A.Fake<IIbisFileDataErrorTranslator>(); IbisFileDataGenerator generator = new IbisFileDataGenerator( customerFileGenerator, transactionFileGenerator, errorTranslator); // Act await generator.CreateFileDataAsync(fileID, A.Dummy<InvoiceRun>()); // Assert A.CallTo(() => errorTranslator.MakeFriendlyErrorMessages(A<List<Exception>>._)) .MustHaveHappened(); }