Skip to content

Instantly share code, notes, and snippets.

Patrick Lioi plioi

  • Austin, TX
Block or report user

Report or block plioi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
plioi / linebreaks_wp.cs
Created Jul 11, 2013
Wordpress's automatic <p> tag insertion meat grinder, portedn to C#.
View linebreaks_wp.cs
static string linebreaks_wp(string body)
if (body.Trim() == "")
return "";
//Ensure all newlines are simply \n and that we end with a \n
body = body.Replace("\r\n", "\n")
.Replace("\r", "\n");
body = body + "\n";
View ComplexTypes.cs
public abstract class Entity
public Guid Id { get; set; }
public class Customer : Entity
public Customer()
Orders = new List<Order>();
View ContactsContext.cs
public class ContactsContext : DbContext
private DbContextTransaction _currentTransaction;
public void BeginTransaction()
if (_currentTransaction != null)
View ExampleDbContext.cs
public class ExampleDbContext : DbContext
private DbContextTransaction _currentTransaction;
public void BeginTransaction()
if (_currentTransaction != null)
View Assertions.cs
public static class Assertions
public static void ShouldMatch<T>(this T actual, T expected)
=> Json(actual).ShouldEqual(Json(expected), "Expected two objects to match on all properties.");
private static string Json<T>(T actual)
=> JsonConvert.SerializeObject(actual, Formatting.Indented);
View UnitOfWork.cs
public class UnitOfWork : ActionFilterAttribute
public override void OnActionExecuting(ActionExecutingContext filterContext)
var database = DependencyResolver.Current.GetService<ContactsContext>();
public override void OnActionExecuted(ActionExecutedContext filterContext)
View ContactEdit.cs
namespace ContactList.Features.Contact
using System;
using AutoMapper;
using ContactLists.Core;
using Core.Domain;
using FluentValidation;
using MediatR;
public class ContactEdit
View EntityTests.cs
using System.Linq;
using ContactList.Core.Domain;
using ContactList.Tests;
using static Testing;
public class EntityTests
public void ShouldPersist<TEntity>(TEntity entity) where TEntity : Entity
View Testing.cs
public static class Testing
private static IContainer Container => TestDependencyScope.CurrentNestedContainer;
public static T Resolve<T>()
return Container.GetInstance<T>();
public static object Resolve(Type type)
View AutoFixtureParameterSource.cs
public class AutoFixtureParameterSource : ParameterSource
public IEnumerable<object[]> GetParameters(MethodInfo method)
// Produces a randomly-populated object for each
// parameter declared on the test method, using
// a Fixture that has our customizations.
var fixture = new Fixture();
You can’t perform that action at this time.