This post is really just to call out a sweet feature of Mercurial; addremove with a --similarity option.

So I’ve decided I wanted to change a naming convention in my View Models, renamed and refactored and compiled then went to commit my changes and Mercurial shows me a whole load of file adds and file deletes. Which means that all the history of these files will stop and a new history start just because I decided to change their names.

Well to the rescue comes Detecting Renames Automatically by Steve Losh which shows how to use this command.

$ hg addremove --similarity 95

What this does is get Mercurial to compare all files and where they’re 95% identical it will record the action as a rename and not the delete and add.

Don’t expect this to show up in the GUI or even when doing a status, if you find matches you just need to commit the changes in order for this to have any effect. This took me a bit to figure out. Cause although TortoiseHg told me it found my renames nothing else happened which confused me.

output-log-addremove

Tags: , | Categories: Mercurial

January 1302

Testing a gist

This post is just to test embedding a gist

Tags: | Categories: General

I’m not sure when this happened but I have noticed that the Syntax Highlighter that I use on this blog has stopped working. I’ve spent some of this morning trying to patch it up but am now, frankly, bored of trying to patch it – something needs to be done.

When I looked at the requests my page was making I noticed that it was getting 404s returned from http://alexgorbatchev.com.s3.amazonaws.com/ which is where the Syntax Highlighter extension was configured to get the css and JavaScript files from – the CDN. On the hosting page Alex lists out the Urls that are currently in use so I modified: App_Code\Extensions\SyntaxHighlighter.cs and updated the CDN references, and nothing changed. Eventually I hardcoded the Urls I needed and managed to get the file paths correct e.g. http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css but although the files were now loading I wasn’t getting any syntax highlighting.

Next I had to ‘tweak’ the JavaScript files and again ran into difficulties, so again hardcoded the handful of BrushXXX.js files that I know I am likely to use (SQL, Plain, C#, CSS, JavaScript, PowerShell and Xml). Again even with the files showing up in the page requests ok I am still not getting syntax highlighting and I’ve bloated my page as a feature of the highlighting tool was that it detected which scripts to load and then loaded only the needed files.

So at this point I’m not prepared to continue to hack about with the SyntaxHighlighter.cs file any more. I have noticed that BE.N has a new release, currently I’m on 2.6.0.17 but 2.7 is out so maybe upgrading to that will help solve my highlighting issues. I’ll probably take a go at that later today, but if that doesn’t work then I think I’ll have to look for an alternative. I quite like the gists from github and was disappointed to find the feature lacking from BitBucket, and as I use BB for my code repositories I would have preferred to keep all my code together; I could hunt out a pastebin I guess and use that but actually I might as well use gists.

Tags: | Categories: Rant | SiteNotice

Following on from my post on Integrating SQL Test / tSQLt with CruiseControl.NET this post adds something that I’d missed out, if the tests fail then the build should fail but all the tests should be run.

As this stand in the other post you would need to check the Build Report or the tSQLt Report in order to know whether there were any failing tests. That is clearly not ideal for an automated system, what is needed is for all the tests to run and if any of them fail then the build should overall fail, but not abort. If you use the build arg “-b” then the build is aborted if the step fails, in other words this:

<exec executable="$(sqlCmdPath)">
    <description>Run Unit Tests</description>
    <buildArgs>-E -b -d MyDatabase 
               –i "IF EXISTS 
                     (SELECT * 
                      FROM sys.objects 
                      WHERE OBJECT_ID = OBJECT_ID(N'[tSQLt].[RunAll]')
                      AND TYPE IN (N'P',N'PC'))
                      BEGIN
                      EXECUTE [tSQLt].[RunAll]
                      END"
    </buildArgs>
    <baseDirectory>\Artifacts\MyDatabase-Database</baseDirectory>
    <buildTimeoutSeconds>3000</buildTimeoutSeconds>
    <successExitCodes>0,63</successExitCodes>
</exec>

would cause the build to abort if just one test failed but that is not helpful. I wanted all the tests to run and to know which of them failed (so I could fix them all), there might be quite a few.

The answer to this problem comes courtesy of Dave Green, who based his answer on a post by tSQLt author Dennis, it checks the content of the test results and raises an error if there are any which are not successful. I added the following exec block last in my project tasks, after getting the test results output into the xml file:

<exec executable="$(sqlCmdPath)">
    <description>Checking test results</description>
    <buildArgs>-b -d MyDatabase 
               -Q "IF EXISTS 
                     (SELECT * 
                      FROM tSQLt.TestResult 
                      WHERE Result != 'Success') 
                   RAISERROR('Errors encountered',16,1)"
     </buildArgs>
</exec>

Now when I run the test project not only do I get the tSQLt Report showing me which of the tests that were run failed but the build fails when any of my tests fail.

Tags: | Categories: ContinuousIntegration | CruiseControl.Net

Unit testing is something that should be done often and although Red Gate’s SQL Test product (which is a wrapper around the open source tSQLt database unit testing framework) makes unit testing in databases easier it is still a manual task and therefore easy to forget about. Integrating the running of the tests with a continuous integration system is, in my opinion, a major step forward in terms of fully testing an application.

There is a post on Integrating tSQLt with Cruise Control on the tSQLt site but nothing on integrating CruiseControl.NET. Likewise there is a great post Using SQL Test Database Unit Testing with TeamCity Continuous Integration, which is highly recommended and helped me solve the same problem for CCNet, but again it didn’t answer my problem – integrating with CruiseControl.NET. As I am doing mostly the same thing I will skim over some of the groundwork.

In my build configuration I have a number of steps that drop my existing database and then recreate it so each run always uses the latest version. The tests are then run and the results merged to the CCNet build log and then custom Build Reports are included. I spent a few days Googling for xsl files that work with the xml created and transform it for appropriate display in the results but didn’t find anything – so I’m including the versions (links at the end) I came up with in the hope that it saves someone some trouble in future.

This extract from the MyDatabase test project shows these steps, in practice the SQL statements should be stored externally as .sql files and then simply invoked – but for the purposes of showing the code I’ve inlined them here.

<tasks>
    <exec executable="$(sqlCmdPath)">
        <description>Turn on CLR on this server.</description>
            <buildArgs> 
                -Q 
                "EXEC sp_configure 'show advanced options',1 ; RECONFIGURE; EXEC sp_configure 'clr enabled',1; RECONFIGURE;"
            </buildArgs>
            <baseDirectory>\Artifacts\MyDatabase-Database</baseDirectory>
            <buildTimeoutSeconds>90</buildTimeoutSeconds>
            <successExitCodes>0</successExitCodes>
    </exec>
    <exec executable="$(sqlCmdPath)">
        <description>Close Local MyDatabase Database</description>
            <buildArgs> 
                -Q 
                "ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE;DROP DATABASE MyDatabase"
            </buildArgs>
            <baseDirectory>\Artifacts\MyDatabase-Database</baseDirectory>
            <buildTimeoutSeconds>90</buildTimeoutSeconds>
            <successExitCodes>0</successExitCodes>
    </exec>
    <exec executable="$(sqlCmdPath)">
        <description>Re-Create Local MyDatabase Database</description>
            <buildArgs> 
                -b 
                -E 
                -Q 
                "CREATE DATABASE MyDatabase"
            </buildArgs>
            <baseDirectory>\Artifacts\MyDatabase-Database</baseDirectory>
            <buildTimeoutSeconds>90</buildTimeoutSeconds>
            <successExitCodes>0</successExitCodes>
    </exec>        
    <exec executable="$(sqlCmdPath)">
        <description>Set database as trusted</description>
            <buildArgs> 
                -b 
                -E 
                -Q 
                "ALTER DATABASE MyDatabase SET TRUSTWORTHY ON;"
            </buildArgs>
            <baseDirectory>\Artifacts\MyDatabase-Database</baseDirectory>
            <buildTimeoutSeconds>90</buildTimeoutSeconds>
            <successExitCodes>0</successExitCodes>
    </exec>    
    <exec executable="$(sqlComparePath)">
        <description>Build MyDatabase Database</description>
            <buildArgs> 
                /scripts1:/CI_Databases/MyDatabase
                /server2:localhost
                /Database2=MyDatabase
                /synchronise
            </buildArgs>
            <baseDirectory>\Artifacts\MyDatabase-Database</baseDirectory>
            <buildTimeoutSeconds>90</buildTimeoutSeconds>
            <successExitCodes>0</successExitCodes>
    </exec>
    <exec executable="$(sqlCmdPath)">
        <description>Run Unit Tests</description>
        <buildArgs>-E -b -d MyDatabase –i 
        "IF EXISTS (SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[tSQLt].[RunAll]')
              AND TYPE IN (N'P',N'PC'))
              BEGIN
              EXECUTE [tSQLt].[RunAll]
              END"</buildArgs>
        <baseDirectory>\Artifacts\MyDatabase-Database</baseDirectory>
        <buildTimeoutSeconds>3000</buildTimeoutSeconds>
        <successExitCodes>0,63</successExitCodes>
    </exec>
    <exec executable="$(sqlCmdPath)">
        <description>Get Unit Tests</description>
        <buildArgs>-E -b -d MyDatabase -h-1 -y0 -I
           -i ":XML ON
                EXEC [tSQLt].[XmlResultFormatter];" 
           -o "C:\CCNetProjects\Configuration\CI_SQL\Results\TestResults.xml"
        </buildArgs>
        <baseDirectory>\Artifacts\MyDatabase-Database</baseDirectory>
    </exec>
</tasks>
<publishers>
    <merge>
        <files>
            <file>C:\CCNetProjects\Configuration\CI_SQL\Results\TestResults.xml</file>
        </files>
    </merge>
    <statistics />
    <modificationHistory onlyLogWhenChangesFound="true" />
    <xmllogger logDir="\CCNetProjects\buildlogs"/>
    <artifactcleanup cleanUpMethod="KeepLastXBuilds" cleanUpValue="50" />
</publishers>

With all that set up each time the project is run the old database is dropped, then a new instance created and configured for SQL Test. Next SQL Compare is used to sync the new database to the Version Control repository copy. The tests are run and the output stored in TestResults.xml and finally that xml is merged, in the publishers node, with the build logs. What is now required is getting those results to do something in CCNet, because as things stand you would have to check the build log manually to see whether any tests passed or failed and decide what to do about it.

Integrating the results with CCNet

This is the part that caused me the most pain, because I was hoping for a pre-existing xsl file to transform the xml – after all there are already a good number of these included with CCNet – but alas I didn’t find anything, so decided to write my own. First I copied existing xsl’s that were doing what I wanted for both the buildReportBuildPlugins, which shows up on the main build summary and the ReportBuildPlugin that’s listed on the left side (under the link to the build log) and then added them to the dashboard.config

<buildPlugins>
  <buildReportBuildPlugin>
    <xslFileNames>
      <xslFile>xsl\header.xsl</xslFile>
      <xslFile>xsl\modifications.xsl</xslFile>
      <xslFile>xsl\compile-msbuild.xsl</xslFile>
      <xslFile>xsl\compile.xsl</xslFile>
      <xslFile>xsl\tSQLtSummary.xsl</xslFile>
    </xslFileNames>
  </buildReportBuildPlugin>
  <xslReportBuildPlugin description="tSQLt Report" 
actionName="tSQLtReport"
xslFileName="c:\CCNetProjects\Custom Reports\tSQLtReport.xsl"> <includedProjects> <projectName>StudentNet-Database</projectName> </includedProjects> </xslReportBuildPlugin> </buildPlugins>
report-plugin-menu

This shows the tSQLtSummary integrated into the Build Report. It summarises the number of tests run, passed and any failures. As I said I based the summary on an existing xsl (NUnit) and I needed to modify a few paths in order to access the results; I’m only including a few lines here but the full version is available as a link at the bottom.

<xsl:variable name="nunit2.result.list" select="/cruisecontrol/build/testsuites/testsuite"/>
<xsl:variable name="nunit2.testcount" select="sum($nunit2.result.list/@tests)"/>
<xsl:variable name="nunit2.failures" select="sum($nunit2.result.list/@failures)"/>

The tSQLtReport.xsl file is also quite lengthy, so again the full version is linked at the bottom. I started with the MsTestReport.xsl and tweaked it for tSQLt in much the same way as for the summary.

<xsl:value-of select="sum(/cruisecontrol/build/testsuites/testsuite/@tests)" />

tSQLtResults

This gives a nice degree of visibility into the status / health of your database builds.

I know there is a great deal more polish that could be added to these reports, but I’ve done the initial work and am happy enough (for the moment) with the result. If anyone wants to update the files please feel free and share them / ping me so I can update them.

Links to the full files:
Tags: | Categories: CruiseControl.Net | ContinuousIntegration

This is a quick tip about how to reach the Navigation Bar via the keyboard (in Visual Studio) and it’s shamelessly reproducing that post by Scott Cate, not because I think I’m adding anything new but because I wanted to be able to find it again easily.

Navigation-BarThe Navigation Bar is just below the tabs in Visual Studio and has 2 drop downs; the first lists objects in the current file and the second lists the members of the selected object. This can be a very quick way to navigate around your class file, though the CodeRush Quick Navigation is more powerful IMO.

So to jump up to the Navigation Bar press Ctrl+F2, then you can tab between the left and right drop downs. When you’ve selected the member you want to move to press enter to have the cursor and focus move to that selection.

Incidentally I thoroughly recommend Scotts’ VSTricks category, which is in turn replaying Sara Ford’s Tip of the Day posts in video format.

Tags: , | Categories: Tips&Tricks | Visual Studio

November 1223

Support me in Movember

During November each year, Movember is responsible for the sprouting of moustaches on thousands of men’s faces in the UK and around the world. The aim of which is to raise vital funds and awareness for men’s health, specifically prostate cancer and testicular cancer.Mo-is-King

Each Mo Bro must begin the 1st of Movember with a clean shaven face. For the entire month each Mo Bro must grow and groom a moustache. There is to be no joining of the mo to the sideburns (that’s considered a beard), there’s to be no joining of the handlebars to the chin (that’s considered a goatee) and each Mo Bro must conduct himself like a true gentleman.

The funds raised in the UK are directed to programmes run directly by Movember, Prostate Cancer UK and the Institute of Cancer Research.

Since its humble beginnings in Melbourne, Australia Movember has grown to become a truly global movement inspiring more than 1.9 Million Mo Bros and Mo Sistas to participate with formal campaigns all over the world. No matter the country or city, Movember will continue to work to change established habits and attitudes men have about their health, to educate men about the health risks they face, and to act on that knowledge, thereby increasing the chances of early detection, diagnosis and effective treatment.
In 2011, over 854,000 Mo Bros and Mo Sistas around the world got on board, raising GBP 79.3 million.

So I am asking you to help support my personal journey by making a donation. The size of which isn't important, every little contribution helps Movember to continue its funding of world class programmes.  If you want to know more about what you'll be helping to fund, you can visit Movember's Program Overview page - http://uk.movember.com/about/funding-overview/

To highlight the importance of what I am doing, take a look at these statistics:

  • 1 in 9 men will be diagnosed with prostate cancer in their lifetime
  • This year 40,000 new cases of the disease will be diagnosed in the UK
  • 47% of testicular cancer cases occur in men under 35 years and over 90% occur in men under 55 years

If you'd like to help change these statistics, please donate to me by donating online at: http://mobro.co/6403025

Tags: | Categories: General

If you see this post it means that BlogEngine.NET 2.7 is running and the hard part of creating your own blog is done. There is only a few things left to do.

Write Permissions

To be able to log in to the blog and writing posts, you need to enable write permissions on the App_Data folder. If your blog is hosted at a hosting provider, you can either log into your account’s admin page or call the support. You need write permissions on the App_Data folder because all posts, comments, and blog attachments are saved as XML files and placed in the App_Data folder. 

If you wish to use a database to to store your blog data, we still encourage you to enable this write access for an images you may wish to store for your blog posts.  If you are interested in using Microsoft SQL Server, MySQL, SQL CE, or other databases, please see the BlogEngine wiki to get started.

Security

When you've got write permissions to the App_Data folder, you need to change the username and password. Find the sign-in link located either at the bottom or top of the page depending on your current theme and click it. Now enter "admin" in both the username and password fields and click the button. You will now see an admin menu appear. It has a link to the "Users" admin page. From there you can change the username and password.  Passwords are hashed by default so if you lose your password, please see the BlogEngine wiki for information on recovery.

Configuration and Profile

Now that you have your blog secured, take a look through the settings and give your new blog a title.  BlogEngine.NET 2.7 is set up to take full advantage of of many semantic formats and technologies such as FOAF, SIOC and APML. It means that the content stored in your BlogEngine.NET installation will be fully portable and auto-discoverable.  Be sure to fill in your author profile to take better advantage of this.

Themes, Widgets & Extensions

One last thing to consider is customizing the look of your blog.  We have a few themes available right out of the box including two fully setup to use our new widget framework.  The widget framework allows drop and drag placement on your side bar as well as editing and configuration right in the widget while you are logged in.  Extensions allow you to extend and customize the behaivor of your blog.  Be sure to check the BlogEngine.NET Gallery at dnbegallery.org as the go-to location for downloading widgets, themes and extensions.

On the web

You can find BlogEngine.NET on the official website. Here you'll find tutorials, documentation, tips and tricks and much more. The ongoing development of BlogEngine.NET can be followed at CodePlex where the daily builds will be published for anyone to download.  Again, new themes, widgets and extensions can be downloaded at the BlogEngine.NET gallery.

Good luck and happy writing.

The BlogEngine.NET team

Tags: , | Categories: BlogEngine.NET

I am setting up my new work PC at the moment and Visual Studio kept telling me there were updates for NuGet. Dutifully I tried to run the update but it kept failing, I tried to run VS as an admin but due to the way it is installed on the network that wasn't possible. Uninstalling NuGet from the Uninstall Program option in Control Panel removed it from the list of installed programs, but not from Visual Studio, so then I thought I'd try some brute force and just remove the whole folder to see if that helped. 

That got me somewhere, now Visual Studio didn't think NuGet was installed, but I couldn't install it either... Well if there's a brute force way to remove the extension then there's a brute force way to install the extension and that's simply to download the NuGet.Tools.visx then extract it to C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\NuGet (this folder may not exist, or you might have previously removed it with the brute force approach). After extracting the contents of the visx I relaunched Visual Studio and now have NuGet Version: 2.1.31002.9028, though the Disable and Uninstall buttons are greyed out (lack of admin rights I guess), so next time I need to update it looks like I'll need to repeat my "Uninstall" process, which is why I wrote this post... to remind me Wink

Tags: | Categories: Development | Tips&Tricks

I’m starting a new job and yesterday was my last day for my current employer. It’s been nearly 2 years working from home and I’ve really enjoyed it, but it’s now time for me to move on. A fantastic opportunity has presented itself and fantastic opportunities don’t grow on trees so when they present themselves only a fool lets them pass by without doing anything.

Working from home has been great, I got into computers years ago because I wanted the flexibility in my life to allow me to work from home, or anywhere for that matter but it isn’t for everyone and it can take time (for the whole family) to adjust to, ideally you need some space at home that is reserved for work – no one wants to sleep in the office! I do think that more and more we’ll see jobs that offer working from home as an option, it benefits employers and employees in so many ways: greater productivity, financial savings and personal flexibility for example. That said being in an office, with your team, also has its advantages: being able to see the people you’re talking to, bouncing ideas off each other, being able to see what other people are doing and sharing ideas. So maybe 4 days at home and 1 day in the office would be a good way to work, time will tell… give it a few years and the internet revolution may change the work place as much as the industrial revolution did, but I digress.

I’ll be doing something a bit different still writing code but obviously with fresh problems to solve, so hope to have more to blog about in the near future. As you might have guessed from what I’ve just said I’ll be office based again, so will benefit from a (short) walk to work in the mornings, a healthy way to start the day and get the blood flowing. There’s a team of people to get to know and the challenge of the new job to keep me on my toes and who knows what else in store, but I know I’ve done a good thing for my career and that’s the key.

Tags: | Categories: General