Created
August 16, 2011 12:31
-
-
Save AlexZeitler/1148962 to your computer and use it in GitHub Desktop.
Inheritance of BehaviorConfigs for machine.fakes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Machine.Fakes; | |
using Machine.Specifications; | |
namespace BehaviorConfigInheritance { | |
public class Given_a_car_when_starting_it : WithSubject<Car> { | |
static string _sound; | |
Establish context = () => | |
{ | |
//With(new EngineLoaded(300)); | |
With<EngineWith300PSLoaded>(); | |
}; | |
Because of = () => { _sound = Subject.Start(); }; | |
It should_roar = () => { _sound.ShouldEqual("roar"); }; | |
} | |
public class Car { | |
readonly IEngine _engine; | |
public Car(IEngine engine) { | |
_engine = engine; | |
} | |
public string Start() { | |
if (_engine.Power >= 300) { | |
return "roar"; | |
} | |
return "whisper"; | |
} | |
} | |
public interface IEngine { | |
int Power { get; } | |
} | |
public class EngineLoaded { | |
static int _horsePower; | |
public EngineLoaded(int horsePower) { | |
_horsePower = horsePower; | |
} | |
OnEstablish context = | |
OnEstablish; | |
public static void OnEstablish(IFakeAccessor fakeAccessor) { | |
IEngine eninge = new Engine(_horsePower); | |
fakeAccessor.Configure(c => c.For<IEngine>().Use(eninge)); | |
} | |
} | |
public class Engine : IEngine { | |
public Engine(int power) { | |
Power = power; | |
} | |
public int Power { get; private set; } | |
} | |
public class EngineWith300PSLoaded : EngineLoaded { | |
public EngineWith300PSLoaded() : base(300) { | |
} | |
OnEstablish context = EngineLoaded.OnEstablish; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment