Thursday, September 29, 2011

render a view in another folder (not the shared folder)

@Html.Partial("~/Views/Foo/_ListModel.cshtml", Model.Whatever) is an example of this approach.

how to collect the names of only string value columns from a DataTable, how to test an abstract class, and when to nest two classes in one file

ListViewModel is an abstract class that has a method called ReturnListOfNamesOfStringBasedColumns in it which has one line within it:

return this.ListTable.Columns.Cast<DataColumn>().Where(column => column.DataType == typeof (string)).ToDictionary(column => column.ColumnName, column => column.ColumnName);

 
 

I am testing it like so:

[TestClass]

public class ListViewModelTest

{

   [TestMethod]

   public void ReturnListOfNamesOfStringBasedColumns_Behaves_As_Expected()

   {

      //arrange

      PseudoChildForTestingAnAbstractClass listModel =

            new PseudoChildForTestingAnAbstractClass();

      listModel.ListTable = new DataTable();

      listModel.ListTable.Columns.Add("Foo", typeof (string));

      listModel.ListTable.Columns.Add("Bar", typeof (Int32));

      listModel.ListTable.Columns.Add("Baz", typeof (string));

      listModel.ListTable.Columns.Add("Qux", typeof (string));

      

      //act

      Dictionary<string, string> dictionary =

            listModel.ReturnListOfNamesOfStringBasedColumns();

      

      //assert

      Assert.AreEqual(3, dictionary.Count);

      Assert.AreEqual("Foo", dictionary["Foo"]);

      Assert.AreEqual("Baz", dictionary["Baz"]);

      Assert.AreEqual("Qux", dictionary["Qux"]);

   }

}

 

public class PseudoChildForTestingAnAbstractClass : ListViewModel<object>

{

 

}

 
 

This is a rare case where it seems OK to have two classes in one file. Another example might be having an Enum class next to the only class that is ever going to use it.

Tuesday, September 27, 2011

.Verifiable();

.Verifiable() in MOQ is apparently something like Assert.WasCalled in Rhino Mocks. This suggests that .VerifyAll(); needs to be called at the end of a unit test to make the .Verifiable() calls mean anything.

Friday, September 23, 2011

rename a DataTable column

this.ListTable.Columns["FirstShipDate"].ColumnName = "First Ship Date";

giving a "friendly name" for a database field at our project

We can enter our .edmx, select a field, go to "Properties" and then expand "Documentation" to give a friendly name at "Long Description." The friendly name may be used, for example, to display "First Name" in lieu of "FirstName"

press F12 in IE9 to masquerade as IE7 or IE8

there will be an obvious spot for "Document Mode" to change the setting

to see your open bugs in TFS

Go to: Work Items > Team Queries > [Your Project Name Here] > My Open Bugs