Friday 16 August 2013

NUnit using data source

I am using NUnit to run unit test.
I have been using  test cases for a while but I needed to use multiple tests with date time.
I did not wanted to write a parsing string into date time.
My code generates html as you can see from code below.


My solution after while of reading documentation:








 [Test, TestCaseSource(typeof(NewsHtmlHelperTests), "DisplayRelatedUpdateLinkTestSources")]
        public void DisplayRelatedUpdateLinkTests(string sourcePath, string articlePath, string name, DateTime createdDate, MvcHtmlString expected)
        {
            var actual = NewsHelper.DisplayRelatedUpdateLink(null, sourcePath, articlePath, name, createdDate);
            Assert.AreEqual(expected.ToString(),actual.ToString());
        }

        public static IEnumerable DisplayRelatedUpdateLinkTestSources
        {
            get
            {
                yield return new TestCaseData("/test", "/test", "Test Article", new DateTime(2012, 05, 28), 
                                            new MvcHtmlString("
  • 28 May Test Article
  • ")); yield return new TestCaseData("/test", "/test/Different", "Test Article Name", new DateTime(2012, 10, 21), new MvcHtmlString("
  • 21 Oct Test Article Name
  • ")); yield return new TestCaseData("/testing", "/test", "Test Article", new DateTime(2012, 09, 18), new MvcHtmlString("
  • 18 Sep Test Article
  • ")); yield return new TestCaseData("/News/Article1", "/News/Article1", "Test Article", new DateTime(2012, 06, 05), new MvcHtmlString("
  • 5 Jun Test Article
  • ")); yield return new TestCaseData("/", "/Hello", "Test Article", new DateTime(2013, 08, 25), new MvcHtmlString("
  • 25 Aug Test Article
  • ")); yield return new TestCaseData("/Snipe", "/Snipe", "Sniper in London", new DateTime(2011, 05, 15), new MvcHtmlString("
  • 15 May Sniper in London
  • ")); } }

    Wednesday 14 August 2013

    Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=11.0.0.0,

    Tuesday 13 August 2013

    For loop in F#

    Tutorial 2

    Define list of numbers
    Create for loop to display results.



    Code:


    // Learn more about F# at http://fsharp.net
    // See the 'F# Tutorial' project for more help.

    open System

    printfn "Started"

    // define list
    let list1 = [ 1; 2; 3; 4; 5; ]

    //loop through all
    for i in list1 do
       printfn "%d" i

    // i squared
    for i in list1 do
        printfn "%d squared %d" i (i*i)

    printfn "Press any key to exit"
    Console.ReadKey()




    Your result




    Hello world in F#

    Lets open our VS studio and open new F# console application project.
    I am writing this example based of my C# knowledge

    1. Text starting with // are comments
    2. The are no {}  as indenting does the same thing.. neeter code love it


    type following

    // same as using
    open System

    // write to screen same as Console.Write("Hello world")
    printfn "Hello world"

    // waits for any key to be pressed
    Console.ReadKey(true)



    Hit F5 and you have nice console application






    Monday 12 August 2013

    Umbraco get media id from url

    Working with umbraco 6 is great fun.

    I am working with images and needed to access image before is served to public.
    Hope my solution will  save you some time.

    Here is solution


    var path = HttpContext.Current.Request.Path.ToLower();
    
    // filter requests that we know are not relevant
    if (!path.StartsWith("/media/") || path.StartsWith("/media/temp/") || path.Contains("_thumb.")) return;
    
    
    // access medisa service
    Umbraco.Core.Services.MediaService ms = new Umbraco.Core.Services.MediaService(new Umbraco.Core.Persistence.RepositoryFactory()); 
    var item = ms.GetMediaByPath(path);
    
    

    Monday 5 August 2013

    Adding typescript minified scripts into bundles.

    Problem:

    I want to add TypeScript generated minified files into bundle configuration.

    By default, minified files are excluded.


    Solution:
    I need to add custom implementation of ignore list in order to manage ignore list. I do not change any configuration of typescripts generated files, but add custom code.

    See implementation below:


     protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();

                WebApiConfig.Register(GlobalConfiguration.Configuration);
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);
                AuthConfig.RegisterAuth();
            }

    public class BundleConfig
        {

       public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
            {
                ignoreList.Clear();
                ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
            }

            // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
            public static void RegisterBundles(BundleCollection bundles)
            {
                AddDefaultIgnorePatterns(bundles.IgnoreList);

                bundles.Add(new ScriptBundle("~/bundles/site")
                    .Include("~/Scripts/Site.min.js",
                             "~/Scripts/Test2.min.js"));
            }
    }