Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to have a code snippet for testing favicons in my website. Can someone help me or provide a source code that do unit testing for favicons.
I am using MVC5 in ASP.Net.

What I have tried:

I tried in MVC but I am not successful. I have many favicons in my website for different countries. For example for italy it is different, for netherland it is different. I cannot achieve this task to check it one by one for 10 countries
Posted
Updated 15-Jan-18 5:51am

1 solution

I'm assuming you already know how to write a unit test so I won't be going into that, rather just one of, probably, many approaches to handle unit testing for different favicon files.

Why would you want to have unit tests for your favicon? I'm assuming you've got multiple clients and each client has their own favicon.

In order to unit test it you'd have to add it either to your model for the controller or add it as a ViewBag item and have your view re-arranged accordingly to something like <link rel="shortcut icon" href="@Model.CustomerSpecificFavicon" type="image/x-icon"> or <link rel="shortcut icon" href="@ViewBag.CustomerSpecificFavicon" type="image/x-icon">.

Give you are attempting to unit test, I'd suggest adding it to your model class for the view and handling that way so you don't have to mock the viewbag.

Then this way, if its in your controller you'd write a unit test for your controllers specfic action you want to test, then test the model to make sure model.CustomerSpecificFavicon == "my_desired_favicon_file.ico" as part of your test for that action of the controller.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900