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

handle enum values in Quoters #1475

Closed
wants to merge 34 commits into from

Conversation

MihailsKuzmins
Copy link

PR for the issue #1441.

  • created QuoterOptions which is passed to all Quoters
  • handle enum values by EnumAsUnderlyingType (false - stringm true - numeric). Default value: false, i.e. string (as it is now)
  • added a configuration method WithQuoterConventions() in MigrationRunnerBuilderExtensions
  • added tests for enum handling

Copy link
Collaborator

@jzabroski jzabroski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MihailsKuzminsDG Thanks for this contribution. Most of my remarks are fairly minor - typos, adjusting application binary interface to ensure no breaking changes. It looks like you took care of one of my earlier remarks about the QuoterOptions not being three-valued logic but we still need a default constructor. Also, the FirebirdGenerator constructor appears to have an ABI breaking change - can you please restore the old constructor and mark it as Obsolete so that consumers are aware.

public interface IQuoterOptions
{
/// <remarks>
/// If <see langword="true"/> enums are converted to a string, if <see langword="false"/> enums are converted to the underlying numeric type.<br/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small grammar. Think this should say:

If , enums are converted to a string; if , enums are converted to the underlying numeric type.

{
/// <inheritdoc />
/// <summary>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behavior of inheritdoc + summary back to back? I never used that. More just wondering.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, my bad. I created an interface for it where <remarks> were specified, so the <summary> was taken from the actual class and the <remarks> were taken from the interface.
Along the way I deleted the interface and probably forgot to remove the <inferitdoc /> tag 😔

@@ -74,74 +74,74 @@ public override string ToString()
[Test]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a lot cleaner with an NUnit Theory, so that you can parameterize the options values and outcomes.

In other words, while it might be a bit silly to set EnumAsString in the below CanEscapeAString test, it would then be possible to test not just a string, but an enum-as-string.

Thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike xUnit, NUnit has global Theory parameters (it might become painful to have multiple Theories in one class). Do you think tests for QuoteColumnName should be extracted to another class?
I am sorry, but I don't quite follow you with regards to CanEscapeAString. The property EnumAsString (now EnumAsUnderlyingType) does not affect QuoteColumnName which is tested by CanEscapeAString

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the point- the theory would verify it doesn't affect QuoteColumnName. It might be needless complexity since an enum field name can't have a common escape in it - but Oracle and DB2 allow for arbitrary escapes, so it gets interesting fast.

@@ -187,6 +186,18 @@ public void EnumIsFormattedAsString()
.ShouldBe("'Bar'");
}

[Test]
public void EnumIsFormatterAsUnterlyingType()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo. Please find+replace EnumIsFormatterAsUnterlyingType with EnumIsFormatterAsUnderlyingType


public GenericQuoter(QuoterOptions quoterOptions = null)
public GenericQuoter([CanBeNull] QuoterOptions options)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see @fubar-coder remarks about having the default constructor still available. I would not use [CanBeNull] - instead, the default constructor should just initialize the quoter to a default value. Adding nulls will just complicate future code.

@@ -30,9 +30,9 @@ public class GenericQuoter : IQuoter
{
private readonly QuoterOptions _options;

public GenericQuoter([CanBeNull] IOptions<QuoterOptions> options = null)
public GenericQuoter(IOptions<QuoterOptions> options)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you did my comments in the previous commit. Agree, using [CanBeNull] and assigning to null adds messy three-valued logic that we don't need. We just need a default constructor for GenericQuoter so that we don't break ABI with existing consumers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CanBeNull] for just for me in order that I don't have billions of compilation errors when I add this new parameter. But you're right, I should've added a default obsolete constructor.

[NotNull] IOptions<GeneratorOptions> generatorOptions)
: this(new FirebirdQuoter(fbOptions.ForceQuote), fbOptions, generatorOptions)
: this(new FirebirdQuoter(fbOptions, quoterOptions), fbOptions, quoterOptions, generatorOptions)
{
}

public FirebirdGenerator(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please specify what parameters the obsolete overload should consume?
FirebirdQuoter seems to be injected (QuoterOptions are injected into FirebirdQuoter)

@schambers
Copy link
Member

This PR is outdated by several years and is stale @jzabroski. Any concerns about closing it? I can ping the original author to clean it up and open a new PR if needed. Thoughts?

@MihailsKuzmins
Copy link
Author

This PR is outdated by several years and is stale @jzabroski. Any concerns about closing it? I can ping the original author to clean it up and open a new PR if needed. Thoughts?

@schambers well as for me this functionality is not required anymore (I had a workaround that has been working until now), so if this functionality is not required by the members of the project it is fine to close the PR.

@jzabroski
Copy link
Collaborator

We can close it. I might reimplement it now that I'm done making type map injectable

@jzabroski jzabroski closed this Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants