Skip to content

Instantly share code, notes, and snippets.

View ChrisMissal's full-sized avatar
💭
set status

Chris Missal ChrisMissal

💭
set status
View GitHub Profile
@ChrisMissal
ChrisMissal / About.md
Last active August 30, 2019 17:12
Example of Partial DbContext and interface for mocking/testing.

About

The file WorkifyEntities.Context.cs is what EF generates for us, or in EF Core, you can create yourself on top of the base class.

The Entities.cs file, we create our own partial class, and assign an interface. From here, we will register our own interface while the instance will be the DbContext.

Usage

Just inject the interface and use it. You will have to add properties and methods to the interface to match the DbContext.

@ChrisMissal
ChrisMissal / FailingTest.cs
Last active September 14, 2017 20:53
Auto property initializers vs Expression-bodied members. Explained here: http://thebillwagner.com/Blog/Item/2015-07-16-AC6gotchaInitializationvsExpressionBodiedMembers
public class Test
{
public class Name
{
public string Text { get; set; }
}
public abstract class Widget
{
public abstract Name Name { get; }
public class ConsistentInterval : IDisposable
{
private readonly TimeSpan delay;
private readonly CancellationToken cancellationToken;
private readonly DateTimeOffset startTime;
public ConsistentInterval(TimeSpan delay, CancellationToken cancellationToken)
{
this.delay = delay;
this.cancellationToken = cancellationToken;
@ChrisMissal
ChrisMissal / mat-quote-from-txjs.md
Last active August 29, 2015 14:27
The Once & Future Web: Mat Marquis

I love this quote by Mat Marquis from TXJS 2015:

We, as an industry, have nearly decided that we are all doing a really, really good job as long as we don't count the instances where we're doing a really, really bad job.

Source: https://www.youtube.com/watch?v=WZAx3f0nJS0

@ChrisMissal
ChrisMissal / clitests.cs
Last active August 29, 2015 14:17
CLI Code Spike – Rethinking how I interact with the command line via C# a little bit. I have some spike code in which all these tests pass. Thoughts?
public class CommandResolutionTests
{
public void should_resolve_text_to_command()
{
"samplecommand".Called<SampleCommand>();
}
public void should_call_command_hello()
{
"samplecommand hello".Called<SampleCommand>()
begin transaction
create table DumbSample (
Expired bit default 0,
Name varchar(max)
)
insert into DumbSample (Expired, Name) values (0, 'Milk');
@ChrisMissal
ChrisMissal / ImplicitCausingNullRef.cs
Created April 10, 2014 18:47
Implicit operator causing sneaky NullReferenceException
void Main()
{
var order = new Order
{
Instructions = SpecialInstructions.LeaveAtDoor,
};
var thing = new Thing
{
Instructions = order.Instructions,
@ChrisMissal
ChrisMissal / ApiController.cs
Last active December 29, 2015 11:59
URLs as JSON to be used on the client
using System.Linq;
using System.Web.Mvc;
using Construction.Core.Features.QuickSearch;
using Construction.Core;
using Construction.Core.Extensions;
using Core.Helpers;
using Newtonsoft.Json.Linq;
public class ApiController : BaseController
{
@ChrisMissal
ChrisMissal / screencapture.ps1
Created September 19, 2013 20:58
How can I do a screen capture in windows powershell?
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
@ChrisMissal
ChrisMissal / find_references.sql
Created September 19, 2013 15:03
Find all columns that have foreign keys referencing another table.
select t.name as TableWithForeignKey, fk.constraint_column_id as FK_PartNo , c.name as ForeignKeyColumn
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = 'tablename')
order by TableWithForeignKey, FK_PartNo