My Notes of Daily Lessons in Software Engineering

DotNet

Output generated SQL from Entity Framework to the console

            dotnet add [project_file.csproj] package Microsoft.Extensions.Logging.Console
        
            public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => {builder.AddConsole();});
            ...
            services.AddDbContext(o => {
                o.UseSqlServer(connection, options => options.EnableRetryOnFailure())
                    .UseLoggerFactory(MyLoggerFactory);    
            })
            ...
        

DB Context is null when being injected into a Repository class

Fields in appsettings.json must have a correspdoning property in AppSettings.cs in order to be available in code.

Unit Testing Entity Framework connected to SQL Server

            var configurationBuilder = new ConfigurationBuilder()
                .SetBasePath(AppDomain.CurrentDOmain.BaseDirectory)
                .AddJsonFile($"appSettings.json", optional: false, reloadOnChange: false)
                .AddEnvironmentVariables().Build();
            var services = new ServiceCollection()
                .Configure(configurationBuilder)
                .AddSingleton(resolver => resolver.GetRequiredService>().Value)

            services.AddTransient()
            services.AddDbContext(o => {
                o.UseSqlServer(contextInstance);
            });
        

From the Unit Test, get the service by calling a method on the fixture after everything has started up.

            public T GetService(){
                return _provider.GetServices().FirstOrDefault();
            }
        

Elasticsearch

If you want to change/map how property names get serialized to Elasticsearch document, use [DataMember(Name="")] from System.Runtime.Serialization

PowerShell

            
        

SQL

            select * from sys.columns c
            inner join sys.tables t on c.object_id = t.object_id
            where c.name like '%%'
        

Redis

Create a replica. Copy PROD data to QA.

            REPLICAOF host port
        

Javascript

            Tagged Templates https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
        

Website Marketing

  • Setup Google Analytics
  • Google Search - https://search.google.com/ Verify domain with DNS TXT record
  • Optimize page speed with https://developers.google.com/speed/pagespeed/insights

Multiple Gitlab Accounts

            # ~/.gitconfig             
            # This is Git's per-user configuration file.
            [user]
            # Please adapt and uncomment the following lines:
                name = Joey Guerra
                email = {email address}
            [pull]
                rebase = false
            [init]
                defaultBranch = main
            
            [includeIf "gitdir/i:~/src/{project folder for code}/"]
                path = ~/src/{project folder for code}/.gitconfig
        

e2e integration tests with Gitlab pipeline

integration:
  image: mcr.microsoft.com/playwright:focal
  services:
    - redis
  variables:
    APP_NAME: PdfGenerator
  script:
    - curl https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb --output packages-microsoft-prod.deb
    - dpkg -i packages-microsoft-prod.deb
    - rm packages-microsoft-prod.deb
    - apt-get update
    - apt-get install -y apt-transport-https
    - apt-get install -y dotnet-sdk-5.0
    - cd $APP_NAME.Tests
    - pwd
    - dotnet build
    - dotnet tool install --global Microsoft.Playwright.CLI
    - export PATH="$PATH:/root/.dotnet/tools"
    - playwright install
    - cd ../
    - make integration
  artifacts:
    name: '$CI_JOB_NAME_$CI_COMMIT_REF_NAME'
    paths:
      - $APP_NAME.Tests/IntegrationTests_*.xml

        

Kubernetes

            kubectl create secret generic {name of secret} -n {namespace name} --dry-run=client --from-literal {key}={password} --from-literal {key}={password} --from-literal {key}={password} -o yaml | kubeseal --format yaml | tee sealed-secret.yaml