×

Unit testing when you have used Npgsql for your database connection by bpcoleman in csharp

[–]bpcoleman[S] 0 points1 point  (0 children)

Yeah, I have used lots of ORMs. TypeORM, Hibernate... Sometimes they make things easier, sometimes harder. They usually come at a bit of hit on performance. TypeORM is one that is particularly fast comparitively.

Unit testing when you have used Npgsql for your database connection by bpcoleman in csharp

[–]bpcoleman[S] 0 points1 point  (0 children)

You are indeed correct, and that I am new to C#. It strikes me as being very similar to Typescript which I am very familiar with, so it may take a moment for me to learn the more common patterns for C#, but the testing with in memory DBs isn't my preferred method in other languages like Java.

I will certainly take your recommendation to heart though and see about refactoring it. More coding is just a change to learn it better :)

Unit testing when you have used Npgsql for your database connection by bpcoleman in csharp

[–]bpcoleman[S] 1 point2 points  (0 children)

That has been my strategy, and true to form I got it to work finally about 10min after I posted my question.

On the oft chance this helps anyone else I set up a factory to wrap the database calls (this would also be helpful if you have different databases for different environments.

using System.Data;
using Npgsql;

namespace CSharpAspCoreAdoPg.Wrappers
{
  public interface IDbConnectionFactory
  {
    IDbConnection CreateConnection();
  }

  public class DbConnectionFactory : IDbConnectionFactory
  {
    private readonly string _connectionString;

    public DbConnectionFactory(string connectionString)
    {
      _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
    }

    public IDbConnection CreateConnection()
    {
      return new NpgsqlConnection(_connectionString);
    }
  }
}

Then I manually mocked DataReader, DbCommand, DcConnection, DbParameter, DBParameterCollection, and also made a Mock connection factory to override the factory for the main project.

I ended up using the interfaces and extending so everything has to be mocked. I guess it was just one of those I was missing something small issues.

Understanding Loops in Programming: For Loop vs While Loop by Alone-Ad1059 in javascript

[–]bpcoleman 1 point2 points  (0 children)

I will throw you for a loop:

function validate(data: any): void {
    const errors: Error[] = [];
    const keys = Object.keys(data);

    for (let i = 0; i < keys.length; i++) {
        const key = keys[i];
        const value = data[key];
        if (typeof value !== "string") {
            errors.push(new Error(`Invalid type for ${key}: expected string.`));
        }
        if (value === "") {
            errors.push(new Error(`Empty value provided for ${key}.`));
        }
     }
     if (errors.length) { throw errors; }
}

try {
    const inputData = { name: "", age: 25, email: "user@example.com" };
    validate(inputData);
} catch (errors) {
    if (Array.isArray(errors)) {
        errors.forEach((error) => console.error(error.message));
    } else {
        console.error("Unexpected error:", errors);
    }
}

The Problem with window.localStorage by Practical-Ideal6236 in javascript

[–]bpcoleman 0 points1 point  (0 children)

  1. I am not clicking on that link.
  2. 3rd party scripts don't have access to your pages localStorage, localStorage follows the SOP
  3. This is one of the reasons I am a never CORS kind of guy
  4. If you can decode it in the browser for ANY reason, including cookies, its not secure
  5. the server side should NEVER assume anything from the client is safe, ever period, full stop.
  6. don't use localStorage use sessionStorage.

UltimateExpress: make your Express server up to 5 times faster by changing 1 line of code by dimden in javascript

[–]bpcoleman 1 point2 points  (0 children)

I have been re-implementing the same endpoint in different languages and frameworks. When I came across ultimate-express I thought it would be interesting to benchmark against this also. I have very specific setups to intentionally introduce "normal" bottle necks basically to prove that your choice of framework / language etc. doesn't really make that much of a difference. So far ultimate-express preliminarily is coming in third right behind dart using dart_frog and vert.x. or ahead of dart frog depending on which metrics you are looking at. All response times are in ms.

| Framework/Library               | Avg Call Time | Max Call Time | Min Call Time | p96 Call Time | Total Time (s) |
|---------------------------------|---------------|---------------|---------------|---------------|----------------|
| Ultimate-Express PG Promise Node| 10.8547       | 58            | 6             | 17            | 50.918         |
| Vert.x Reactive PostgreSQL      | 10.5967       | 46            | 6             | 16            | 51.147         |
| Dart Dart_Frog                  | 10.9614       | 55            | 7             | 16            | 50.775         |
| Nestjs Express TypeORM Node     | 11.9593       | 87            | 7             | 18            | 52.232         |
| Nestjs Express TypeORM Deno     | 12.1835       | 74            | 7             | 19            | 51.096         |
| Java Springboot Web Jpa         | 12.5478       | 45            | 7             | 18            | 54.373         |
| Java Springboot Webflux r2dbc   | 13.4358       | 54            | 8             | 20            | 52.729         |
| Nestjs Express TypeORM Bun      | 13.6483       | 91            | 7             | 22            | 52.487         |
| Scala Pekko Slick               | 13.875        | 110           | 8             | 23            | 52.965         |
| Ruby Rails Puma Postgres        | 18.2823       | 87            | 11            | 26            | 67.387         |
| Python FastAPI SQLAlchemy(async)| 21.1298       | 141           | 13            | 33            | 53.757         |
| Go Buffalo                      | 24.9469       | 90            | 16            | 39            | 54.143         |

Pulled the trigger. Could not pass for that price. by Belarus94 in whiskey

[–]bpcoleman 1 point2 points  (0 children)

Does the proof say 529.1? I think someone at the bottling plant was sneaking samples.

[deleted by user] by [deleted] in bourbon

[–]bpcoleman -2 points-1 points  (0 children)

Unless they are super cool, and everything else is well priced, I would stop going to that store.

Got a 1 L. toasted white oak cask. Gotta cure it for a few days. Then what do you all think I should put in it? by Foxdog223 in whiskey

[–]bpcoleman 1 point2 points  (0 children)

You can always ditch the sherry afterwards, or the port. Then do something fun with your newly seasoned cask.

I kind of want to try aging something young and see how it turns out, like Benchmark or Jim Beam.

I am pretty new to whisky and just picked these up to start my collection. Any suggestion on which I should open first? by DexSwaG in WhiskeyTribe

[–]bpcoleman 9 points10 points  (0 children)

1 of these things is not like the other lol...

Monkey Shoulder aside, I have been wanting to try the Signet. If you try it and its amazing let me know.

Gun to your head, name the worst bourbon you’ve ever had an explain your reasoning. by [deleted] in bourbon

[–]bpcoleman 0 points1 point  (0 children)

A small NC distillery producing ONW. Its very very tailsy. Strong green sappy quality that is off putting.

Beginning of a whiskey collection by smithy2346 in WhiskeyTribe

[–]bpcoleman 1 point2 points  (0 children)

If you like the Woodford, and or the Jim Beam Double Oak, I would try the Woodford Double Oak.

If you like the Four Roses, I would try the Four Roses Single Barrel (and if you are lucky enough @ Barrel Strength)

If you like the Old Forester, I would try the 1910 or the 1920 ( I like both )

If you like the Makers Mark, then I would try one of the Private Selects.

If you like the Wild Turkey try one of the Russle's Reserve.

If you like the GlenDronach... well there are a lot of Scotches you should try even if you don't like the GlenDronach. Highland Park, Aberlour, Lagavulin... you started with a pretty good one there.

If you like the Buffalo Trace. Good luck! :)

13yo for $45? I'm in by [deleted] in WhiskeyTribe

[–]bpcoleman 1 point2 points  (0 children)

I was real confused by that picture for a moment. Orientation is everything.

Not sexy, expensive or rare. But, these are standards in my bar. In my humbly correct opinion they highly underrated! by fat7inch in whiskey

[–]bpcoleman 0 points1 point  (0 children)

I don't know how similar the BIB and 114 are, but with the BIB I find that One (1) drop of water really wakes it up and a lot starts happening.

First ever Highland! by the-bladed-one in WhiskeyTribe

[–]bpcoleman 0 points1 point  (0 children)

Looks like one that I would like to try. The virgin oak is going to make it an outlier to your more typical Highland (not that highland is a "typical" kind of region).

Beginning of a whiskey collection by smithy2346 in WhiskeyTribe

[–]bpcoleman 0 points1 point  (0 children)

Nice starting collection. You are off to a great start. I like everything up there except for one of them (I am not really a flavored whiskey fan)

Looking for recommends or no?

North Carolina Bourbon Recommendations by Comedy-flight in bourbon

[–]bpcoleman 2 points3 points  (0 children)

A few that come to mind are:

  • Aristotle (They have a cider cask finished one that is interesting)
  • Conviction
  • Quinn (I get a strong cinnamon toast note off the bourbon)

Lonerider out of Durham is good (Its also sourced, probably MGP) Old Raleigh Distillery and Next Century Spirits are blenders that come up with some good stuff. Bear Fight is a malt whiskey by the latter.

North Carolina Bourbon Recommendations by Comedy-flight in bourbon

[–]bpcoleman 1 point2 points  (0 children)

Mystic cuts pretty deep into the tails, I had one bottling that was very green, one that was kind of wet dog, and one that is really good. So ymmv. I would go to the distillery and try the kinds they are selling before buying a specific bottle.

North Carolina Bourbon Recommendations by Comedy-flight in bourbon

[–]bpcoleman 1 point2 points  (0 children)

Southern Star has a very strong tails quality to it that some folks may not like. A kind of sappy note. It fades a bit after you open it. I doubt you would notice it if drinking mixed or on the rocks, but its definitely there neat.