小编Jee*_*Jsb的帖子

用于存储过程方法的C#单元测试

我使用实体库代替实体框架来执行数据操作。

以下是我的示例BL方法,该方法用于更新人的文化。我不知道如何为这种方法编写单元测试。

public static Culture UpdatePersonCulture(Guid userId, Culture culture)
{
    try
    {
        if (userId == Guid.Empty)
            throw new exception("User id should not be empty");

        DatabaseProviderFactory factory = new DatabaseProviderFactory();
        Database database = factory.CreateDefault();

        using (DbConnection dbConnection = database.CreateConnection())
        {
            if (dbConnection.State == ConnectionState.Closed)
                dbConnection.Open();

            DbCommand dbCommand = database.GetStoredProcCommand("usp_UpdatePersonCulture");
            database.DiscoverParameters(dbCommand);
            dbCommand.Parameters["@userId"].Value = userId;
            dbCommand.Parameters["@cultureId"].Value = culture.Id;

            DataSet dataSet = database.ExecuteDataSet(dbCommand);

            return BLDataPopulation.PopulateCultures(dataSet.Tables[0]).FirstOrDefault();
        }
    }
    catch (Exception exception)
    {
        throw BLLogger.Log(exception);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# unit-testing stored-procedures

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

在 Quartz.net 中,一次运行一个作业实例

我已经提到了以下问题,但没有帮助我解决问题。

在 Quartz.NET 中,有没有一种方法可以设置一个只允许一个 Job 实例运行的属性?

https://github.com/quartznet/quartznet/issues/469

对于 CronTrigger,在调度程序中使用了以下内容cs.WithMisfireHandlingInstructionDoNothing()

HelloJob
DisallowConcurrentExecution.

代码怎么了?
在 Execute 方法中,我已经设置了断点。根据我的代码,execute 方法将在每个 10 秒内执行。

打到第一个断点后,又等了31秒。然后我删除了断点并执行了代码,根据我的期望,应该只执行一次以进行另一次尝试。

但是 execute 方法在另外 10 秒内执行了 3 次(3*10 秒)。

如何解决这个问题?

调度程序代码。

ISchedulerFactory schedFact = new StdSchedulerFactory();
IScheduler sched = schedFact.GetScheduler();
sched.Start();

// define the job and tie it to our HelloJob class
IJobDetail job = JobBuilder.Create<HelloJob>()
    .WithIdentity("myJob", "group1")
    .Build();

// Trigger the job to run now, and then every 40 seconds
ITrigger trigger = trigger = TriggerBuilder.Create()
    .WithIdentity("trigger3", …
Run Code Online (Sandbox Code Playgroud)

c# quartz.net

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

Angular 5 - 指令中的生命周期钩子

我是 Angular 5 的新手。
我已经为外部 JS 库创建了指令。
但是在同一个指令中,我将值绑定到属性。

我试图起诉ngAfterViewInit以检测是否所有值都绑定到该属性,然后调用 jQuery 插件。

但是我只找到了组件的生命周期钩子。我可以在指令中使用那些吗?这是一个不错的选择吗?

<div *ngFor="let item of easypiechartOptions"
    [option]="item"
    appEasyPieChart
    [attr.data-percent]="item.percent">
</div>
Run Code Online (Sandbox Code Playgroud)

如果我不使用ngAfterViewInit,那么当我调用 jQuery 插件时,这些值不会被绑定。
如果我使用它,当我调用 jQuery 插件时,属性值就准备好了。

javascript jquery directive angular5

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

如何对HttpContext.Current.Server.MapPath进行单元测试

我正在使用HttpContext.Current.Server.MapPath()我的方法来获取文档.

要为此方法编写单元测试,

我该怎么做:

  1. App.config中
  2. 在我的单元测试方法中

我怎么嘲笑这个?

我经历做一个单元测试只对Current.Server.Mappath()Path.Combine()

asp.net unit-testing

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

如何查看代码不覆盖块

我正在使用Visual Studio Premium 2012.

在单元测试中,它仅显示未覆盖的块数,但它不显示我未覆盖的块.

在visual studio 2010中,它显示了未覆盖的块数以及我没有用不同颜色覆盖的块.

如何知道我没有覆盖哪个区块?如何使用VS premium 2012来了解我没有覆盖哪个块?

c# unit-testing visual-studio-2012

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

如何并行运行子程序?

for(i=0; i<5; i++)
{
  method1();
}

sub method1()
    {
           // here do something
    }
Run Code Online (Sandbox Code Playgroud)

这里我在for循环中调用了method1子程序.在这里,我希望在不等待先前调用的结果的情况下调用(并行)此method1子例程.怎么做 ?除了线程之外还有其他方法吗?

parallel-processing perl

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