Mvc xunit for favicon [英] Mvc xunit for favicon

查看:90
本文介绍了Mvc xunit for favicon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个代码片段来测试我网站上的favicon。有人可以帮我或提供一个源代码,对favicon进行单元测试。

我在ASP.Net中使用MVC5。



< b>我尝试了什么:



我在MVC尝试但是我没有成功。我的网站上有很多关于不同国家的网站。例如对于意大利而言它是不同的,因为对于荷兰来说它是不同的。我无法完成这项任务,一个接一个地检查10个国家

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

推荐答案

我假设你已经知道如何编写单元测试所以我不会进入那个,可能是很多方法来处理不同的favicon文件的单元测试。



为什么你想为你的favicon进行单元测试?我假设你有多个客户,每个客户都有自己的图标。



为了进行单元测试,你必须将它添加到你的控制器的模型或将其添加为ViewBag项目,并根据< link rel =快捷图标href =@ Model.CustomerSpecificFavicontype =image /重新安排您的视图x-icon> < link rel =快捷图标href =@ ViewBag.CustomerSpecificFavicontype =image / x-icon>



给你试图进行单元测试,我建议你把它添加到你的模型类中,以便查看和处理这样的方式让你不要不得不嘲笑viewbag。



然后就这样,如果它在你的控制器中,你要为你想要测试的控制器特定动作编写一个单元测试,然后测试模型以确保 model.CustomerSpecificFavicon ==my_desired_favicon_file.ico作为对控制器操作的测试的一部分。
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.


这篇关于Mvc xunit for favicon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆