Hi all
Just wanted to announce that I've released a beta-version of my WCF Extensions Library on my CodePlex project called Renewal Projects. Check out the documentation section for more info. I think WCF users in the .NET space may want to have a look at this as it might prove useful in the long run as it contains a Channel Repository, Channel Pool and the possibility to have WCF channels hosted in a IOC container.
Its in BETA at the moment but testers are welcome to try it out.
http://renewalprojects.codeplex.com/
LA's Blog
Lessons, knowledge snippets and personal growth, all fine tuned by God's hands and redeemed through Christ's work on the cross for all to see and share.
Wednesday, November 09, 2011
Wednesday, November 02, 2011
MVC 2 Hidden Helper Extension
I don't know if you've ever needed to store an entire entity object inside a html page using the hidden form fields but for some reason the standard ASP.NET MVC HiddenFor() method doesn't do that. It only seems to work for simple data types such as ints and strings, etc.
So I wrote a little helper method to do just that.
It takes all the entity that you wish to store in your HTML page and iterates over each property and performs a Hidden() method call on them to ensure that all its properties are encoded as hidden fields so that it gets passed back to the Controller Action via the POST method.
So I wrote a little helper method to do just that.
It takes all the entity that you wish to store in your HTML page and iterates over each property and performs a Hidden() method call on them to ensure that all its properties are encoded as hidden fields so that it gets passed back to the Controller Action via the POST method.
public static MvcHtmlString HiddenEntirelyFor<TModel, TResult> (this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TResult>> expression)
{
ModelMetadata modelMetadata =
ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
List<string> htmlEntries =
modelMetadata.Properties
.Select(property => htmlHelper.Hidden(ExpressionHelper.GetExpressionText(expression) + "." + property.PropertyName, property.Model, null))
.Select(mvcHtmlString => mvcHtmlString.ToHtmlString())
.ToList();
return MvcHtmlString.Create(String.Join(Environment.NewLine, htmlEntries.ToArray()));
}
Monday, September 05, 2011
Moles with Mocking capability
Myself and a colleague of mine made a discovery when we started to do some unit test coding with moles that it doesn't have any expectation-functionality like Rhino mocks where you can specify what the incoming parameter values should be for a mocked-class.
That's when I did some searching on the web for mocking frameworks which might complement the Moles tool-set. I came across this library: http://simpledotnet.codeplex.com
It's not the best out there but it does feature one thing that other mocking frameworks (and correct me if I'm wrong) doesn't have and that is delegate mocking. I told my colleague about it and he tried it out... and it worked! It makes coding less and improves readability.
Now suppose you have a class ClassX that you want to mock.
Now with Moles you can only stub the target type by substituting the behavior with delegates.
With Simple.Net, you first create the expectation scope:
Then you can create the mock-delegate:
Now we stub the target class with the mock:
Now you set some expectations:
Run your system under test code:
Verify expectations are met:
And now your test should succeed. Please check out the Simple.NET website to see how this mocking framework works.
Hope this helped someone.
That's when I did some searching on the web for mocking frameworks which might complement the Moles tool-set. I came across this library: http://simpledotnet.codeplex.com
It's not the best out there but it does feature one thing that other mocking frameworks (and correct me if I'm wrong) doesn't have and that is delegate mocking. I told my colleague about it and he tried it out... and it worked! It makes coding less and improves readability.
Now suppose you have a class ClassX that you want to mock.
Now with Moles you can only stub the target type by substituting the behavior with delegates.
With Simple.Net, you first create the expectation scope:
var expectationScope = new ExpectationScope();
Then you can create the mock-delegate:
var getNameMock = Mock.Delegate<MolesDelegates.Func<ClassX, string>>();
Now we stub the target class with the mock:
MClassX.AllInstances.GetName = getNameMock;
Now you set some expectations:
Expect.Exaclty(1).MethodCall(() => getNameMock(Any<ClassX>.Value)).Returns("Fred");
Run your system under test code:
ClassX x = new ClassX();
Assert.AreEqual("Fred",x.GetName());
Verify expectations are met:
AssertExpectations.IsMetFor(expectationScope); And now your test should succeed. Please check out the Simple.NET website to see how this mocking framework works.
Hope this helped someone.
Friday, September 02, 2011
Renewal Projects first release
Hi there all.
I have been working on my own open-source project for a while now. Its actually going to be a collection of projects but I think you get the idea. I have released my first .NET assemblies on CodePlex (http://renewalprojects.codeplex.com):
I have been working on my own open-source project for a while now. Its actually going to be a collection of projects but I think you get the idea. I have released my first .NET assemblies on CodePlex (http://renewalprojects.codeplex.com):
- .NET Encrypted Configuration Viewer
- ParamGate application parameter handling library
Subscribe to:
Posts (Atom)