Infragistics WPF controls

How to configure mono 2.10, .NET 4.0 and ASP.NET MVC to run on an Ubuntu Apache web server.

The challenge... As per my previous post [post title here], I wanted to configure mono on my recently installed Ubuntu machine.  Specifically, I wanted to be able to use the latest .NET functionality as well as ASP.NET MVC integration with Apache.  In this post, I plan to provide the steps and resources in which I took to accomplish my goals. Let's start with the Ubuntu machine.... The Ubuntu desktop specifications The machine in which I've installed Ubuntu is an OLD machine that I had laying around the house.  My Android has more horsepower than this old Dell, however, Ubuntu 10.4 seems to operate at a perfectly acceptable capacity.  I plan to "refresh" my Linux skills and look for spare RAM to add to this machine before I upgrade to Ubuntu 12.04.  The recommended minimum requirements for Ubuntu 12.04 are as follows; [For installing] The minimum memory requirement for Ubuntu 12.04 is 384 MB of memory for Ubuntu Desktop. Note that some of your system's memory may be unavailable due to being used by the graphics card. If your computer has only the minimum amount of memory, the installation process will take longer than normal; however, it will complete successfully, and the system will perform adequately once installed. [For upgrading] While the minimum memory requirement for 32bit is 384 MB, a minimum of 512 MB is needed for the 64bit installation. On systems with only the bare minimum amount of memory, it is also strongly recommended to use the "Install Ubuntu" option as it uses less memory than the full live session. Ubuntu Desktop System Requirements for 12.04 LTS What's with all the aPtitude? As much as I love aptitude, I'm quite annoyed by the time it takes for source repositories to list packages as "stable".  I understand that this has nothing to do with the package manager itself and that the Ubuntu version carries more of the blame, even so, I wanted to simply apt-get install mono-complete, I would be stuck with mono 2.4.  Since I wanted to use   some newer functionality, I had some planning to do.  The overall process went a little something like this; Find a bash script that compiles all of the mono packages that I needed to get the job done. Execute the script and watch some T.V while I waited for the massive compile to complete. Move the Apache mono module configuration into the "available modules" folder to enable mod-mono under Apache. I needed to create an Apache virtual host configuration file with the mod-mono specific settings that are required. I had to prepare my file system to serve my ASP.NET applications (c:\inetpub\wwwroot\ for all you Windows natives). I needed to provide a simple solution to publish ASP.NET applications from Visual Studio on my Windows 7 machine to my Ubuntu web server. Finally I needed to restart apache2, publish a web application and test the fruits of my labor. BASHing mono into shape As I stated before, I wasn't going to apt-get install my way into the wonderful world of mono with all of the specific details that my target installation required.  Luckily, I found this post http://www.integratedwebsystems.com/2011/02/mono-2-10-install-script-for-ubuntu-fedora/  in which someone created a BASH script that would download all of the specific packages and compile the sources to produce the exact environment that I was after.  I'm sure  if I had used a modern PC it wouldn't have taken so long, never the less, the compilation was quite a time consuming task indeed!  The script was authored very well in that if there was an error detected, the script would break execution to make it easier for you to find what went wrong.  Fortunately, my compilation completed without a hitch!   Enabling mod_mono in Apache The BASH script had installed created the mod_mono.conf configuration file but I had to find it and copy it to the enabled modules directory so that Apache would recognize it. Here is the command that I executed from a terminal to copy the file to the proper location sudo cp mod_mono.conf /etc/apache2/mods-enabled Of course I had to find the configuration file before I could copy it sudo find -name mod_mono.conf With the configuration file in place, I restarted Apache to make sure all was well sudo service apache2 restart The service restarted successfully so I felt OK with what had been done so far. Creating the mono virtual host configuration file There is a webiste that will require you to fill in some input fields and click a button to generate this file the virtual host configuration with mono specific settings.  I merely had to modify one line of the file. The website is http://go-mono.com/config-mod-mono/ I simply used localhost as my server name and it generated the physical path of /srv/www/localhost. I used nano to edit the file and I modified the MonoDirectory line to point to the correct path of my mono_server4 binary's path which I was able to search and find to be /opt/mono-2.10/bin . Creating wwwroot, or /svr/www ... It was now time to prepare my file system to setup a home for my site hosting.  This basically involved creating some folders, setting permissions and creating an alias link or two. Create the directories sudo mkdir /srv/www sudo mkdir /srv/www/localhost Assign a root group to the folder sudo chown root:www-data /srv/www/localhost -R Change the directory attributes sudo chmod 775 /srv/www/localhost -R I then moved the virtual host site generated file to the appropriate path mv ~/Desktop/localhost.conf /etc/apache2/sites-available I then created a symbol link so I could refer to the vhost configuration file with leading zeros (Apache loads the configurations alphabetically). sudo ln -s ../sites-available/localhost.conf "000-localhost.conf" I restarted Apache, fired up firefox, browsed http://localhost and that's all it took...  I hope you enjoyed reading this article and I hope this helps someone configure ASP.NET MVC under Apache on Ubuntu using mono.  Until next time.. ~/Buddy James   kick it on DotNetKicks.com  


The mono project. The state of .NET on non Microsoft platforms.

Ubuntu too I've recently decided that I wanted to install linux on an older PC in my home.  Many moons ago, before most linux distributions could auto detect and configure your hardware, I had cut my teeth on Debian.  I've had a soft spot ever since for the aptitude package manager.  Naturally I wanted to use a distro that was based on Debian so I went with Ubuntu.  The Ubuntu CD that I have is dated (version 8.04) so I did some research and decided to upgrade to version 10.04.  I fired up a terminal and executed 'sudo do-release-upgrade -d' to apply an upgrade to my system. Watching LED dry The upgrade was a pretty long process, and I found myself watching the terminal window as all of the packages were added, upgraded, and removed.  As I watched, I noticed that quite to my surprise, there were many packages that relied on mono assemblies.  As a .NET consultant, of course this had sparked my curiosity.  I've followed the mono project, from a distance, for a while now but I knew that there was a following, however, I had no idea that mono had made it's way into the heart of the packages that make up an Ubuntu installation.   The current state of things I've decided to take a 1,000 feet view of the current state of the mono project.  As stated by the official website; The easiest way to describe what Mono currently supports is:Everything in .NET 4.0 except WPF, EntityFramework and WF, limited WCF.   That's quite a lot of functionality!  I had no idea that there had been so much work done on the project.  I can write a .NET 4.0 application, an ASP.NET MVC 2 web application and host it on a linux based Apache server.  Well at least that's what the website has told me. Perhaps I'll try to accomplish just that and write about how smooth the whole process actually is. Here are some links for those who are interested. The official mono homepage http://www.mono-project.com/Main_Page The mono project compatability http://www.mono-project.com/Compatibility The mono migration analyzer MoMA http://www.mono-project.com/MoMA Design apps for your iPhone or iPad using monoTouch http://xamarin.com/monotouch Design apps for your android device using mono for android http://xamarin.com/monoforandroid I hope you found something of interest.  Until next time.. ~/Buddy James   kick it on DotNetKicks.com  


TDD using MSTest and Visual Studio 2010 Part one of two

Visual Studio 2010 and unit testing Unit testing has become a necessity in the world of software development.  Incorporating unit testing early and often into your build process can detect new bugs introduced into source code by recent changes from you or other developers.  This in turn will produce lower maintenance costs associated with your projects.   This article will explain MSTest, the integrated testing suite introduced in Visual Studio 2010.  I'll cover the core attributes that you use to mark the test methods in your test classes.  These attributes provide solutions to accomplish common testing tasks such as test setup and break down routines.   I'll also explain Test Driven Development or TDD which is a design methodology that when used properly can add great benefit to your software projects. Just to be clear, I will start by discussing what a unit test is and what it's not. A Unit Test IS An automated unit of code that will invoke methods and change property values on your classes under test then evaluate the state of your objects to see if your code performs as you expect. A unit of code that should be small in size. A unit of code that should be easy to write and maintain. A unit of code that should execute quickly. A unit of code that who's tests are handled by an automated testing framework. In this instance we are using MSTest inside of Visual Studio 2010 as our unit testing framework although there are other alternatives which I will list at the end of this article. A Unit Test IS NOT A test of the entire system by a QA technician. Found inside of your production source project. A piece of code that is dependent upon objects in which you have no control.  Some examples include; A Database system. A file system. A network resource. A third party library in which you don't own the source code. Test Driven Development Test driven development is a design methodology in which you write unit tests before implementing the code that is being tested.  I know, this seems strange, however, when implemented properly, TDD can greatly benefit the design of your code. How does it work? In this multipart series I will explain TDD and related concepts and then follow up with an example project that you can download. Chances are, you source code is probably contained in one or more class libraries (.DLL projects).  These libraries represent components which are made up of classes that define the data and logic of your application.   The idea behind TDD is to write tests that invoke the methods and properties that make up the interface or contract of your class.  The contract is made up of the public members of your classes. You are only testing how the objects are intended to be used by the outside world.  In this way, you are free to think about the design of your classes from a higher level of abstraction because you aren't concerned about the inner workings of your methods.  This concept of information hiding is known as encapsulation.  Once you've written a failing test, it's time to develop the code that implements the methods and properties tested so that you can successfully build the tests. The end goal is to have unit tests that pass.     Red, Green, Refactor! So you have a test project and a class library in a solution and they both build.  The test project should contain a reference to the class library that contains the code under test.  The test class should contain a method to test some functionality of your class.  The test method should be marked with the attribute [TestMethod] MSDN Documentation on [TestMethod] attribute .  At this point, we are aiming for a test that fails when you try to run it.  When your test fails, you will receive a red error indicator from the MSTest Visual Studio integration window.  This is the "Red" in Red, Green, Refactor.  Your next step is to implement the class' methods and properties until you can run the unit test and it passes.  This is the "Green" state.  The last step in the process is to refactor your newly written class.  The definition of refactoring from wikipedia is as follows.   Code refactoring is a "disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior",[1] undertaken in order to improve some of the nonfunctional attributes of the software. Typically, this is done by applying a series of "refactorings", each of which is a (usually) tiny change in a computer program's source code that does not modify its functional requirements. Advantages include improved codereadability and reduced complexity to improve the maintainability of the source code, as well as a more expressive internal architecture or object model to improve extensibility. An important thing to remember when refactoring code is that you don't change the way that the world interacts with your objects, or their interfaces.  Refactoring should be applied in small incremental changes to optimize the existing code found in your methods and helper routines.  With each iteration, be sure to run your unit tests to make sure you have not broken the functionality of your new class.   Some examples of refactorings are as follows;  Try to remove over complicated blocks of code like unnecessary nested if blocks.  Try to rename variables to better suite their values.  A key benefit to refactoring is your code should be easier to read. Once you've finished refactoring, simply start the process over.  Pick some functionality, write a test that fails, get the test to pass, then refactor the newly written code. Here are some TDD related links. MSDN Guidelines for Test-Driven Development http://msdn.microsoft.com/en-us/library/aa730844(v=vs.80).aspx TDD with Visual Studio 2010 http://channel9.msdn.com/Blogs/VisualStudio/Test-Driven-Development-with-Visual-Studio-2010 I hope I have provided you with a place to start with TDD and MSTest.  In part two of this article I plan to implement a full fledged example in c#.  Stay tuned.   kick it on DotNetKicks.com  


About the author

My name is Buddy James.  I'm a Microsoft Certified Solutions Developer from the Nashville, TN area.  I'm a Software Engineer, an author, a blogger (http://www.refactorthis.net), a mentor, a thought leader, a technologist, a data scientist, and a husband.  I enjoy working with design patterns, data mining, c#, WPF, Silverlight, WinRT, XAML, ASP.NET, python, CouchDB, RavenDB, Hadoop, Android(MonoDroid), iOS (MonoTouch), and Machine Learning. I love technology and I love to develop software, collect data, analyze the data, and learn from the data.  When I'm not coding,  I'm determined to make a difference in the world by using data and machine learning techniques. (follow me at @budbjames).  

Related links

Month List