Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Coding

stuart williams BlitzkriegSoftware

💭
Coding
View GitHub Profile
@BlitzkriegSoftware
BlitzkriegSoftware / DumpDataTable.cs
Created Apr 13, 2020
Take a C# System.Data.DataTable and dump it to the console for debugging
View DumpDataTable.cs
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 Oct 21, 2019
Test serialization of a DTO (if you have a REST API, please test it's DTOs)
View SerializationHelper.cs
// 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 Sep 10, 2019
Example of using the Elastic APM Helper in a controller.
View ElasticApmDemoController.cs
// 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 Sep 10, 2019
Elastic APM Wrapper for ASP.NET Framework
View ElasticApmWrapper.cs
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 Aug 24, 2019
A Handy Timer for use in MSTEST to wrap a block of code to time execution
View TxTimer.cs
/// <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 Aug 24, 2019
A handy logger for use in MSTEST to provide an ILogger
View MsTestLogger.cs
/// <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 Aug 24, 2019
A handy helper to do a round trip serialization test (JSON)
View AssertHelpers.cs
/// <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 Aug 24, 2019
A handy testing method to serialize an object as JSON for MSTEST output
View TestOutPutHelper.cs
/// <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 Feb 4, 2019
Send an e-mail from .NET Core 2.1+
View SendMail.cs
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 Feb 4, 2019
Support Class for sending e-mail in .NET Core 2.1+
View EMailDTO.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace testemail
{
public class EmailDTO
{
public string address { get; set; }
public string port { get; set; }
You can’t perform that action at this time.