Skip to content

Instantly share code, notes, and snippets.

@scichelli
scichelli / ExpectedObjects_ShouldEqual_vs_ShouldMatch_with_partial_objects.cs
Created July 5, 2011 21:02
First two fail (as expected), but with an unexpected error message, e.g., "For Customer, expected <>f__AnonymousType3`1[System.String]:[{ Name = Expected Name }] but found ExpectedObjectsAssertions.Customer."
[TestFixture]
public class When_testing_equivalence_or_matching_for_partially_supplied_properties
{
private const string ExpectedName = "Expected Name";
private Customer _actual;
private ExpectedObject _expected;
[Test]
public void Should_flag_extra_properties_on_actual_object_as_unequal()
{
@scichelli
scichelli / JsRunningTimerBefore.js
Created November 28, 2011 23:47
JS RunningTimer, before refactoring
$('.runDisplay').hide();
var RT = {
setup : {},
warmupDuration : 5,
cooldownDuration : 5
};
var runProgram = function() {
RT.setup = readSetup();
@scichelli
scichelli / jsModuleMocking.html
Created December 17, 2011 22:00
Replacing behavior in JS modules (for test doubles)
<html><body><script type="text/javascript">
var myController = function() {
var ui = function() {
var show = function(message) {
alert("original: " + message);
}
return { show : show }
}();
@scichelli
scichelli / UsingWhereAndCount.cs
Created February 20, 2012 23:09
LINQ: testing .Count() > 0, which could be replaced with .Any()
bool hasMissedDeadlines = deliverables
.Where(d => d.Deadline < _systemClock.Today)
.Count() > 0;
@scichelli
scichelli / UsingAny.cs
Created February 20, 2012 23:30
LINQ: .Any() to the rescue
bool hasMissedDeadlines = deliverables
.Any(d => d.Deadline < _systemClock.Today);
@scichelli
scichelli / UsingWhereAndCount.cs
Created February 21, 2012 16:21
LINQ: testing .Count() > 0, which could be replaced with .Any()
bool hasMissedDeadlines = deliverables
.Where(d => d.Deadline < _systemClock.Today)
.Count() > 0;
@scichelli
scichelli / UsingAny.cs
Created February 21, 2012 16:21
LINQ: .Any() to the rescue
bool hasMissedDeadlines = deliverables
.Any(d => d.Deadline < _systemClock.Today);
@scichelli
scichelli / BindingOutputError.txt
Created March 27, 2012 14:49
XAML binding to an object
A breakpoint in my Value Converter is never hit. Here's an excerpt of my Output window:
System.Windows.Data Warning: 68 : BindingExpression (hash=22895473): Found data context element: Image (hash=23663325) (OK)
System.Windows.Data Warning: 76 : BindingExpression (hash=22895473): Activate with root item OperatingRoomCase (hash=12289189)
System.Windows.Data Error: 40 : BindingExpression path error: '' property not found on 'current item of collection' ''OperatingRoomCase' (HashCode=12289189)'. BindingExpression:Path=/; DataItem='OperatingRoomCase' (HashCode=12289189); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource')
System.Windows.Data Warning: 78 : BindingExpression (hash=22895473): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=22895473): TransferValue - using fallback/default value <null>
System.Windows.Data Warning: 87 : BindingExpression (hash=22895473): TransferValue - using final value <null>
@scichelli
scichelli / BetterCollectionTest.cs
Created October 4, 2012 22:39
Collection Comparison
private void AssertStructure(string[] actualCollection, string[] expectedCollection)
{
var actual = string.Join(",", actualCollection);
var expected = string.Join(",", expectedCollection.Select(s => s == "..." ? ".*" : s)).Replace(",.*", ".*").Replace(".*,", ".*");
Assert.That(actual, Is.StringMatching(expected));
}
@scichelli
scichelli / offscreen.css
Created November 20, 2012 02:57
CSS to hide visible elements while still letting them be read by screenreaders
.offscreen {
position:absolute;
left:-10000px;
top:auto;
width:1px;
height:1px;
overflow:hidden;
}