ASP.NET

ASP.NET

Using the Test Data Builder Pattern in unit tests

In an application with lots of complex dependencies, writing unit tests that actually test a single unit of code is challenging. A customer has a large application where most of the "unit" tests are actually integration tests that rely on known test data in the database. For new development in this application, I've been moving toward true unit tests where possible. Using mock objects helps. Instead of the external dependencies for the system under test relying on the database, I mock the dependencies with RhinoMocks. Configuring the test data in the mocks is still painful, though, since each...

Fun with regular expressions: Adding validators to a DetailsView

For a recent prototype, we needed to add required-field validators to a bunch of fields in asp.net DetailsView controls. We had to convert each BoundField to a TemplateField and add a RequiredFieldValidator. In other words, we needed to transform <asp:BoundField DataField="Country" HeaderText="Country" HeaderStyle-CssClass="importantHeader" /> to <asp:TemplateField HeaderText="Country" HeaderStyle-CssClass="importantHeader"> <ItemTemplate> <%# Eval("Country") %></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Country") %>'></asp:TextBox><asp:RequiredFieldValidator runat="server" Display="Dynamic" ControlToValidate="TextBox3" Text="Required" /></EditItemTemplate> ...

Stand back, I know regular expressions! (Part 2)

Now that we’ve got an asp.net DetailsView control with fields from a SubSonic ObjectDataSource and we’ve set the header text, it’s time to work on the code-behind code needed to update the object. The DetailsView template has the following fields: <asp:BoundField DataField="DirectMarketing" HeaderText="Direct Marketing" SortExpression="DirectMarketing" /> <asp:BoundField DataField="AffiliateMarketing" HeaderText="Affiliate Marketing" SortExpression="AffiliateMarketing" /> [... and lots of other fields] We’ll use Visual Studio 2008’s find and replace to generate the update code. Find what:...

Stand back! I know regular expressions!

Regular expressions in Visual Studio’s find and replace can save a lot of time. For a recent project, we used a DetailsView bound to an ObjectDataSource generated by SubSonic. The bound fields were almost, but not quite, what we needed. They were quickly updated with some regular expression magic. The DetailsView has camel-cased text for the field names and the header text. <Fields> <asp:BoundField DataField="CustomerBase" HeaderText="CustomerBase" SortExpression="CustomerBase" /> ...

Creating a DetailsView for a SubSonic data object

The DetailsView control helps accelerate web application development. For a recent ASP.NET project, we used it in conjunction with SubSonic to create a rapid prototype. The data objects generated by SubSonic make it easy to create and configure a DetailsView control. First, create the necessary controller if needed. Here's the partial class I created for the Share table: using System.ComponentModel; namespace CustomerProject.Data {     public partial class ShareController     {         [DataObjectMethod(DataObjectMethodType.Select,...

Multiple web part connections

One of the MOSS 2007 features that ASP.NET developers often miss when writing a custom solution for WSS 3.0 is the QueryString (URL) Filter web part.  We often use the query string to define the filter for displaying lists or forms.  This web part gives users the flexibility to define the query string key value without affecting the functionality of the solutions.  For some of the custom solutions we have built for WSS 3.0, we have implemented our own QueryString Filter web part to provide similar functionality and flexibility.  With this web part, we can easily pass information from query...