Release 0.4 – Learning a New Language

Hi everyone, I am back with the last post of Release 0.4. The semester is almost over, and I have enjoyed working in the Open Source environment so much this whole semester. I will talk more about this in another post. Stay tuned.

For the last internal pull request, I decided to challenge myself a little and finish strong. Since I had so much fun learning Python during the Hacktoberfest, I decided that I will learn another new language this time. Also, one of the internal projects that I am interested in called “Portfolio Generator” uses C# language. Therefore, I decided to learn C# and add a unit test for the project (#26).  

I started by looking into what a unit test is. It is programs that will test the code to maintain code health, ensure code coverage, and to find errors and faults before customers do (Source: Getting started with unit testing). Then, I went through one of the Microsoft’s documents on how to create and run unit tests for managed code. It has taught me some basic syntax on writing unit tests. After that, I looked into XUnit.net because that’s what was suggested in the issue. I found this very helpful documentation: Getting started with xUnit.net which has helped me to get started. 

Since I am still new at C# language, I decided to write the unit test for DeleteFiles() function in the HtmlGenerator.cs. It looks like this:

using System;
using Xunit;
using Portfolio_generator_console;

 namespace UnitTests
{
    public class PortfolioGeneratorTests
    {
        [Fact]
        public void TestDeleteFiles()
        {
            string templateDir = Path.Combine (Directory.GetCurrentDirectory ().ToString (), "templates");
            string[] files = Directory.GetDirectories (templateDir);
            
            string expected = null; // expected result after the deletion
             Console.Write("Please enter the file you want to delete: ");
            var fileName = Console.ReadLine();
            var path = path.Combine(templateDir, files);
            
            HtmlGenerator.deleteFiles(path);
             string actual = path;
             Assert.AreEqual(expected, actual, "File not deleted correctly."); // compares the expected result with the actual result
        }
    }
}

This is still the trial version and probably needs modifications afterwards before getting merged. So, more work will probably be needed later on. Here is the Pull Request: Unit test for DeleteFiles function #29.

Learning a new programming language is always fun, and thanks to Open Source, we have gotten the perfect opportunity to learn, practice, and improve. 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s