小编Dil*_*lma的帖子

FormsAuthentication.SetAuthCookie使用Moq进行模拟

嗨,我正在对我的ASP.Net MVC2项目进行一些单元测试.我正在使用Moq框架.在我的LogOnController中,

[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl = "")
{
  FormsAuthenticationService FormsService = new FormsAuthenticationService();
  FormsService.SignIn(model.UserName, model.RememberMe);

 }
Run Code Online (Sandbox Code Playgroud)

在FormAuthenticationService类中,

public class FormsAuthenticationService : IFormsAuthenticationService
    {
        public virtual void SignIn(string userName, bool createPersistentCookie)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot     be null or empty.", "userName");
            FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
        }
        public void SignOut()
        {
            FormsAuthentication.SignOut();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我的问题是如何避免执行

FormsService.SignIn(model.UserName, model.RememberMe);
Run Code Online (Sandbox Code Playgroud)

这条线.或者有没有办法去Moq

 FormsService.SignIn(model.UserName, model.RememberMe);
Run Code Online (Sandbox Code Playgroud)

使用Moq框架而不更改我的ASP.Net MVC2项目.

c# unit-testing moq asp.net-mvc-2

8
推荐指数
1
解决办法
5284
查看次数

Spark数据帧使用随机数据添加新列

我想在数据框中添加一个新列,其值由0或1组成.我使用了'randint'函数,

from random import randint

df1 = df.withColumn('isVal',randint(0,1))
Run Code Online (Sandbox Code Playgroud)

但我得到以下错误,

/spark/python/pyspark/sql/dataframe.py",第1313行,在withColumn断言isinstance(col,Column)中,"col应该是列"AssertionError:col应该是Column

如何使用自定义函数或randint函数为列生成随机值?

python apache-spark apache-spark-sql pyspark

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

如何在Eclipse Java Dynamic Web Project中使用.properties文件?

我正在Eclipse中开发一个Dynamic Web Project.我为商店数据库详细信息(用户名,密码等)创建了一个.properties文件.我通过右键单击项目和New - > File添加了它.我使用了Java util包Properties类.但它不起作用.我无法从文件中检索任何属性.这是我使用的代码,

Properties prop = new Properties();

    try {

        prop.load(new FileInputStream("database.properties"));

        String db = prop.getProperty("database");
        String userName = prop.getProperty("dbuser");
        String password = prop.getProperty("dbpassword");

    } catch (IOException ex) {
        ex.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

有什么不对或有什么特别的地方我应该放置属性文件.

java eclipse properties java-ee

5
推荐指数
1
解决办法
4万
查看次数