Skip to content

Instantly share code, notes, and snippets.

View DavidSSL's full-sized avatar
💭
Set the status

DavidSSL

💭
Set the status
View GitHub Profile
@DavidSSL
DavidSSL / ReadAsJsonAsync
Created March 20, 2013 12:31
ReadAsJsonAsync
public static Task<dynamic> ReadAsJsonAsync(this HttpContent content)
{
if (content == null)
throw new ArgumentNullException("content");
return content.ReadAsStringAsync().ContinueWith(t =>
JsonConvert.DeserializeObject(t.Result));
}
class Program
{
static void Main()
{
Person.Eats();
}
}
public class Person
{
class Program
{
// 1 Declaration of a delegate type
public delegate void PersonEatsDelegate();
static void Main()
{
// 3 Instantiation of a delegate (short form)
PersonEatsDelegate personEatsDelegate = Person.Eats;
private ILogger _logger = NullLogger.Instance;
public ILogger Logger
{
get { return _logger; }
set { _logger = value; }
}
public ActionResult Send()
{
_logger.Info("In Send method");
...
}
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
See http://nlog-project.org/wiki/Configuration_file
for information on customizing logging rules and outputs.
-->
<targets>
<!-- add your targets here -->
@DavidSSL
DavidSSL / Semantic comparison test
Last active December 16, 2015 09:19
Correct implementation of Parser Test
[Theory, AutoFixture]
public void ParseValidInputShouldReturnCorrectResult(
PatientReportParser sut)
{
const string argsString = @"-o=C:\Temp\someFile -p=1 -d";
var args = new string[0];
IResult actualResult = null;
var expectedResult =
new Likeness<CreateReportResult, CreateReportResult>(new CreateReportResult(@"C:\Temp\someFile", "1", "database"));
@DavidSSL
DavidSSL / IResultTest
Created April 18, 2013 10:42
Problem IResult
[Theory, AutoFixture]
public void ParseValidInputShouldReturnCorrectResult(
PatientReportParser sut)
{
const string argsString = @"-o=C:\Temp\someFile -p=1 -d";
var args = new string[0];
IResult actualResult = null;
"Given valid arguments"
.Given(() => args = argsString.Split(' '));
@DavidSSL
DavidSSL / IResult
Created April 18, 2013 10:32
Illustatres how SemanticComparison helps with keeping code clean
public interface IResult
{
void Execute();
}
public class ErrorResult : IResult
{
public void Execute()
{
// Does something
public static void Main()
{
// 1. Instantiate the IWindsor container object
var container = new WindsorContainer();
// 2. Register the services and the respective components that implement them
container.Register(Types
.FromAssemblyContaining<HttpFileDownloader>
.BasedOn<IHtmlTitleRetriever>());
);
// 3. "Resolve" the root service