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
View Domain.cs
namespace ContactList.Core.Domain
{
using System;
public abstract class Entity
{
public Guid Id { get; set; }
}
public class Contact : Entity
@plioi
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)
return;
View ExampleDbContext.cs
public class ExampleDbContext : DbContext
{
private DbContextTransaction _currentTransaction;
...
public void BeginTransaction()
{
if (_currentTransaction != null)
return;
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>();
database.BeginTransaction();
}
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
{
[AllEntities]
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)
You can’t perform that action at this time.