Skip to content

Instantly share code, notes, and snippets.

View JayBazuzi's full-sized avatar

Jay Bazuzi JayBazuzi

View GitHub Profile
@JayBazuzi
JayBazuzi / wewut-tests.cs
Last active August 29, 2015 14:17
Code samples from Working Effectively with Unit Tests (https://leanpub.com/wewut)
[TestClass]
public class CustomerTest
{
private const string DavidName = "David";
private const string JohnName = "John";
private const string PatName = "Pat";
private const string SteveName = "Steve";
private readonly Customer[] _customers;
private readonly Customer _david;
private readonly Customer _john;
@JayBazuzi
JayBazuzi / CA2214Example.cs
Created March 27, 2015 00:29
Example of why FxCop rule CA2214 (Do not call overridable methods in constructors) matters
class C : B
{
string s;
public C()
{
s = "hi";
}
protected override void F()
{
Console.WriteLine(s.Length); // NullReferenceException
class Foo
{
private readonly IEvents _events;
public Foo(IEvents events)
{
_events = events;
}
public interface IEvents
@JayBazuzi
JayBazuzi / resharper-sort-members-bug.cs
Last active August 29, 2015 14:19
Using R# 9, uncomment one of the lines below and run Code Cleanup. I get different results depending on which I uncomment.
public class C
{
public void F()
{
}
public static readonly C C1 = new C {S = "sldkfjsldf"};
// public static readonly C C2 = new C {S = C1.S};
// public static readonly C C2 = new C {S = "sdflskdfj"};
public string S;
[TestMethod]
public void RouteToGetUser()
{
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:4567/api/users/me");
var config = new HttpConfiguration();
WebApiConfig.Register(config);
config.EnsureInitialized();
var result = config.Routes.GetRouteData(request);
public class HttpRequestMessageList : List<HttpRequestMessage>
{
public void Add(string uri, HttpMethod httpMethod)
{
this.Add(new HttpRequestMessage(httpMethod, uri));
}
}
void Caller1(C c, I i)
{
c.F1(); // No warning
c.F2(); // CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
i.F3(); // No warning
}
async Task Caller2(C c, I i)
{
c.F1(); // CS4014
@JayBazuzi
JayBazuzi / Boxstarter.ps1
Last active February 4, 2017 20:07
Boxstarter Script
Set-CornerNavigationOptions -EnableUpperRightCornerShowCharms -EnableUpperLeftCornerSwitchApps -EnableUsePowerShellOnWinX
Update-ExecutionPolicy RemoteSigned
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowFileExtensions
Enable-RemoteDesktop
Install-WindowsUpdate -acceptEula
#cinst sublimetext3 sublimetext3.packagecontrol
#cinst 7zip
cinst googlechrome
# START http://boxstarter.org/package/url?https://gist.githubusercontent.com/JayBazuzi/7b22dcb5d0ba3d326a99/raw/24fe6d3946337474ea292227a18e4fd529055a92/BoxStarterADM.ps1
Set-ExecutionPolicy RemoteSigned -Force
Set-WindowsExplorerOptions -showHiddenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions
Enable-RemoteDesktop
cinst chocolatey
cinst vs2013.4
cinst ncrunch-vs2013
cinst vs2013.4
static bool ShouldAcceptConnectionRequest(bool firstUserHasConnections, bool secondUserHasConnections)
{
return !firstUserHasConnections && !secondUserHasConnections;
}