Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
johnmmoss / Selenium-Setup.cs
Created March 24, 2021 14:52
Setup Selenium tests using new Context Injection
using Microsoft.Extensions.Configuration;
[Binding]
public class Setup
{
[BeforeFeature]
public static void BeforeFeature(FeatureContext featureContext)
{
// Read settings from testSettings.Development file
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development" ;
@johnmmoss
johnmmoss / AzureDevops-UpdateWebConfig.ps1
Created December 29, 2020 14:06
Script hack to update web.config before build
$server = "127.0.0.1"
$database = "TomatoFarm123"
$username ="use12356"
$password = "pAssWord!"
$connectionString = "Server=$server;Database=$database;User Id=$username;Password=$password;"
$webConfig = "C:\Code\tomatofarm\Api\Api\Web.Config"
$xml = New-Object xml
$xml.PreserveWhitespace = $true
public class ApiContext : IApiContext
{
private readonly string _baseUri;
public ApiContext(string baseUri)
{
_baseUri = baseUri;
}
public Uri GetPageUri(PaginationFilter filter, string route)
var tasks = new List<Task<ResponseDto>>();
foreach (var survey in filteredSurveys)
{
var task = Task.Run(() => GetResponses(survey));
tasks.Add(task);
}
Task.WaitAll(tasks.ToArray());
return tasks.Select(x => x.Result).ToList();
[Route("api/[controller]")]
[ApiController]
public class EmployeeController : ControllerBase
{
private readonly HrContext _hrContext;
public EmployeeController(HrContext hrContext)
{
_hrContext = hrContext;
}
var connectionString = "Server=(local)\\sqlexpress;Initial Catalog=AcmeDatabase;Persist Security Info=False; integrated security=True";
services.AddDbContext<AcmeContext>(o => o.UseSqlServer(connectionString));
public class AcmeContext : DbContext
{
public AcmeContext(DbContextOptions<AcmeContext> options)
: base(options)
{
}
public DbSet<Employee> Employees { get; set; }
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Running Select Many Sample...");
IEnumerable<Person> people = new List<Person>()
{
new Person()
{
@johnmmoss
johnmmoss / downloadFile.js
Created January 6, 2020 15:22
Create a link and click it then remove link. Used for fudging browser file downloads
const downloadFile = (filename, text) => {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
#
# Build Task - Pack the Migration
#
$dataDir = "$(System.DefaultWorkingDirectory)\Acme.Data\bin\Release"
$migrationExePath = "$(System.DefaultWorkingDirectory)\packages\EntityFramework.6.2.0\tools\migrate.exe"
$stagingDirectory = "$(Build.ArtifactStagingDirectory)\Data"
Write-Output "MigrationPath: $migrationExePath"
Write-Output "DataDir: $dataDir"