Skip to content

Instantly share code, notes, and snippets.

View BlitzkriegSoftware's full-sized avatar
💭
Coding

stuart williams BlitzkriegSoftware

💭
Coding
View GitHub Profile
@BlitzkriegSoftware
BlitzkriegSoftware / DumpDataTable.cs
Created April 13, 2020 23:05
Take a C# System.Data.DataTable and dump it to the console for debugging
private static void DumpDataTable(DataTable dt)
{
if((dt == null) || (!SqlHelper.HasRows(dt)))
{
Console.Error.WriteLine("There are no rows");
} else
{
foreach(DataColumn c in dt.Columns)
{
Console.Write($"\"{c.ColumnName}\",");
@BlitzkriegSoftware
BlitzkriegSoftware / SerializationHelper.cs
Created October 21, 2019 19:52
Test serialization of a DTO (if you have a REST API, please test it's DTOs)
// using Microsoft.VisualStudio.TestTools.UnitTesting;
// using Newtonsoft.Json;
// using System;
// using System.Collections.Generic;
// using System.Linq;
/// <summary>
/// Tests that a model serializes correctly
/// </summary>
/// <typeparam name="T">Type</typeparam>
@BlitzkriegSoftware
BlitzkriegSoftware / ElasticApmDemoController.cs
Last active September 10, 2019 17:23
Example of using the Elastic APM Helper in a controller.
// NuGet: Elastic.Apm
using Blitzkrieg.ElasticApmHelper;
using Elastic.Apm.Api;
// ...
namespace Blitzkrieg.DemoWeb {
public class ValuesController : ApiController
{
private Libs.ElasticWrapper alm = new ElasticWrapper();
@BlitzkriegSoftware
BlitzkriegSoftware / ElasticApmWrapper.cs
Created September 10, 2019 17:13
Elastic APM Wrapper for ASP.NET Framework
using System;
using Elastic.Apm.Api;
// NuGet: Elastic.Apm
namespace Blitzkrieg.ElasticApmHelper {
/// <summary>
/// Elastic Wrapper
/// </summary>
public class ElasticWrapper
@BlitzkriegSoftware
BlitzkriegSoftware / TxTimer.cs
Last active August 24, 2019 20:35
A Handy Timer for use in MSTEST to wrap a block of code to time execution
/// <summary>
/// Handy Helper to Time Executions of Tests
/// <example>
/// Here is a typical snippet, because the class supports <see cref="IDisposable"/> the time can be started at the top
/// of the using statement and automatically stopped in the dispose
/// <code>
/// // Stop Watch Created and Started
/// using (TxTimer myTimer = new TxTimer( ... )) {
/// // Do something you want timed
/// var elapsed = myTimer.ElapsedMilliseconds;
@BlitzkriegSoftware
BlitzkriegSoftware / MsTestLogger.cs
Created August 24, 2019 20:33
A handy logger for use in MSTEST to provide an ILogger
/// <summary>
/// MsTestLogger<typeparamref name="T"/> for ILogger
/// </summary>
/// <typeparam name="T"></typeparam>
public class MsTestLogger<T> : ILogger<T>, IDisposable
{
private TestContext _output;
public MsTestLogger(TestContext output)
{
@BlitzkriegSoftware
BlitzkriegSoftware / AssertHelpers.cs
Created August 24, 2019 20:31
A handy helper to do a round trip serialization test (JSON)
/// <summary>
/// Helpers to do asserts on objects in bulk
/// </summary>
public static class AssertHelpers
{
#region "Serialization Helper"
/// <summary>
/// XUnit Tests that a model serializes correctly
/// </summary>
@BlitzkriegSoftware
BlitzkriegSoftware / TestOutPutHelper.cs
Created August 24, 2019 20:29
A handy testing method to serialize an object as JSON for MSTEST output
/// <summary>
/// Helper to output as JSON
/// </summary>
public static class TestOutputHelper
{
/// <summary>
/// Emit an object as json
/// </summary>
/// <param name="output">ITestOutputHelper</param>
@BlitzkriegSoftware
BlitzkriegSoftware / SendMail.cs
Created February 4, 2019 19:51
Send an e-mail from .NET Core 2.1+
using System.Net;
using System.Net.Mail;
namespace testemail
{
public static class SendMailer
{
public static void SendMail(EmailDTO dto)
{
SmtpClient client = new SmtpClient(dto.address);
@BlitzkriegSoftware
BlitzkriegSoftware / EMailDTO.cs
Created February 4, 2019 19:46
Support Class for sending e-mail in .NET Core 2.1+
using System;
using System.Collections.Generic;
using System.Text;
namespace testemail
{
public class EmailDTO
{
public string address { get; set; }
public string port { get; set; }