Geeks With Blogs

News Infragistics JQuery Advertisement
----------------
profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers

Check out Elapser from T3rse!
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
And then listen to Francis Chan speaking at LifeLight in SD.
Programming and Learning from SD Unit Testing
MVC Validation of a Password with a Regular Expression
I have requirement (specification) that the password has to be at least 7 characters long and contain a special character (~@#$&*()-_+=) which are all the specials in the number keyboard row. I found that using the RegularExpression DataAnnotations is really slick, but there was a point that caught me for a while. The problem is that @".*([!@#$&*()-_+=]+).*$" works in the UI, but fails in the unit test. @"[!@#$&*()-_+=]+" works in the test, but not in the UI (the MVC unobtrusive library ......

Posted On Friday, April 26, 2013 11:16 AM

Jasmine Specification Testing Pointers
I’ve been using Jasmine JavaScript testing library for Behavior Driven Development testing the last few months with KnockoutJs view models and the Revealing Module Pattern. We now have 244 specs on a system that will be around and hopefully expand. I was hired to get it going, then others will maintain it and add to it after I’m gone. They have helped me think through what needs to happen (when {X} it should do this), test functionality with out having to click through things and help stop me from ......

Posted On Friday, April 5, 2013 3:18 PM

Making jQuery UI Droppable Testable
I’m using jQuery UI’s droppable for drag and drop capabilities. I wanted to be able to test it with Jasmine, but I couldn’t find a way to mock it. I found Jasmine jQuery, but wasn’t able to figure out how to spyOn or mock $('#jQueryElement').droppab... accept: function (d) { return accept(d); }, drop: function (event, ui) { drop(event, ui); } }); So I created a wrapper for this function. I’ve found that creating wrappers is an easy way to make things testable and to remove coupling to libraries ......

Posted On Tuesday, March 26, 2013 9:47 AM

Use the bind method for Jasmine toThrow Tests
Thanks to Danyal Aytekin for his Stackoverflow answer. If you want to use the toThrow in Jasmin tests on actual functions, you can use the “Function.bind, which was introduced in JavaScript 1.8.5. This works in the latest versions of Chrome and Firefox, and you can patch other browsers by defining the function yourself.” From his answer:describe('using bind with jasmine', function() { var f = function(x) { if(x === 2) { throw new Error(); } } it('lets us avoid using an anonymous function', function() ......

Posted On Thursday, March 21, 2013 2:11 PM

FakeItEasy - Sealed Methods can not be intercepted exception
I was trying to do a partial mock in FakeItEasy and kept getting "The current proxy generator can not intercept the specified method for the following reason: - Sealed methods can not be intercepted".The fix is to make the method virtual. (notice the A.Fake<LayoutManager>, not A.Fake<ILayoutManager> for the partial mock) var layoutManagerFake = A.Fake<LayoutManager>(); A.CallTo(() => layoutManagerFake.UpdateAss... assigned, "user")).CallsBaseMethod(); In LayoutManager (note ......

Posted On Tuesday, March 12, 2013 3:09 PM

WebAPI Dependency Injection
If you try to dependency injection into a constructor with WebAPI, you’ll get an exception that says you need a parameter less constructor. The same is true for MVC controllers, but that is a different topic. Microsoft contains a good guide on how to get this working. There is also a useful StructureMap.DependencyReso... nuget package by statish860 that does it for you. Get the nuget package, then add GlobalConfiguration.Configu... = new DependencyResolver(ObjectFa... ......

Posted On Friday, December 14, 2012 10:29 AM

Specification Test for the Authorized Attribute in MVC
I wanted to Unit Test (in BDD I’d call it a specification) that the controller had the authorize attribute so I found this approach in a GoodSearch a while back and forgotten who to give credit for it, but I thought I’d post it, so I won’t have to search for it next time. I put this in a base class and it’s been very useful. EDIT: March 21st, 2013 I added a way to also verify the correct roles are in the attribute. This is especially nice, sine the attribute takes strings. [Authorize(Roles = "Super ......

Posted On Friday, March 15, 2013 1:27 PM

Mocking or Faking DbSet
I needed to Fake the DbSet of a DBContext in EF 5 so that I could test my caching implementation. I searched for awhile and found this link on creating an in memory DbSet. I first copied the code in and created an InMemoryDbSet class. Then I changed all my DbSets in my DBContext to IDbSet. Then I was able to mock the call to UserProfiles and return a dummy object. The Test I’m using FakeItEasy which is a nuget packages. Notice the usage of the InMemoryDbSet<UserProfil... [TestInitialize] public ......

Posted On Wednesday, December 12, 2012 11:14 AM

Get a new instance with StructureMap
It took me too long to figure this out, so hopefully it will help you. StructureMap has way that will create a new instance of the object every time, instead of storing this in the container. I’m going to use this for the DBContext and for WCF Service references. Since the ObjectFactory is a static class, MVC will have these stored in memory without this. Credit goes to Joshua Flanagan for answering my question.[TestMethod] public void GetConcreteInstanceOf_Shoul... { ObjectFactory.Initialize(re... ......

Posted On Thursday, November 29, 2012 10:44 AM

Copyright © Aligned | Powered by: GeeksWithBlogs.net | Join free