Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.



Programming and Learning from SD Unit Testing
Karma Test Results with TFS Build
TLDR; 1. Setup the Karma Trx Reporter. 2. Add Publish Results Build Step using ../TestResults/**/karma-tes... as the path. 3. If remote Vm for Jasmine tests, copy the .trx file to the Results directory. Our team has been using JasmineJs for unit testing our client side JavaScript code. We now have over 3,000 tests! In order to run these tests on multiple browsers we useKarma, the "Spectacular Test Runner for JavaScript" created by people from Google to run all our tests on multiple browsers. ......

Posted On Friday, September 16, 2016 7:54 AM

FakeItEasy and EntityFramework
We needed to fake or mock out Entity Framework so that we could test our “service layer” that holds our business logic without hitting a real database. We are using EF as our Repository and skipping all the extra work in creating a repository code layer that only wraps EF. We are ok with being this closely tied to EF. It was difficult to figure out how to fake the context with an interface we made ourselves. We found some helpful Nuget packages, so I decided to share it. EntityFramework.Testing: ......

Posted On Friday, November 20, 2015 9:11 PM

Using Visual Studio Online's new build system to achieve a Continuous Delivery pipeline Presentation
Please visit me and read this article at AlignedDev.I had the honor and pleasure of giving my first presentation at an event at South Dakota Code Camp last weekend on November 7th. Thanks to the organizers and sponsors, I’m looking forward to next year already. I talked about the importance of Continuous Delivery in today’s development practices and how it helps us get quality code to our users quicker and more reliably using automated processes. Microsoft’s build system has improved immensely in ......

Posted On Tuesday, November 10, 2015 4:10 PM

Cleanup your TestResults folder with a Scheduled Task
I run automated UI test with Selenium (unit testing will do this as well, though not as many files) from the Visual Studio Test Explorer a lot. This creates a new folder inside of my solution location named TestResults for every test run. Depending on what I need to deploy for the test (Selenium chrome driver, images, dlls, etc) the size of that it takes up on my hard drive gets very large after a few weeks. I’ve deleted gigs before. In the spirit of “if you do something more than once, automate ......

Posted On Tuesday, January 13, 2015 5:04 PM

Quick Guide to setup a MVC project for Unit Testing
Reposted on my new blog. Come visit me there!A barrier to getting into writing executable tests (Unit Tests, integration tests, automated UI tests, etc) with some people I work with, is not knowing how to get started. I believe the desire and the recognition of the value and importance of this testing is growing, but I want to help people get over that hump. Read the MSDN Unit Testing MVC article. consider splitting controllers into a different project as suggested Don’t put your data access code ......

Posted On Thursday, September 25, 2014 9:18 PM

Checking the Status of a Cloud Service with Azure Management API
We are automatically deploying a package to Azure, then running tests against that instance. See Brady Gaster’s article for more details. I needed a way to make sure the deployment was complete, and if not wait for it. After digging through the objects with Intellisense, we found this solution:public bool IsCloudServiceRunning() { var details = _computeManagementClient.Ho... var deployment = details.Deployments.First(d => d.Name == _parameters.CloudServiceName ......

Posted On Thursday, September 18, 2014 12:37 PM

Dependency Injection Interview Video
In the video from Visual Studio Magazine with Miguel Castro who has some interesting things to say about Dependency Injection and Unit Testing. "It should be mainstream". "no longer do we new objects up, now = new this()". "this [new objects] used to be a no-brainer... until all of a sudden Unit testing hit the world by storm" "#1 reason for this is so we can test properly""You're writing untestable code [without DI]" "I'm a consultant, so I need to leave something maintainable and tested" ~ talking ......

Posted On Thursday, September 19, 2013 4:05 PM

Benefits of Behavior Driven Development
Now posted on aligneddev.netContinuing my previous article on BDD, I wanted to point out some benefits of BDD and since BDD is an extension of Test Driven Development (TDD), you get those as well. I’ll add another article on some possible downsides of this approach. There are many articles about the benefits of TDD and they apply to BDD. I’ve pointed out some here and copied some of the main points for each article, but there are many more including the book The Art of Unit Testing by Roy Osherove. ......

Posted On Friday, July 26, 2013 10:44 AM

Mock the window.setTimeout in a Jasmine test to avoid waiting
Jasmine has a clock mocking feature, but I was unable to make it work in a function that I’m calling and want to test. The example only shows using clock for a setTimeout in the spec tests and I couldn’t find a good example. Here is my current and slightly limited approach. If we have a method we want to test: var test = function(){ var self = this; self.timeoutWasCalled = false; self.testWithTimeout = function(){ window.setTimeout(function(){ self.timeoutWasCalled = true; }, 6000); }; }; Here’s ......

Posted On Thursday, August 21, 2014 4:42 PM

Getting Started with Behavior Driven Development
I've re-posted on my [new blog](https://aligneddev.ne... this post, I wanted to share some thoughts and resources that I’ve collected since learning about Behavior Driven Development (BDD) (as of June 2013). Thinking in BDD terms has really helped me in improving my software development and thinking through problems. I remember a day when it clicked. It was an exciting time for me and I don’t planning on going back to the old approach. ......

Posted On Tuesday, June 11, 2013 10:18 AM

Mock RequireJS define dependencies with config.map
I had a module dependency, that I’m pulling down with RequireJS that I needed to use and write tests against. In this case, I don’t care about the actual implementation of the module (it’s simple enough that I’m just avoiding some AJAX calls). EDIT: make sure you look at the bottom example after the edit before using the config.map approach. I found that there is an easier way. I did not want to change the constructor of the consumer as I had a chain of changes that would have to be made and that ......

Posted On Monday, August 18, 2014 4:53 PM

Use Selenium to Find Elements By Knockout’s Data-bind
I created a quick C# extension method for Selenium to find an element by its data-bind attribute. I wanted to find an element by the binding instead of having to add a class or id to the element. If you have a Knockout Model function MyViewModel() { “use strict”; this.name = ko.observable(); } In the html the element may look like this <input id="nameInput" data-bind="text: name" /> <div id="infoContainer"> <span data-bind=”text: name” /> </div> With the extension method I ......

Posted On Wednesday, July 9, 2014 11:14 AM

A few hints to get started with writing code to test your code
I’ve talked about and shown examples of testing with code (we usually say Unit testing) with fellow developers, but it seems that there is always a barrier to getting started. Here are some of my thoughts on helping you get past that barrier. Notice that I avoided “Unit testing” in my title. I break testing with code into several categories, that help me think and talk about testing. Unit Functionality of test directly, with dependencies removed through mocks or fakes. Behavior (BDD) Test the expected ......

Posted On Friday, May 2, 2014 4:42 PM

Thinking about Productive Work as a Software Developer
Since I started my career as a Software Developer about 7 years ago, I’ve realized that perception of what a valuable use of my time while at work has changed. Scott Hanselman blogged his productivity tips which got me thinking about this more. Meetings I have many times grumbled when a new meeting pops up in Outlook. I have been a part of a lot of time wasting meetings, but there are several that are very useful. Daily stand ups or Scrums are essential to keep everyone on the same page. Retrospectives ......

Posted On Thursday, April 3, 2014 11:57 AM

Notes from Jan 09, 2014 LIDNUG TDD, Where did it all go Wrong
I recently was asked by a co-worker to watch Ian Cooper talk about TDD to give my take on Mr. Cooper’s presentation on TDD. Here’s what I sent back and decided to share it with all of you as well. He's got a lot of experience and laid out things are often stated as things against TDD. Even mentions SpecFlow and problems he had with that. This turns out to validate some of my ideas on BDD. Interesting talk about refactoring too (write code quick, then refactor and write clean code). I'd suggest that ......

Posted On Monday, February 10, 2014 2:21 PM

Steps to Get MVC running with Ninject
enable package restore on solution Nuget Ninject.MVC3 (pre-release available?) * adds Ninject, Ninject.Web.Common, Ninject.Web.Mvc * App_Start/NinjectWebCommon.cs -> has WebActivator.PreApplication... attribute -> runs at startup add interface and class for testing (IBikeManager and BikeManager) add controller constructor to HomeController that takes in the interface - run website => Error "Error activating IBikeManager No matching bindings are available, and the type is not self-bindable. ......

Posted On Wednesday, November 20, 2013 10:46 AM

Heartland Developers Conference 2013 Highlights
I was able to go to another great year of HDC 13 at the beginning of September (on Twitter #hdc13). Our company sent 8 of us down for the Thursday and Friday (thanks for investing in us!). The main theme I got from the conference was to get out and build an app or with the “internet of things” figure out how things work and look into Arduino and connecting for outside control. How do we use of skills for good as well? The Bing platform looks very promising. There were also some Windows 8.1 demos ......

Posted On Wednesday, October 2, 2013 11:20 AM

MVVM with Windows 8 and Window Phone 8
I just read Leveraging Windows 8 Features with MVVM by Brent Edwards in the July 2013 MSDN magazine. I had skipped it before, because I wasn't as interested in building a Windows 8 app. This article is a great walk through of how to use MVVM to achieve a unit testable application. He also introduces Charmed which is the examples in an open source library. It looks very useful.Brent also has Writing a Cross-Platform Presentation Layer with MVVM in the September 2013 MSDN magazine article. This shows ......

Posted On Friday, September 20, 2013 1:57 PM

Faking the WebApi User
I needed to unit test a WebAPI call in my MVC 4 application that checks the user's role. I'm doing this in my MVC controllers with the following code using FakeItEasy (I should do a post on that sometime): this.UserPrincipalFake = A.Fake<IPrincipal>(); A.CallTo(() => this.UserPrincipalFake.Iden... A.CallTo(() => this.UserPrincipalFake.Iden... this.HttpContextBaseFake = A.Fake<HttpContextBase&g... this.HttpContextBaseFake.User ......

Posted On Wednesday, June 5, 2013 10:29 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

MVC Validation of a Password with a Regular Expression
Re-posted on January 19th, 2018 to AlignedDev.net.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 ......

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

DataService and AjaxService for JavaScript
Here is what I’ve been using to make my JavaScript more modular and testable. I’m using JQuery’s promises and the Revealing Module Pattern. I got the idea for the DataServices from John Papa's Pluralsight course on Knockoutjs, but modified it to work with promises, instead of passing in the callback as a parameter. // DataService example: dataService.UiDataService = (function (ajaxService) { 'use strict'; var webServiceUrl = "/api/UiApi/", /** * @brief Get all the components from the service. */ ......

Posted On Friday, April 12, 2013 8:54 AM

Jasmine Specification Testing Pointers
I’ve been using Jasmine JavaScript testing library for Behavior Driven Development (see my Benefits of BDD post) 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 ......

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

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

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

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

Copyright © Aligned | Powered by: GeeksWithBlogs.net