Skip to content

Instantly share code, notes, and snippets.

View erikdietrich's full-sized avatar

Erik Dietrich erikdietrich

View GitHub Profile
@erikdietrich
erikdietrich / IntegrationTest.cs
Created November 8, 2012 20:14
The Integration Tests for the bowling calculator
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ScratchPadTest
{
[TestClass]
public class IntegrationTest
{
@erikdietrich
erikdietrich / ExtendedAssert.cs
Created November 8, 2012 20:15
Extended Assert class I wrote a long time ago when I was coming from NUnit to MSTest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ScratchPadTest
{
public static class ExtendedAssert
@erikdietrich
erikdietrich / MainWindow.xaml
Created November 14, 2012 06:56
XAML for the window with a combo box.
<Window x:Class="WpfScratchpad.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<ComboBox Width="150" ItemsSource="{Binding Options}" DropDownOpened="HandleDropDownOpened" SelectedIndex="0" IsEditable="False" />
<Button Content="Exit" Click="HandleButtonClick" HorizontalAlignment="Left" Margin="334,256,0,0" VerticalAlignment="Top" Width="75"/>
</StackPanel>
</Window>
@erikdietrich
erikdietrich / MainWindow.xaml.cs
Created November 14, 2012 06:57
Code behind for the main window
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
@erikdietrich
erikdietrich / MainWindowViewModel.cs
Created November 14, 2012 06:59
View model for the main window, including combo box item logic
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace WpfScratchpad
{
@erikdietrich
erikdietrich / Readability2.cs
Created November 7, 2015 20:51
The second installment of the experiment is about cyclomatic complexity.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeReadability
{
public class CyclomaticComplexity
{
public static ISetup<T, TResult> Setup<T, TResult>(this T mock, Expression<Func<T, TResult>> expression) where T : class
{
return Mock.Get(mock).Setup(expression);
}
public static void Verify<T, TResult>(this T mock, Expression<Func<T, TResult>> expression) where T : class
{
Mock.Get(mock).Verify(expression);
}
@erikdietrich
erikdietrich / MockGet.cs
Last active December 14, 2015 00:19
Demonstration of the Mock/regular conflict in Moq
private ISomeService Service { get; set; }
[TestMethod, Owner("ebd"), TestCategory("Proven"), TestCategory("Unit")]
public void SomeTest()
{
Service = Mock.Of<ISomeService>();
//I want to inject it as if it were just some service
Target = new SomeClassUnderTest(Service);
private ISomeService Service { get; set; }
[TestMethod, Owner("ebd"), TestCategory("Proven"), TestCategory("Unit")]
public void SomeTest()
{
//I want to inject it as if it were just some service
Target = new ContractUpdater(Service);
//And set it up more intuitively
Service.Setup(serv => serv.Create(It.IsAny<Service>())).Throws(new Exception());
public class SomeClass
{
private readonly List<Customer> _customers = new List<Customer>();
public void AddCustomerForModelIfValid(CustomerModel modelOfCustomer)
{
if (IsModelValidForAdding(modelOfCustomer))
AddCustomerForModel(modelOfCustomer);
}