Skip to content

Instantly share code, notes, and snippets.

View HEskandari's full-sized avatar

Hadi Eskandari HEskandari

View GitHub Profile
@HEskandari
HEskandari / NH Jet Driver Test
Created March 26, 2011 08:51
Testing Saving of Decimal/Double Values
[Test]
public void Decimal_Values_Are_Not_Truncated_Once_Saved()
{
var entity = new DecimalEntity
{
SimpleDecimal = 1.1m,
SimpleDouble = 1.2d,
NullableDecimal = 1.3m,
NullableDouble = 1.4d
};
@HEskandari
HEskandari / DataCache.cs
Created May 26, 2011 06:45
Abstracted Async model in Silverlight 4.0
public IEnumerable<IResult> LoadLookupCache()
{
yield return ProgressResult.Show("Loading Cache...");
var masterDataService = new MasterDataServiceClient();
var therapyService = new TherapyServiceClient();
masterDataService.getAllHealthFundsCompleted += (o, e) => _serviceHandler.AddTo(e, _lookups.HealthFunds);
masterDataService.getAllPatientCompleted += (o, e) => _serviceHandler.AddTo(e, _lookups.Patients);
therapyService.getTherapyTypesCompleted += (o, e) => _serviceHandler.AddTo(e, _lookups.TherapyTemplateTypes).Apply(x => x.Type = TemplateTypes.Therapy);
@HEskandari
HEskandari / Parser.cs
Created June 11, 2011 07:40
Parser Magic
protected static short[] yyTable = { 31,
19, 15, 72, 32, 70, 73, 112, 69, 113, 47,
3, 4, 67, 66, 33, 65, 69, 68, 92, 18,
93, 67, 69, 64, 34, 43, 68, 67, 66, 35,
65, 74, 68, 123, 75, 36, 124, 19, 19, 30,
87, 19, 19, 19, 19, 19, 37, 19, 114, 71,
2, 3, 4, 5, 6, 7, 18, 18, 15, 19,
18, 18, 18, 18, 18, 136, 18, 113, 48, 3,
4, 26, 38, 140, 26, 113, 30, 30, 18, 63,
30, 30, 30, 30, 30, 27, 30, 67, 27, 68,
@HEskandari
HEskandari / XmlDecoderTests.cs
Created July 6, 2011 18:39
Decoding string to dynamic and static objects (part of EasyHttp project)
[TestFixture]
public class XmlDecoderTests
{
[Test]
public void can_decode_xml_response_as_static_object()
{
IDecoder decoder = new XmlDecoder();
var xml = GetXmlContent();
var customer = decoder.DecodeToStatic<Customer>(xml, HttpContentTypes.ApplicationXml);
@HEskandari
HEskandari / DefaultDecoderTests.cs
Created July 25, 2011 11:37
Failing test when deserializing xml content
[TestFixture]
public class DefaultDecoderTests
{
[Test]
public void XmlAttributes_Are_Not_Converted_To_Elements()
{
var customerRaw = @"<Customer Mode=""Add"">
<CustomerNo>02121V</CustomerNo>
</Customer>";
@HEskandari
HEskandari / API Usage
Created September 29, 2011 19:50
Async Abstraction Usage
public IEnumerable<IResult> LoadReport(int reportId)
{
yield return Display.Busy();
var service = new ReportingServiceClient();
yield return Display.ChangeStatus("Preparing Reports...");
yield return new WebServiceResult().Invoke(service.PrepareReports);
@HEskandari
HEskandari / PixleFormat enum
Created October 11, 2011 11:40
PixelFormat enum in GDI+
namespace System.Drawing.Imaging
{
public enum PixelFormat
{
DontCare = 0,
Undefined = 0,
Max = 15,
Indexed = 65536,
Gdi = 131072,
Format16bppRgb555 = 135173,
@HEskandari
HEskandari / ComponentsWithTypedFactoryTestCase.cs
Created January 11, 2012 07:30
Failing test for Windsor 3.0
// Copyright 2004-2012 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@HEskandari
HEskandari / ExceptionHandler.cs
Created April 20, 2012 06:11
Exception Handler? Or Thrower?
public ActionResult HandleException()
{
return HandleException(new Exception("An Exception Has Occurred"));
}
public ActionResult HandleException(Exception ex)
{
throw ex;
}
[TestFixture]
public class MockingAsyncTask
{
[Test]
public async void can_mock_interface_methods_with_task_return()
{
var mock = NSubstitute.Substitute.For<ILongRunningOperation>();
var sut = new SystemUnderTest {Operaiton = mock};
await sut.Execute();