小编qin*_*126的帖子

需要帮助来对我的mvc3项目中的服务层进行单元测试

我的mvc3项目具有服务和存储库层。

我的服务层:

public class UserService : IUserService
{
    private readonly IUserRepository _userRepository;

    public UserService(IUserRepository userRepository)
    {
        _userRepository = userRepository;
    }

    public ActionConfirmation<User> AddUser(User user)
    {
        User existUser = _userRepository.GetUserByEmail(user.Email, AccountType.Smoothie);
        ActionConfirmation<User> confirmation;

        if (existUser != null)
        {
            confirmation = new ActionConfirmation<User>()
                               {
                                    WasSuccessful = false,
                                    Message = "This Email already exists",
                                    Value = null
                               };

        }
        else
        {
            int userId = _userRepository.Save(user);
            user.Id = userId;

            confirmation = new ActionConfirmation<User>()
                               {
                                   WasSuccessful = true,
                                   Message = "",
                                   Value = user
                               }; …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc nunit unit-testing asp.net-mvc-3

3
推荐指数
1
解决办法
2856
查看次数

如何根据alt属性检查图像是否存在?

如果我想将另一个图像附加到此列表中.

<img src="1.jpg" alt="apple">
Run Code Online (Sandbox Code Playgroud)

如果apple已经在此列表中,则不执行任何操作.有没有办法可以使用jQuery来检查?

我试着用find, var existItem = $("#targetBox").find(" not sure what to put here ")

<div id="test">
  <img src="1.jpg" alt="apple">
  <img src="2.jpg" alt="banana">
  <img src="3.jpg" alt="grape">
</div>
Run Code Online (Sandbox Code Playgroud)

jquery jquery-selectors

3
推荐指数
1
解决办法
2854
查看次数

Kendo,如何使用mvc4 helper进行网格服务器分页

我正在使用mvc4.在我的一个页面上,它有Kendo Grid.我想每页显示5行.使用纯javascript我没有问题,但是,如果我使用的是mvc helper.我迷路了,在网上找不到任何样品.

这是我的javascript代码.

        <script language="javascript" type="text/javascript">

            $(document).ready(function () {
                $("#grid").kendoGrid({
                    dataSource: {
                        type: "json",
                        serverPaging: true,
                        pageSize: 5,
                        transport: { read: { url: "Products/GetAll", dataType: "json"} },
                        schema: { data: "Products", total: "TotalCount" }
                    },
                    height: 400,
                    pageable: true,
                    columns: [
                            { field: "ProductId", title: "ProductId" },
                            { field: "ProductType", title: "ProductType" },
                            { field: "Name", title: "Name" },
                            { field: "Created", title: "Created" }
                        ],
                    dataBound: function () {
                        this.expandRow(this.tbody.find("tr.k-master-row").first());
                    }
                });
            });
Run Code Online (Sandbox Code Playgroud)

现在如果我正在使用mvc helper

            @(Html.Kendo().Grid(Model)
                .Name("Grid")  //please …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc kendo-ui

3
推荐指数
2
解决办法
2万
查看次数

knockoutJs,何时使用ko.computed

我对ko.computed很困惑.不知道何时使用它.我有2个陈述.你能否向我解释一下这些差异以及何时使用它们?

self.fullName = ko.computed(function() {
    return self.firstName() + " " + self.lastName();
});


self.fullName = function() {
    return self.firstName() + " " + self.lastName();
};
Run Code Online (Sandbox Code Playgroud)

knockout.js

3
推荐指数
1
解决办法
1941
查看次数

请解释为什么这个c#扩展方法有效

我买了pro asp.net mvc2框架书.我在第122页遇到了困难.我无法理解为什么会这样.

我已经通过电子邮件发送了作者,但还没有收到任何回复.这是代码,有人可以向我解释为什么它的工作原理.

    public static class PagingHelpers
{
    public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl)
    {
        StringBuilder result = new StringBuilder();

        for (int i = 1; i <= pagingInfo.TotalPages; i++)
        {
            TagBuilder tag = new TagBuilder("a");
            tag.MergeAttribute("href", pageUrl(i));

            tag.InnerHtml = i.ToString();

            if (i == pagingInfo.CurrentPage)
                tag.AddCssClass("selected");

            result.AppendLine(tag.ToString());
        }

        return MvcHtmlString.Create(result.ToString());
    }
}
Run Code Online (Sandbox Code Playgroud)

这个PageLinks辅助方法需要3个参数,但是在本书后面,当作者调用它时,

<%: Html.PageLinks(
      new PagingInfo { CurrentPage = 2, TotalItems = 28, ItemsPerPage = 10 },
      i => Url.Action("List", new{ page = i}) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-2

2
推荐指数
1
解决办法
286
查看次数

asp.net mvc3,为什么我们在使用存储库模式时需要服务层

我正在观看"店面入门套件",它使用带有服务层的存储库模式.在视频中,他没有真正解释他为什么使用服务层.好像那些只是额外的.

什么是使用服务层的利弊?

repository-pattern service-layer asp.net-mvc-3

2
推荐指数
1
解决办法
794
查看次数

web.config文件中的Custom Config部分会破坏我的单元测试

我的单元测试工作,但在我添加一些代码以从web.config文件中的Custom Config部分获取值之后,单元测试停止工作.以下是我的代码,那些标有"// new"的行是我添加的新代码,它们打破了测试.

public partial class AccountController : Controller
{
    private readonly string _twitterConsumerKey;
    private readonly string _twitterConsumerSecret;
    private readonly string _twitterAccessToken;
    private readonly string _twitterAccessTokenSecret;

    private readonly IUserService _userService;

    public AccountController(IUserService userService)
    {
        if (userService == null)
            throw new ArgumentNullException("userService");


        _userService = userService;

        _twitterConsumerKey = TwitterSettings.Settings.ConsumerKey;  //new code
        _twitterConsumerSecret = TwitterSettings.Settings.ConsumerSecret;  //new code
        _twitterAccessToken = TwitterSettings.Settings.AccessToken;  //new code
        _twitterAccessTokenSecret = TwitterSettings.Settings.AccessTokenSecret;  //new code

    }





public class TwitterSettings : ConfigurationSection
{

    private static TwitterSettings settings = ConfigurationManager.GetSection("Twitter") as TwitterSettings;
    public …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing asp.net-mvc-3

2
推荐指数
1
解决办法
1152
查看次数

sql server 2008存储过程,不能在单引号中使用变量

这是我的存储过程.

ALTER PROCEDURE [dbo].[SearchIngredients] 
    @Term NVARCHAR(50) 
AS
BEGIN
    SET NOCOUNT ON;

    SELECT  *
    FROM    dbo.FoodAbbrev
    WHERE   Name LIKE '%@Term%'
    ORDER BY Name

END
Run Code Online (Sandbox Code Playgroud)

我一直没有得到任何结果.我认为这是因为我把变量放在单引号中,可能DB认为这是字符串的一部分,而不是变量.尝试了其他一些方法,还是无法修复它,请帮帮我.

我也试过了.仍然没有得到回报.

    SET @Term = '''%' + @Term + '%'''

    SELECT  *
    FROM    dbo.FoodAbbrev
    WHERE   Name LIKE @Term
    ORDER BY Name
Run Code Online (Sandbox Code Playgroud)

sql-server stored-procedures sql-server-2008

2
推荐指数
1
解决办法
2185
查看次数

流浪汉 - 没有颜色,它做什么?

我正在学习厨师,并从一个厨师教程页面找到了这个命令.

https://learnchef.opscode.com/quickstart/converge/

我知道什么是流浪汉.但是 - 没有颜色,我不知道这是为了什么.我搜索了整个流浪网站.仍然找不到它.

只是好奇这是什么.

chef-infra vagrant

2
推荐指数
1
解决办法
784
查看次数

visual studio 2015调试器停止工作,不断收到"错误CS0103:当前上下文中不存在该名称"

我正在使用visual studio 2015并使用mvc core创建了一个空白的mvc应用程序.

在startup.cs文件中,我添加了一个新的测试方法.然后我将它附加到hello world字符串.如果我只是运行它,一切正常.我得到了"Hello World!3".但如果我尝试调试我的代码.我在测试方法中设置了几个断点.当我移动鼠标移动器那些a,b,c变量时.我一直得到":错误CS0103:当前上下文中不存在名称'xxxx'".这发生在今天.我创建了这个全新的应用程序,除了这个简单的方法之外什么都没有.

这是我到目前为止所做的.重启visual studio,重置所有设置.但仍然得到相同的错误消息.我认为它是视觉工作室.

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {

    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        int d = test();

        app.UseIISPlatformHandler();

        app.Run(async (context) =>
        {
            await …
Run Code Online (Sandbox Code Playgroud)

visual-studio asp.net-core-mvc

2
推荐指数
1
解决办法
1657
查看次数