Created
April 18, 2011 08:46
-
-
Save AlexZeitler/925015 to your computer and use it in GitHub Desktop.
SolidWorks and StructureMap RhinoAutoMocker
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
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 | |
= () => | |
{ | |
_mocks = new RhinoAutoMocker<ModelReader>(); | |
_mocks.Inject(new SolidWorksOleConnector().Connect(new SolidWorksVersion2010())); | |
}; | |
Because of | |
= () => { | |
_exception = Catch.Exception(() | |
=> new ModelReader((ISldWorks) _mocks.Container.GetInstance(typeof(ISldWorks)))); | |
}; | |
It should_not_throw_an_exception | |
= () => { _exception.ShouldBeNull(); }; | |
It should_return_the_active_modeldoc | |
= () => { _model.ShouldNotBeNull(); }; | |
} | |
public class ModelReader { | |
readonly ISldWorks _solidWorks; | |
public ModelReader(ISldWorks solidWorks) { | |
_solidWorks = solidWorks; | |
} | |
} |
Then this is your lucky day. This will be the default model in the next version of mfakes which will be released this week ;-)
fixed the Because to:
_exception = Catch.Exception(()=> _modelReader = _container.GetInstance<ModelReader>());
still green.
w00t! ;-) Thank you, mate!
Something went wrong:
public class When_putting_a_concrete_solidworks_instance_into_a_mock : WithSubject<ModelReader> {
static ISldWorks _solidWorks;
static IModelDoc2 _model;
static Exception _exception;
static ModelReader _modelReader;
Establish context
= () =>
{
Configure(config =>
config.For<ISldWorks>()
.Use(new SolidWorksOleConnector()
.Connect(new SolidWorksVersion2010())));
};
Because of
= () => {
_document = Subject.Document;
};
It should_return_the_active_modeldoc
= () => { _modelReader.Document.ShouldNotBeNull(); };
static IModelDoc2 _document;
}
throws the exception again...
Use the lambda based factory as in the SM example. This should work
Configure(config =>
config.For<ISldWorks>()
.Use(() => new SolidWorksOleConnector() //<! ----------------------
.Connect(new SolidWorksVersion2010())));
sorry, missed that due to hurried work ;-)
works like a charme now - thanks again.
You're welcome!
…On Montag, 18. April 2011 at 15:01, AlexZeitler wrote:
sorry, missed that due to hurried work ;-)
works like a charme now - thanks again.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/925015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the snippet had some errors, modified it this way to make it run:
_container = new Container(x => x.For<ISldWorks>().Use(() => new SolidWorksOleConnector().Connect(new SolidWorksVersion2010())));
Because of
= () =>
{
_exception = Catch.Exception(()=> _modelReader = new ModelReader(_container.GetInstance<ISldWorks>()));
};
All tests green now.