Snippets Collections
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore;


namespace TDD.Tests
{
    public class PatientTestsDbWAF<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
    {

        protected override IWebHostBuilder CreateWebHostBuilder()
        {
            return WebHost.CreateDefaultBuilder()
                .UseStartup<TStartup>();
        }
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureServices(async services =>
           {
               // Remove the app's DbContext registration.
               var descriptor = services.SingleOrDefault(
                      d => d.ServiceType ==
                          typeof(DbContextOptions<DataContext>));

               if (descriptor != null)
               {
                   services.Remove(descriptor);
               }

               // Add DbContext using an in-memory database for testing.
               services.AddDbContext<DataContext>(options =>
                  {
                      // Use in memory db to not interfere with the original db.
                      options.UseInMemoryDatabase("PatientTestsTDD.db");
                  });
           });
        }
    }
}
models:
  advanced_testing:
    # checks for every model under models directory should have unique and not_null test
    +required_tests: {"unique.*|not_null": 2}
    # checks for 'exclude' directory models should have unique and not_null test
    exclude:
      +required_tests: {"unique.*|not_null": 2}
	# checks for 'marts' directory models should have relationship test
    marts:
      +required_tests: {'relationship.*': 1}
select
	<column>
from <table>
group by 1
having count(*) > 1
window.location.search.includes('cro_mode=qa')

// or

window.location.search.indexOf('cro_mode=qa') > -1

// finding it in cookies: 
function getCookie(name) {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop().split(';').shift();
}
//then...
getCookie('cro_mode')

//or something like ...
  const parts = document.cookie.split('cro_mode');
  if (parts.length === 2) {console.log(parts.pop().split(';').shift())}
test('Check addTodo able add todo to todoList', () => {
  document.body.innerHTML = `
    <input id="newTodoInput" />
    <button id="addTodoBtn">Add todo</button>
    <ol id="todoList"></ol>
  `;
  require('../todolist.js');

  const newTodoInput = document.getElementById('newTodoInput');
  const addTodoBtn = document.getElementById('addTodoBtn');
  const todolist = document.getElementById('todoList');

  newTodoInput.value = 'New todolist!';
  addTodoBtn.click();

  expect(todolist.innerHTML).toBe('<li>New todolist!</li>');
});
const APP = (() => {
  var userData = null;
  const myURL = "http://stackoverflow.com";
  const getData = () => {
    $.ajax({
      type: "GET",
      url: myURL,
      success: obj.handleSuccess,
      error: obj.handleError,
    });
  };
  const handleError = () => {
    console.log("ERROR");
  };
  const handleSuccess = (data) => {
    userData = data;
    console.log(userData);
  };
  const render = () => {
    return "<div>some stuff</div>";
  };
  const obj = {
    getData,
    handleError,
    handleSuccess,
    render,
  };
  return obj;
})();
module.exports = APP;


const APP = require("../ajax");
describe("Ajax", () => {
  beforeEach(() => {
    jest.restoreAllMocks();
  });
  it("Data should load", () => {
    const ajaxSpy = jest.spyOn($, "ajax");
    APP.getData();
    expect(ajaxSpy).toBeCalledWith({
      type: "GET",
      url: "http://stackoverflow.com",
      success: expect.any(Function),
      error: expect.any(Function),
    });
  });
  it("should handle success", () => {
    const mUser = { userId: 1 };
    const logSpy = jest.spyOn(console, "log");
    APP.handleSuccess(mUser);
    expect(logSpy).toBeCalledWith(mUser);
  });
  it("should handle error", () => {
    const logSpy = jest.spyOn(console, "log");
    APP.handleError();
    expect(logSpy).toBeCalledWith("ERROR");
  });
});
let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex.test(myString); // result === true
  public static EasyRandomParameters getEasyRandomParameters(int collectionSize) {
    return new EasyRandomParameters()
        .randomize(BigDecimal.class, BIG_DECIMAL_RANDOMIZER)
        .collectionSizeRange(collectionSize, collectionSize);
  }

  public static final Randomizer<BigDecimal> BIG_DECIMAL_RANDOMIZER =
      () ->
          BigDecimal.valueOf(ThreadLocalRandom.current().nextDouble(0, 100))
              .setScale(8, RoundingMode.DOWN);
  public static final Randomizer<BigDecimal> BIG_DECIMAL_RANDOMIZER =
      () ->
          BigDecimal.valueOf(ThreadLocalRandom.current().nextDouble(0, 100))
              .setScale(8, RoundingMode.DOWN);
star

Tue Jun 06 2023 08:05:54 GMT+0000 (Coordinated Universal Time) https://www.freecodecamp.org/news/learn-tdd-with-integration-tests-in-net-5-0/?utm_source

#tdd #test #in-memory #db
star

Mon May 08 2023 05:12:28 GMT+0000 (Coordinated Universal Time)

#dbt #test #global
star

Mon May 08 2023 01:32:29 GMT+0000 (Coordinated Universal Time)

#dbt #test #ad-hoc
star

Tue Feb 14 2023 21:44:06 GMT+0000 (Coordinated Universal Time)

#test #cookie
star

Wed Feb 01 2023 13:26:33 GMT+0000 (Coordinated Universal Time)

#javascript #jest #test
star

Wed Feb 01 2023 13:23:45 GMT+0000 (Coordinated Universal Time)

#javascript #jest #test
star

Sat Dec 18 2021 16:52:43 GMT+0000 (Coordinated Universal Time)

#javascript #test #method
star

Fri Oct 15 2021 09:20:54 GMT+0000 (Coordinated Universal Time)

#java #test #easyrandom
star

Fri Oct 15 2021 09:19:22 GMT+0000 (Coordinated Universal Time)

#java #test #easyrandom

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension