public async Task CreateCustomerFile_WithFileID_CreatesFileWithCorrectFileID()
        {
            // Arrange
            var authority = A.Dummy <UKCompetentAuthority>();

            var address = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                "Post code",
                new Country(Guid.NewGuid(), "UK - England"),
                "01234 567890",
                "*****@*****.**");

            var contact = new Contact("John", "Smith", "Manager");

            var organisation = Organisation.CreateSoleTrader("Test organisation");
            var scheme       = new Scheme(organisation);

            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy <ObligationType>(),
                authority);

            scheme.AddOrUpdateMainContactPerson(contact);
            scheme.AddOrUpdateAddress(address);

            var complianceYear = A.Dummy <int>();

            var memberUpload = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                A.Dummy <decimal>(),
                complianceYear,
                scheme,
                A.Dummy <string>());

            memberUpload.Submit(A.Dummy <User>());

            var memberUploads = new List <MemberUpload> {
                memberUpload
            };

            var invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy <User>());

            var   generator = new BySchemeCustomerFileGenerator();
            ulong id        = 12345;

            // Act
            var result = await generator.CreateAsync(id, invoiceRun);

            var customerFile = result.IbisFile;

            // Assert
            Assert.Equal((ulong)12345, customerFile.FileID);
        }
        public async Task CreateCustomerFile_WithFileID_CreatesFileWithCorrectFileID()
        {
            // Arrange
            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            Address address = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                "Post code",
                new Country(Guid.NewGuid(), "UK - England"),
                "01234 567890",
                "*****@*****.**");

            Contact contact = new Contact("John", "Smith", "Manager");

            Organisation organisation = Organisation.CreateSoleTrader("Test organisation");
            organisation.AddOrUpdateAddress(AddressType.OrganisationAddress, address);
            organisation.AddOrUpdateMainContactPerson(contact);

            Scheme scheme = new Scheme(organisation);
            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear = A.Dummy<int>();

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear,
                scheme,
                A.Dummy<string>());

            memberUpload.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());

            BySchemeCustomerFileGenerator generator = new BySchemeCustomerFileGenerator();
            ulong id = 12345;

            // Act
            var result = await generator.CreateAsync(id, invoiceRun);
            CustomerFile customerFile = result.IbisFile;

            // Assert
            Assert.Equal((ulong)12345, customerFile.FileID);
        }
        public async Task CreateCustomerFile_WithExceptionThrown_ReturnsError_AndNoCustomerFile()
        {
            // Arrange
            var authority = A.Dummy <UKCompetentAuthority>();

            var organisation = Organisation.CreateSoleTrader("Test organisation");

            var scheme = new Scheme(organisation);

            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy <ObligationType>(),
                authority);

            var complianceYear = A.Dummy <int>();

            var memberUpload = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                A.Dummy <decimal>(),
                complianceYear,
                scheme,
                A.Dummy <string>(),
                A.Dummy <string>(),
                false);

            memberUpload.Submit(A.Dummy <User>());

            var memberUploads = new List <MemberUpload> {
                memberUpload
            };

            var invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy <User>());

            var generator = new BySchemeCustomerFileGenerator();

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);

            // Assert
            Assert.Null(result.IbisFile);
            Assert.NotEmpty(result.Errors);
        }
        public void GetIbisPostCode_WithNonUkAddress_ConcatenatesPostCodeAndCountry(string postCode, string countryName, string expectedResult)
        {
            var address = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                postCode,
                new Country(Guid.NewGuid(), countryName),
                "01234 567890",
                "*****@*****.**");

            var generator = new BySchemeCustomerFileGenerator();

            // Act
            var result = generator.GetIbisPostCode(address);

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public async Task CreateCustomerFile_WithOneMemberUpload_CreatesOneCustomer()
        {
            // Arrange
            var authority = A.Dummy <UKCompetentAuthority>();

            var address = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                "Post code",
                new Country(Guid.NewGuid(), "UK - England"),
                "01234 567890",
                "*****@*****.**");

            var contact = new Contact("John", "Smith", "Manager");

            var organisation = Organisation.CreateSoleTrader("Test organisation");

            var scheme = new Scheme(organisation);

            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy <ObligationType>(),
                authority);
            scheme.AddOrUpdateAddress(address);
            scheme.AddOrUpdateMainContactPerson(contact);

            var complianceYear = A.Dummy <int>();

            var memberUpload = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                A.Dummy <decimal>(),
                complianceYear,
                scheme,
                A.Dummy <string>(),
                A.Dummy <string>(),
                false);

            memberUpload.Submit(A.Dummy <User>());

            var memberUploads = new List <MemberUpload> {
                memberUpload
            };

            var invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy <User>());

            var generator = new BySchemeCustomerFileGenerator();

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);

            var customerFile = result.IbisFile;

            // Assert
            Assert.NotNull(customerFile);
            Assert.Equal(1, customerFile.Customers.Count);

            var customer = customerFile.Customers[0];

            Assert.NotNull(customer);
            Assert.Equal("WEE00000001", customer.CustomerReference);
            Assert.Equal("Test organisation", customer.Name);

            Assert.NotNull(customer.Address);
            Assert.Equal("John Smith", customer.Address.AddressLine1);
            Assert.Equal("1 High Street", customer.Address.AddressLine2);
            Assert.Equal(null, customer.Address.AddressLine3);
            Assert.Equal(null, customer.Address.AddressLine4);
            Assert.Equal("Some town", customer.Address.AddressLine5);
            Assert.Equal("Some county", customer.Address.AddressLine6);
            Assert.Equal("Post code", customer.Address.PostCode);
        }
        public async Task CreateCustomerFile_WithTwoMemberUploadsForDifferentSchemes_CreatesTwoCustomers()
        {
            // Arrange
            var authority = A.Dummy <UKCompetentAuthority>();

            var address1 = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                "Post code",
                new Country(Guid.NewGuid(), "UK - England"),
                "01234 567890",
                "*****@*****.**");

            var organisation1 = Organisation.CreateSoleTrader("Test organisation 1");

            var scheme1 = new Scheme(organisation1);

            scheme1.UpdateScheme(
                "Test scheme 2",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy <ObligationType>(),
                authority);
            scheme1.AddOrUpdateMainContactPerson(A.Fake <Contact>());
            scheme1.AddOrUpdateAddress(address1);

            var complianceYear1 = A.Dummy <int>();

            var memberUpload1 = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                A.Dummy <decimal>(),
                complianceYear1,
                scheme1,
                A.Dummy <string>(),
                A.Dummy <string>(),
                false);

            memberUpload1.Submit(A.Dummy <User>());

            var address2 = new Address(
                "2 High Street",
                null,
                "Some town",
                "Some county",
                "Post code",
                new Country(Guid.NewGuid(), "UK - England"),
                "01234 567890",
                "*****@*****.**");

            var organisation2 = Organisation.CreateSoleTrader("Test organisation 2");

            var scheme2 = new Scheme(organisation2);

            scheme2.UpdateScheme(
                "Test scheme 2",
                "WEE/BB2222BB/SCH",
                "WEE00000002",
                A.Dummy <ObligationType>(),
                authority);
            scheme2.AddOrUpdateAddress(address2);
            scheme2.AddOrUpdateMainContactPerson(A.Fake <Contact>());

            var complianceYear2 = A.Dummy <int>();

            var memberUpload2 = new MemberUpload(
                A.Dummy <Guid>(),
                A.Dummy <string>(),
                A.Dummy <List <MemberUploadError> >(),
                A.Dummy <decimal>(),
                complianceYear2,
                scheme2,
                A.Dummy <string>(),
                A.Dummy <string>(),
                false);

            memberUpload2.Submit(A.Dummy <User>());

            var memberUploads = new List <MemberUpload> {
                memberUpload1, memberUpload2
            };

            var invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy <User>());

            var generator = new BySchemeCustomerFileGenerator();

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);

            var customerFile = result.IbisFile;

            // Assert
            Assert.NotNull(customerFile);
            Assert.Equal(2, customerFile.Customers.Count);

            var customer1 = customerFile.Customers[0];

            Assert.NotNull(customer1);
            Assert.Equal("WEE00000001", customer1.CustomerReference);

            var customer2 = customerFile.Customers[1];

            Assert.NotNull(customer2);
            Assert.Equal("WEE00000002", customer2.CustomerReference);
        }
        public void GetIbisPostCode_WithNonUkAddress_ConcatenatesPostCodeAndCountry(string postCode, string countryName, string expectedResult)
        {
            Address address = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                postCode,
                new Country(Guid.NewGuid(), countryName),
                "01234 567890",
                "*****@*****.**");

            BySchemeCustomerFileGenerator generator = new BySchemeCustomerFileGenerator();

            // Act
            var result = generator.GetIbisPostCode(address);

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public async Task CreateCustomerFile_WithNonUkAddress_ConcatenatesPostCodeAndCountry()
        {
            // Arrange
            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            Address address = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                "AABB",
                new Country(Guid.NewGuid(), "Netherlands"),
                "01234 567890",
                "*****@*****.**");

            Contact contact = new Contact("John", "Smith", "Manager");

            Organisation organisation = Organisation.CreateSoleTrader("Test organisation");
            organisation.AddOrUpdateAddress(AddressType.OrganisationAddress, address);
            organisation.AddOrUpdateMainContactPerson(contact);

            Scheme scheme = new Scheme(organisation);
            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear = A.Dummy<int>();

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear,
                scheme,
                A.Dummy<string>());

            memberUpload.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());

            BySchemeCustomerFileGenerator generator = new BySchemeCustomerFileGenerator();

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);
            CustomerFile customerFile = result.IbisFile;

            // Assert
            Assert.NotNull(customerFile);
            Assert.Equal(1, customerFile.Customers.Count);

            Customer customer = customerFile.Customers[0];
            Assert.Equal("AABB  Netherlands", customer.Address.PostCode);
        }
        public async Task CreateCustomerFile_WithExceptionThrown_ReturnsError_AndNoCustomerFile()
        {
            // Arrange
            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            Address address = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                null, // A null value will cause the Ibis class to throw an exception.
                new Country(Guid.NewGuid(), "UK - England"),
                "01234 567890",
                "*****@*****.**");

            Contact contact = new Contact("John", "Smith", "Manager");

            Organisation organisation = Organisation.CreateSoleTrader("Test organisation");
            organisation.AddOrUpdateAddress(AddressType.OrganisationAddress, address);
            organisation.AddOrUpdateMainContactPerson(contact);

            Scheme scheme = new Scheme(organisation);
            scheme.UpdateScheme(
                "Test scheme",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear = A.Dummy<int>();

            MemberUpload memberUpload = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear,
                scheme,
                A.Dummy<string>());

            memberUpload.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());

            BySchemeCustomerFileGenerator generator = new BySchemeCustomerFileGenerator();

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);

            // Assert
            Assert.Null(result.IbisFile);
            Assert.NotEmpty(result.Errors);
        }
        public async Task CreateCustomerFile_WithTwoMemberUploadsForDifferentSchemes_CreatesTwoCustomers()
        {
            // Arrange
            UKCompetentAuthority authority = A.Dummy<UKCompetentAuthority>();

            Address address1 = new Address(
                "1 High Street",
                null,
                "Some town",
                "Some county",
                "Post code",
                new Country(Guid.NewGuid(), "UK - England"),
                "01234 567890",
                "*****@*****.**");

            Organisation organisation1 = Organisation.CreateSoleTrader("Test organisation 1");
            organisation1.AddOrUpdateAddress(AddressType.OrganisationAddress, address1);
            organisation1.AddOrUpdateMainContactPerson(A.Dummy<Contact>());

            Scheme scheme1 = new Scheme(organisation1);
            scheme1.UpdateScheme(
                "Test scheme 2",
                "WEE/AA1111AA/SCH",
                "WEE00000001",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear1 = A.Dummy<int>();

            MemberUpload memberUpload1 = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear1,
                scheme1,
                A.Dummy<string>());

            memberUpload1.Submit(A.Dummy<User>());

            Address address2 = new Address(
                "2 High Street",
                null,
                "Some town",
                "Some county",
                "Post code",
                new Country(Guid.NewGuid(), "UK - England"),
                "01234 567890",
                "*****@*****.**");

            Organisation organisation2 = Organisation.CreateSoleTrader("Test organisation 2");
            organisation2.AddOrUpdateAddress(AddressType.OrganisationAddress, address2);
            organisation2.AddOrUpdateMainContactPerson(A.Dummy<Contact>());

            Scheme scheme2 = new Scheme(organisation2);
            scheme2.UpdateScheme(
                "Test scheme 2",
                "WEE/BB2222BB/SCH",
                "WEE00000002",
                A.Dummy<ObligationType>(),
                authority);

            int complianceYear2 = A.Dummy<int>();

            MemberUpload memberUpload2 = new MemberUpload(
                A.Dummy<Guid>(),
                A.Dummy<string>(),
                A.Dummy<List<MemberUploadError>>(),
                A.Dummy<decimal>(),
                complianceYear2,
                scheme2,
                A.Dummy<string>());

            memberUpload2.Submit(A.Dummy<User>());

            List<MemberUpload> memberUploads = new List<MemberUpload>();
            memberUploads.Add(memberUpload1);
            memberUploads.Add(memberUpload2);

            InvoiceRun invoiceRun = new InvoiceRun(authority, memberUploads, A.Dummy<User>());

            BySchemeCustomerFileGenerator generator = new BySchemeCustomerFileGenerator();

            // Act
            var result = await generator.CreateAsync(0, invoiceRun);
            CustomerFile customerFile = result.IbisFile;

            // Assert
            Assert.NotNull(customerFile);
            Assert.Equal(2, customerFile.Customers.Count);

            Customer customer1 = customerFile.Customers[0];
            Assert.NotNull(customer1);
            Assert.Equal("WEE00000001", customer1.CustomerReference);

            Customer customer2 = customerFile.Customers[1];
            Assert.NotNull(customer2);
            Assert.Equal("WEE00000002", customer2.CustomerReference);
        }