FluentAssertions - complete tutorial for creating custom assertions - fluent-assertions

Has anybody seen a complete tutorial for creating custom assertion classes with FluentAssertions?
Best regards

I maintain a couple of extension packages for Fluent Assertions, so feel free to take a look at our code to see how we do it:
FluentAssertions.Mvc
FluentAssertions.Ioc.Ninjet
I also recently contributed the assembly reference assertions to the core, so have a look at this pull request. Also have a look at the FA source to see how they implement similar assertions (that's where we started).
The top line is you'll need a class to hold your assertions and an extension method to hook it in.

Related

Migration from 0.9.5 to 1.0.1 - ScriptBridge class equivalent

We would like to move our api test created using karate framework to karate framework 1.0.1. I see that there is no such class as ScriptBridge which is used by us to attach screenshots and get information about test status, tags of currently running scenario.
What is the equivalent for the ScriptBridge class?
My question is related with Attaching screenshots to json report where I asked how to attach screenshots to report.
Short answer to your question, the class you are looking for is ScenarioBridge.
But the HTML reporting has been overhauled and hopefully you will be able to achieve what you need without hacking into internal classes. There is a somewhat undocumented doc keyword, you will find an example in the link below. If you feel helpers for handling images need to be part of Karate, do contribute or suggest a feature request.
Please read this: https://stackoverflow.com/a/66822585/143475

Is mocking functionality available for Microsoft Fakes?

With the inclusion of Microsoft Fakes in Visual Studio 11, I thought it would be worth to look into again, since I did not find Moles mature enough last i checked. The documentation is still sparse, but I cannot find any reference to mocks, i.e. the ability to set up and verify expectations on the faked objects.
Does anyone know if this is currently included (as a feature in the library) or will be?
It is not included currently, but we are considering something in this area.
Although they are not included, you can use stubs to hack in the same behavior. In your stub you can capture whether the method was called and the parameters that were called. Of course, by the time you start doing that you're almost hand rolling your own mocks.
In the meantime I'd suggest Moq or RhinoMocks. I find the syntax simpler and I'm not a fan of the generated code that Microsoft Fakes uses anyhow. Try renaming a method on one of your fakes using a refactoring tool. It's not possible because your fake is a generated class, not an instance of the interface you are stubbing.

Where can I find up-to-date documentation about the WCF Web API?

I've been strugling with WCF to do REST the way I want it to work. And apparently so has quite a few others. I've heard about the WCF Web Api project, but wrongly dismissed it without looking too closely at it. Sadly, now that I'm looking at it I find that the documentation is rather outdated. Like, this blog post has some nice information, but classes have changed, parameters have changed, in short, design has changed.
So I've been using an old example of how to plug in Json.NET (newtonsoft) as my serializier, only to realize that after I had it working, it wouldn't work for my IErrorHandler. Further I had a problem with how to Deserialize a string from the uri template to an operation Type parameter.
It appears however that I should be able to solve these two problems (and presumably many others that I haven't stumbled over yet) by using the media formatter extension point and what's referred to as Processor<..>s in outdated documentation, which is now HttpOperationHandler<..>s unless I've missunderstood.
My problem is rather basic, I can't figure out how to correctly configure my IIS-hosted app to use my operation handler, assuming I've implemented it correctly. Since it feels rather dumb to ask for instructions on such a basic thing, I'll rather ask where I can find some documentation on how to do this sort of thing? (Explanations are welcome of course.)
I'm not after seing which classes exist, or what their methods are named with what parameters. I can see all that in my object browser. I need documentation for the overall design, and/or examples implicitly describing things like:
How do the different classes in the API fit together?
How can I configure from web.config?
Must I rather do a custom HttpServiceHostFactory?
What and how are you meant to use the framework?
How should I extend to reach what sort of goals?
How should I configure to place the extensions in effect?
From the lack of answers I assume the documentation quite simply isn't ready.
I was looking for it on the codeplex site under the Documentation tab, and found outdated stuff.
However, after familiarizing myself a bit with Codeplex I found out that the good stuff was in this Discussion section. Searching a bit in there helped a lot to be honest.
Concerning config-file configuration, I didn't find anything, so I'm assuming this will be added as the last thing before official release. Meaning I'll use the HttpConfiguration in a custom HttpServiceHostFactory for now.
The trick about the HttpOperationHandlers was twofold: Firstly I was throwing an exception in my operation and hadn't implemented a global HttpErrorHandler yet. (Doh!) Secondly I didn't know that the parameter name of HttpOperationHandler<..>.OnHandle had to match the name of the operation parameter.

Need Method Entry and Exit event in .net

I like to have event like OnMethodEntry and OnMethodExit which will be used to raise an event when a method in a class is getting invoked in C#.NET.
I have seen Post Sharp which give this feature. Since it is third party tool, we like to design a library something similar to that.
How can I do that?
Thanks,
P.Gopalakrishnan.
CodeProject has a nice article that I think will meet your needs: MethodLogger - Hook into method calls in .NET binaries.
One way to do this is to modify assemblies by inserting these method calls manually in the IL.
You may try Cecil or CCI. They are good and mature libraries for reading and patching assemblies.

How do I get access to Castle Windsor's Fluent Interfaces API?

I've been having tons of problems getting the non-xml configuration for Castle Windsor set up working properly. In the meantime I've seen more and more people giving advice via the Windsor Container fluent interface. I've been Gooogling about for the last day and I cannot find this API anywhere.
I am talking about the key .Register() method which seems to be an extension method to the IWindsorContainer object. It seems like it might be in the Castle.MicroKernel.Registration namespace, but I cannot find the corresponding library anywhere!
Also, is there any place where I can find documentation for this stuff?
EDIT:
I found that the copy of Castle.MicroKernel in the sample project here has more namespaces then the one I was using (even though this one is eight days older and v1.0.0 whereas mine is v1.0.3...), still having trouble finding the .Register() method or any samples though.
EDIT:
I found some fluent interface samples at Bitter Coder, no downloadable samples though so I'm still at a loss.
Edit Again: Finally got it. The most recent source code for castle windsor is available here, get the most recent successful build, inside the zip file is a bin directory. The fluent interface is inside Castle.Microkernel (you will probably need to reference Castle.Dynaproxy, Castle.Dynaproxy2 and Castle.Windsor too).
PS This post is the #1 Google result for "castle fluent interface documentation" sad guys, you need to get on that. Crickets chirp What's that? Fine. Let me figure this out then I'll get on it then.
The Fluent interfaces were introduced a while ago - but are only available on Trunk (after RC3) either grab the castles sources (from the projects subversion repository) and build the IoC projects yourself from here, or easier still grab the latest successful build on the continuous integration server and use that.
Castle.MicroKernel.Registration is the name space you'll need to use, in the MicroKernel assembly - once you have a reasonably fresh build of Castle you should be able to find Register(...) methods on both IKernel and IWindsorContainer interfaces, allowing the application of "registration components" (anything which implements IRegistration) which includes the various fluent component registration features in Castle, as well as anything custom you might develop.
The best place to ask questions regarding Castle is the google castle-project-users and castle-project-devel groups - keep an eye out for Craig Neuwirt in particular as he's the core developer working on the fluent interface features in Castle Windsor, and so is best equipped to answer questions about the various fluent interface features, as they are not widely documented yet.
Ok, so just for reference. Official, complete documentation for the API is on Castle Windsor Documentation Wiki