Skip to content

Instantly share code, notes, and snippets.

View AlexZeitler's full-sized avatar
👷‍♂️
Building stuff

Alexander Zeitler AlexZeitler

👷‍♂️
Building stuff
View GitHub Profile
@AlexZeitler
AlexZeitler / ideas for grouping BDD items using VsCommands
Created June 29, 2010 14:01
my thoughts on grouping #bdd items using #vscommands - any other ideas?
Bar.cs
+-BarSpecs.cs
Foo.cs
+- FooSpecs.cs
vs.
Bar.cs
BarSpecs.cs (with common Bar related IBehaviorConfigs)
+- when_bar_has_this.cs
C:\Users\AZeitler\Desktop\xunitbddextensions>powershell -Command "& {Import-Modu
le .\psake.psm1; Invoke-psake .\default.ps1}"
Executing task: Clean
Executing task: Init
fatal: Not a git repository (or any of the parent directories): .git
default.ps1:You cannot call a method on a null-valued expression.
C:\Users\AZeitler\Desktop\xunitbddextensions>Pause
Press any key to continue . . .
// Concern
protected override void Because() {
_actualDependencyModel = Sut.Resolve(); // "root" of AssemblyHasTwoPartDependencies / EstablishContext should be passed to Resolve
}
// Dependency
public class AssemblyHasTwoPartDependencies : IBehaviorConfig {
public void EstablishContext(IDependencyAccessor accessor) {
IConfiguration activeRootConfiguration = accessor.An<IConfiguration>();
public class LightSwitchedOff : IBehaviorConfig {
public void EstablishContext(IDependencyAccessor accessor) {
accessor.The<ILight>().WhenToldTo(l => l.LightState).Return(LightState.Off).Repeat.Once();
accessor.The<ILight>().WhenToldTo
(l => l.SwitchLight(LightState.On)).Do(
new Func<object, LightSwitchedHandlerArgs, int>((sender1, args1) =>
{
accessor.The<ILight>()
@AlexZeitler
AlexZeitler / gist:798238
Created January 27, 2011 08:29
BDD Learning Tests mit BehaviorConfigs
Ich habe ein COM Interop Szenario. Um das Verhalten des API kennen zu lernen, habe ich Learning Tests / Specs geschrieben, die aber eine OLE-Verbindung zur laufenden App benötigen.
Es müssen z.B. Dokumente in der App geladen werden. Da häufig gleiche Dokumente benötigt werden, sollen diese in BehaviorConfigs ausgelagert werden. Da die BehaviorConfigs teilweise voneinander abhängen (schlecht, aber derzeit nicht anders lösbar), muß EstablishContext der jeweiligen BehaviorConfig vor dem Instanzieren der nächsten BehaviorConfig erledigt sein.
public class EmptyAssemblyAsActiveDocument : IBehaviorConfig {
public void EstablishContext(IDependencyAccessor accessor) {
string applicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string tempFolder = Path.Combine(applicationDataFolder, "Temp");
DirectoryInfo directoryInfo = new DirectoryInfo(tempFolder);
if (!directoryInfo.Exists) {
@AlexZeitler
AlexZeitler / Failing Spec
Created February 21, 2011 14:00
Why does this always fail?
using System;
using SolidWorks.Interop.sldworks;
using Xunit;
namespace SolidTp.SolidWorks.Domain.Tests {
[Concern(typeof (IEquationManagerWriter))]
public class Wenn_eine_variablendefinition_im_modell_aktualisiert_werden_soll_ : InstanceContextSpecification<IEquationManagerWriter> {
private string _variableDefinitionAsEquation;
protected override void EstablishContext() {
@AlexZeitler
AlexZeitler / gist:917497
Created April 13, 2011 13:04
Configuring the The<>() directly
Running the tests results in "System.InvalidOperationException:
The result for IContactRepository.Get(1); has already been setup."
When creating An<IContactRepository> and assigning it by fakeAccessor.Use(), it does work.
public class When_requesting_alex_from_contact_service : WithSubject<ContactService> {
static Contact _contact;
static IContact _actualContact;
Establish context = () => {
@AlexZeitler
AlexZeitler / gist:923466
Created April 16, 2011 20:30
mfakes, StructureMap and COM...
Establish context = () => {
With<SolidWorks2010OleConnected>();
_solidWorks = The<ISolidWorks>();
}
public class SolidWorks2010OleConnected {
OnEstablish context =
fakeAccessor =>
{
ISldWorks solidWorks =
@AlexZeitler
AlexZeitler / gist:925015
Created April 18, 2011 08:46
SolidWorks and StructureMap RhinoAutoMocker
public class When_putting_a_real_solidworks_instance_into_a_mock {
static ISldWorks _solidWorks;
static IModelDoc2 _model;
static Exception _exception;
static RhinoAutoMocker<ModelReader> _mocks;
Establish context
= () =>
{
@AlexZeitler
AlexZeitler / gist:926928
Created April 19, 2011 06:51
Passing params into BehaviorConfigs by With<T> in Machine.Fakes
How about having
Establish context = () => With<CurrentTime>().UsingParams(new DateTime(2011,2,14));
instead of
Establish context = () => With(new CurrentTime(new DateTime(2011, 2, 14)));
I think it would enable a more consistent manner of reading when using more than one behavior config.
Might be nitpicking, though ;-)