TeamCity Build – Excluding Projects From a Solution (sln) file.

As part of a solution I was including the 3rd Party “MVCForum” projects which I didn’t want to build on every commit.  I need to exclude this projects from building in TeamCity.  Steps below…

1. Introduce a new solution configuration


Easiest way to do this is through Visual Studio …Build…Configuration Manager….New (I called mine “TeamCity”). Untick the projects you don’t want to include as part of the build. Ensure “Mixed Platforms” is also selected if that’s your intent.

2. Set up an system parameter


In TeamCity, (Build Configuration….Parameters….System Properties…) and add system.Configuration
with Value of the solution config introduced in point 1 (mine being TeamCity).


Don’t do what I first did and specify /p:Configuration=”MyConfig” in the Build Step as TeamCity whines about using a system param.
There are no “Command Line Parameters” required here. That box should be blank. The beauty of setting up a System Parameter means it will be injected automatically by TeamCity at build time.

3. Change build folders


Finally, if you have a Unit Test step(s) and you should have! then you’ll need to change the bin folder of your unit test assemblies to include your Build config name.

Moq – Mocking the Request context and verifying SQLException is raised.

Mocking the Request on an API Controller

Had an API controller under unit test which made use of the HttpMessageRequest which I needed to mock.How do I get a handle on this?

Again pretty simple really (my initial train of thought was back to front on this one)

var request = new HttpMessageRequest(HttpMethod.Get, "http://....."
controllerUnderTest.request = request;

Verifying that a SQLException is raised.



I was unable to mock

.Throws<<"SQLException">>

as SQLException has a parameterless constructor as in….

‘System.Data.SqlClient.SqlException’ must be a non-abstract type with a public parameterless constructor in order to use it as parameter ‘TException’ in the generic type or method ‘Moq.Language.IThrows.Throws()’

So what to do?

var exception = FormatterServices.GetUninitializedObject(typeof(SqlException)) as SqlException;
mockInvalidDBContext.Setup(d => d.GetConnection()).Throws(exception);

Credit to http://stackoverflow.com/questions/11976996/moq-and-throwing-a-sqlexception

Moq – Verifying parameter values on a mocked method call.

moq logo

Was going down a rabbit hole trying to figure out how to check param value on a mocked method (pretty simple if truth be told).

I need to ensure that when an exception was raised my logger would be called Times.Once and would log the correct level of detail in the message.  I did the following:

  • Unit test to mock method under test to raise an exception;
  • Mocked setup on my logger;
  • Assert with Verify on my mocked logger

_mockLogger.Verify(m => m.LogException(It.IsAny<Exception>(), It.Is<String>(l => l == “Message containing detail that I care about to be logged”));

Work related code has been obfuscated for the purposes of this blog. 

Please check out some of my other Moq articles including mocking a return type of task and tuple

Kudus to the following on StackOverflow which reminded me of “It.Is” here

Wire/Clinic – Drill Festival Sat 22nd April

Went along to the Saturday of a 3 day Drill Festival in Leeds which celebrated Wire’s 40th anniversary but looking forward rather than back.

Tickets were around mid-20s mark for the day which was great value considering all the bands you had access to.  Checked out a few others including JoeyFat who was very entertaining (watched on by Wire’s rhythm section in the crowd).  Lead singer resplendent in what appeared to be a kiddies matador outfit.

 

 

Never seen Clinic live but I’ve always had a soft spot for them.  They were very good and played a lot of their first album to the delight of the crowd.  Will be checking them out live in their own right.

 

 

Wire appeared at around 10pm.  I think it’s fair to say the crowd were waning by now but they put on a blinding performance.  Despite the look back bores “Three Girl Rhumba” got an airing. They continue to release quality albums and put on great live shows.  I look forward to their 50th anniversary as there’s no signs of them slowing down.

British Sea Power @ Birmingham 02 Academy – 13th April 2017

Big smiles as we waltz passed the lines of cheesed off looking Kasabian fans snaking round the corner and up the road from the Birmingham 02 Academy.  We walk straight into the side hall of the Academy (which in itself is a fairly large venue).  On the way in a friendly bouncer looks at us and goes “Ah you here for British Sea Shanties?” with a wry smile on his face. Good effort mate!  I whince as I hand over the £5.10 for a pint of Tubourg!!

 

 

Pint down and BSP hit the stage for the last date of the UK tour.  And it’s another corker.  It’s pretty active down the front and a bit weird.  One guy (not me!) pogos about down the front to just about every song. Then BSP come back on for the encore and let rip with a chaotic cover of Iggy’s “Fun Time” and said pogoer stands there wondering what he’s hearing. Erm.  Anyway, the onstage banter is strong tonight, Noble offers us “What’s your favourite temperature?”.  All jolly good fun.

 

 

 

sdr