Background

Selenium automates browsers. That’s it! What you do with that power is entirely up to you. Primarily, it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.http://docs.seleniumhq.org/

NUnit is a unit-testing framework for all .Net languages. Initially ported from JUnit, the current production release, version 2.6, is the seventh major release of this xUnit based unit testing tool for Microsoft .NET. It is written entirely in C# and has been completely redesigned to take advantage of many .NET language features, for example custom attributes and other reflection related capabilities. NUnit brings xUnit to all .NET languages.http://www.nunit.org/

Install NUnit

You will need NUnit to execute your automated tests. Download the win MSI file and run it. Select a complete installation when prompted.

Setup Visual Studio

Open Visual Studio

Click File, click New, and select Project…

In the left navigation pane, expand Templates, then Visual C#, and then select Class Library in the center window pane.

Solution on GitHub

The System.Reflection namespace is tool that allows you to reflect the properties of an assembly without importing the assembly to your project references. A good example is the RESTful application I host on GitHub.

Reflected Assembly

This code (below) will load an assembly from the specified file path in a WPF application.

The top navigation bar on most sites has some form of highlight to allow the user to quickly see what section of the site they are viewing. In MVC this can be accomplished with a simple HTML and CSS modification.

Modify the Controller(s)

You will need to pass a variable <code>@currentPage</code> to your view from the appropriate controller(s).

Modify the Shared View

You will need to modify the <body> tag of _Layout.cshtml to include an id. In the code (below) I go the extra step of converting the string to lowercase to match the CSS no matter how a developer types the CurrentPage in the controller.

Further Reading

MVC POST a Model with Image

When POSTing a model you may need to stream some file content; like an image. The template controller will need to be modified to accomplish this. For this example, we will look at the source code I used to add ‘products’ to theCosmics.com. You will notice the use of the [Authorize] data annotation, which means only a logged in user can submit the POST.

The Product Model

Note that the model has properties for ImageData and ImageMimeType. If you need to update your models, be sure to enable data migrations.

In the code (above) I have modified the parameters of the Create method to include a second parameterHttpPostedFileBase. As long as the image is not null, it will save two columns of data to the database; the first column is the MIME type (jpg, gif, png, etc.) and the second column is the byte data of the image. NOTE: You will need to modify your EDIT controller method, too.

Using the Image

The webapp can use the SQL data to reassemble the data into a usable image using a new controller.

Further Reading

Background

Telerik Test Studio is an application I have used in Software QA Automation. One project I had was api testing a REST web api for an MVC solution. This code can be used in almost any testing suite that allows you to import .NET 4.5.

Download C#

The fastest way to start developing applications for Windows 8.1, Windows Phone, the web or the cloud. Visual Studio Express products provide a free development environment to develop applications for the latest platforms. Since it is Visual Studio, applications created in Express can be supported in other versions of Visual Studio as your needs grow.http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx

Starting C#

Learn how easy it is to set up Visual Studio and connect to Visual Studio Online. Once you’re set up, we’ll show you how to create and organize your backlog, share your code with your team, and configure your app for continuous builds and deployment. Choose any of the sections below to get started.http://www.visualstudio.com/get-started/overview-of-get-started-tasks-vs

Variables

The C# typing system contains the following categories: Value types, Reference types, and Pointer types.
Variables that are value types store data, and those that are reference types store references to the actual data. Reference types are also referred to as objects. Pointer types can be used only in unsafe mode.
It is possible to convert a value type to a reference type, and back again to a value type, by using boxing and unboxing. With the exception of a boxed value type, you cannot convert a reference type to a value type.
This section also introduces void.
Value types are also nullable, which means they can store an additional non-value state. For more information, see Nullable Types.http://msdn.microsoft.com/en-us/library/3ewxz6et.aspx

Functions

A method is a code block that contains a series of statements. A program causes the statements to be executed by calling the method and specifying any required method arguments. In C#, every executed instruction is performed in the context of a method. The Main method is the entry point for every C# application and it is called by the common language runtime (CLR) when the program is started.http://msdn.microsoft.com/en-us/library/ms173114.aspx

Passing Variables to Functions

Previously, message was accessible because its accessibility level is private (default). Meaning it is accessible from within the Hello class. In this example, we will pass a string value to a method as a parameter.

Further Reading

Most of this section assumes that you already know something about C# and general programming concepts. If you are a complete beginner with programming or with C#, you might want to visit the C# Developer Center, where you can find many tutorials, samples and videos to help you get started.