Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would you consider adding a SortCode for banking data? #77

Closed
cmatskas opened this issue Jun 30, 2017 · 7 comments
Closed

Would you consider adding a SortCode for banking data? #77

cmatskas opened this issue Jun 30, 2017 · 7 comments

Comments

@cmatskas
Copy link

Although you've very well defined a BIC and an IBAN, I was wondering how easy it would be to get an option to add SortCode (6-digits) which are specific to the UK.
If not, is there an easy way to achieve this though the existing, built-in APIs?
Thanks for the great effort and tool btw

@bchavez
Copy link
Owner

bchavez commented Jun 30, 2017

Hi there @cmatskas ,

Thank you for your suggestion. I'm glad you like Bogus 😎. It should be pretty easy to extend Bogus to support ShortCodes. Also, I'd be happy to accept a PR for your feature so others benefit too.

I'm not fimilar with UK ShortCodes but 1) since this is locale specific to the UK and 2) I don't think you would need locale JSON extension storage, you can simply implement your .ShortCode as an extesion method off the Finance data set.

Here is how to do that:

  1. Fork and checkout Bogus.
  2. Run build restore in Command Prompt inside your fresh checkout before using Visual Studio.
  3. Open Visual Studio and create a new file called ExtensionsForUnitedKingdom.cs inside Bogus\Extensions here:

ExtensionsForUnitedKingdom.cs:

namespace Bogus.Extensions.UnitedKingdom
{
   public static class ExtensionsForUnitedKingdom
   {
      public static string ShortCode(this Bogus.DataSets.Finance finance)
      {
         //whatever is needed to create a valid shortcode.
      }
   }
}
  1. Write a unit test in Bogus.Tests\DataSetTests\FinanceTest.cs:

FinanceTest.cs:

[Fact]
public void can_generate_uk_shortcode()
{
   finance.ShortCode().Should().Be("07-24-15");
}
  1. Compile with VS. Test with build test.
  2. If all looks good, build clean and then commit your changes to your fork.
  3. Finally, send in the PR. 😎
  4. We'll wait for CI to check the changes. Review the PR and publish.

Once your changes are published on NuGet, you'll add the new using statement in your program:

using Bogus.Extensions.UnitedKingdom;

var faker = new Faker<BankAccount>()
         .RuleFor( acc => acc.MyUKShortCode, f => f.Finance.ShortCode())

and all UK related extension methods light up over Bogus' API.

Please feel free to ping me at anytime if you need help with anything.

Hope that helps!
Brian

⌚ 🌆 "I just can't wait... I just can't wait... for saturday night..."

@bchavez bchavez assigned bchavez and unassigned bchavez Jul 1, 2017
@cmatskas
Copy link
Author

@bchavez this is freaking awesome! Probably the best response to an issue I've ever got. For this alone, I'll spend some time and raise the PR. Thanks again my friend and keep up the great work :) 👍

@bchavez
Copy link
Owner

bchavez commented Oct 28, 2017

Hi @cmatskas ,

Good news, your feature request for UK banking Short Codes are now available in Bogus v19.

Simply import the Bogus.Extensions.UnitedKingdom namespace as described here:
https://github.com/bchavez/Bogus#api-extension-methods

The .ShortCode() extension method hangs off the Finance data set, so f => f.Finance.ShortCode() should just about do it.

Enjoy :)

Thanks,
Brian

🚶 😎 "So don't delay... act now supplies are running out..."

@Nosmadas
Copy link

How come they're named ShortCodes here? The OP even says SortCode?

Great extension BTW, just a little confused as a consumer.

@bchavez

@bchavez
Copy link
Owner

bchavez commented Feb 27, 2018

Hi @Nosmadas,

Thanks for your question. The official API is ShortCode() defined here:

public static string ShortCode(this Finance finance, bool includeSeperator = true)

My reference to ShortCodes (with an s) in this thread is in the plural form (as a group) and references the ability to generate more than one ShortCode with Bogus.

Is there something else in the United Kingdom that is also called "ShortCodes" that can cause confusion between ShortCode and ShortCodes?

Thanks,
Brian

💨 🚶 "Bubbles of gas in my brain... Send me off balance, it's not enough"

@Nosmadas
Copy link

Hey @bchavez

The API looks great.

I was referring to this instead - https://en.wikipedia.org/wiki/Sort_code rather than plural vs singular.

Sort vs Short.

@bchavez
Copy link
Owner

bchavez commented Feb 27, 2018

Ahhh, now I see. Well, I screwed up that one pretty badly didn't I?

The dyslexia is real. I have no idea why I read "Sort" as "Short" (as in small). Lmao. 😃

My bad.

I'll rename this API to SortCode as originally intended and issue a new release sortly (pun intended). hahaha. 😎

Should be in a few hours, currently putting the final touches on some other new features. 👍

🌙 🌠 "Nothing good happens past 2am..."

@bchavez bchavez reopened this Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants