Introduction to Object-Relational Mapping for DBAs - Part 1

This is the part one of a lighting talk I’m giving at the SQL Saturday Edmonton Speaker Idol Contest.   Imagine I’m actually speaking the words below and showing some of the images on slides and/or doing a demo.  Code can be found here.

This is a rough draft so constructive feedback at chris.cumming@saturdaymp.com is much appreciated.

Skip ahead to Part 2 if don’t feel like reading all of part 1.

Developer Bud wants to create a new application to track the board games he and his friends play.  He wants a simple website where him and his buddies can login to update the results from the board games they have played.  Being a .NET Developer he creates a ASP.NET MVC Core application with individual authentication.

[Read More]

Today I Learned How to Create Custom NUnit Constraints – Part 2: Constraint Usage Syntax

In Part 1 we created a custom NUnit constraint but you where limited in using the constraint.  You could only write:

 
// Instantiate the constraint. 
Assert.That(expected, new EquivalentPropertyWiseToConstraint(actual)); 

// Matches syntax. 
Assert.That(expected, Is.Not.Matches(new EquivalentPropertyWiseToConstraint(actual)));

It would be nice to write:

// Directly access the constraint from Is.
Assert.That(expected, Is.EquivalentPropertyWiseTo(actual));

// Chain the constraint in Is.
Assert.That(expected, Is.Not.EquivalentPropertyWiseTo(actual));

To do that you should read the documentation.  End of blog post.

So is that joke still funny?  No, OK, no more.  Lets get back to what we are doing.  To access the method using Is you need to override the Is class and add a static method.  I recommended making the method name similar to your constraint name.  For example:

[Read More]

Today I Learned How to Create Custom NUnit Constraints - Part 1: Creating the Constraint

NUnit has has built in constraints for most the tests you will need to write so there is no need to create your own.  End of blog post.

OK, that was a bad joke.  The first step in creating a NUnit custom constraint is to read the documentation.  That’s it.  End of blog post.

Not as funny as the first time?  Not funny at all?  I won’t use that joke again.  But you did read the documentation right?  OK, good.

[Read More]

NConstraints Version 1.0.0 Released

A common unit test assert I need to do is compare all the property values of one object to another.  For example:

[Test]
public void TestSaveWorks()
{
  // Create a value to save.
  var expectedDto = new SomeDto() {ValueOne = 1, ValueTwo = "Blah"};

  // Save the value.
  _someDbService.Save(dtoToSave);

  // Load the value from the database.  The DTO ID
  // should have been set by the save.
  var actualDto = _someDbService.Find(expectedDto.Id);
  
  Assert.That(expectedDto.ValueOne, Is.EqualTo(actualDto.ValueOne));
  Assert.That(expectedDto.ValueTwo, Is.EqualTo(actualDto.ValueTwo));
}

In this test we only have two properties to test but if the object has 10 plus properties to test that would be quite onerous.   I often forget to update the tests after I add a new property to the object.

[Read More]
Categories: code-examples  Tags: nconstraints nunit 

Today I Learned How to Run NUnit Tests for a .NET Core Project in TeamCity

In TeamCity you can’t use the usual NUnit Runner to run .NET Core unit tests.  At least I couldn’t get it to work.  I’m sure this will be fixed in the future but for now the below works for me.  I got lots of inspiration from this TeamCity blog post.

For this example I’ll use the NConstraints project.  It contains a .NET Standard project (SaturdayMP.Constraints) that we want to test and two .NET Core Test projects (SaturdayMP.Constratints.Test and TestClient).

[Read More]