小编xer*_*him的帖子

Quartz.net 如何在触发器上设置 MisfireInstruction

在 Quartz 1.0.x 中,可以通过简单地设置触发器上的 MisfireInstruction 来设置它:

trigger.MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
Run Code Online (Sandbox Code Playgroud)

我们将 Quartz 版本升级到 2.3.2,现在不能再这样设置了,因为trigger.MisfireInstruction已经没有 setter 了。

现在如何在触发器上设置 MisfireInstruction?

我尝试使用 TriggerBuilder 重新创建触发器,如下所示:

trigger = trigger.GetTriggerBuilder()...
Run Code Online (Sandbox Code Playgroud)

但我也找不到 TriggerBuilder 上的 MisfireInstruction-Method。

谢谢你的帮助

.net c# quartz-scheduler quartz.net misfire-instruction

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

关键字global ::添加引用时

我今天遇到了一个奇怪的现象,因为我将一个项目的引用添加到另一个项目并尝试使用引用的程序集的接口:

情况:

  • 该课程MySampleApplication在该项目中MyApplication.
  • 接口IMySampleApplication位于引用的项目中MyApplication.Interfaces.

当我这样做:

public class MySampleApplication : IMySampleApplication
Run Code Online (Sandbox Code Playgroud)

Resharper使用以下内容添加以下内容:

using global::MyApplication.Interfaces;
Run Code Online (Sandbox Code Playgroud)

题:

为什么要添加global::前缀,我该如何避免这种情况?

提前致谢

.net c# resharper reference

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

string.Format exception输入字符串的格式不正确

我从string.Format(...)操作中收到以下错误:

System.FormatException - 输入字符串的格式不正确.

我有一个资源字典,其中包含一个带有基本html页面的条目.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title of the document</title>

    <style>
        * { 
            margin: 0; 
            padding: 0; 
        }

        body { 
            font-family: 'Arial, Verdana', Fallback, sans-serif; 
            font-size: 14px;
        }

        table { 
            background-color: #eeeeee; 
            width: 100%; 
            padding: 10px;
            margin: 5px;
        }

        h1 {
            font-size: 16px;
            font-weight: bold;
            margin: 20px 0 10px 0;
        }
    </style>
</head>

<body>
    text<br />

    <table>
        <tr>
            <td>Text 1</td>
            <td>{0}</td>
        </tr>
        <tr>
            <td>Text 2</td>
            <td>{1}</td>
        </tr>
        <tr>
            <td>Text 3</td>
            <td>{2}</td>
        </tr>
        <tr> …
Run Code Online (Sandbox Code Playgroud)

.net c# string string-formatting resourcedictionary

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

Specflow 无法识别步骤

我有一个包含以下内容的specflow特征文件When

When Request for servername 'someurl.com/szhm04c4.xml' is processed
Run Code Online (Sandbox Code Playgroud)

当我按F12Visual Studio 时,我会告诉我可以复制以下步骤定义:

[When(@"Request for servername '(.*)' is processed")]
public void WhenRequestForServernameIsProcessed(string p0)
{
    ScenarioContext.Current.Pending();
}
Run Code Online (Sandbox Code Playgroud)

我将其粘贴到继承Steps并实现它的步骤文件中

public void WhenRequestForServernameIsProcessed(string servername)
{
    var httpRequest = this.Bootstrapper.GetFake<IHttpRequest>();
    A.CallTo(() => httpRequest.Path).Returns(servername);

    var httpContext = this.Bootstrapper.Get<IHttpContext>();

    this.Bootstrapper.Get<IHostRequest>().Process(httpContext);
}
Run Code Online (Sandbox Code Playgroud)

当我执行测试时,它失败并收到以下错误消息:

TechTalk.SpecFlow.SpecFlowException 测试待决:未找到一个或多个步骤的匹配步骤定义。使用系统;使用 TechTalk.SpecFlow;

命名空间 MyNamespace { [Binding] public class StepDefinitions { [When(@"对服务器名称'(.*)'的请求已处理")] public void WhenRequestForServernameIsProcessed(string p0) { ScenarioContext.Current.Pending(); } } } }

这是为什么?我确实定义了这一步......

提前致谢

.net c# specflow

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

FakeItEasy虽然那里没有找到电话

我在FakeItEasy中遇到一些奇怪的问题。

想象一下以下单元测试方法:

[TestMethod]
public void DeletePerson_WhenCalled_ThenPersonIsDeleted()
{
    const int personId = 24;
    var commonParam = new CommonParam();

    this.testee.DeletePerson(commonParam, personId );

    A.CallTo(() => this.personRepository.DeletePersons(commonParam, new[] {personId }, false)).MustHaveHappened(Repeated.Exactly.Once);
    A.CallTo(() => this.personRepository.SaveChanges()).MustHaveHappened(Repeated.Exactly.Once);
}
Run Code Online (Sandbox Code Playgroud)

testee.DeletePerson-方法如下所示:

public ResultatModel DeletePerson(CommonParam commonParam, int personId )
{
    this.personRepository.DeletePersons(commonParam, new[] { personId });
    this.personRepository.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)

personRepository.DeletePersons(但是这个被fakeiteasy伪造了...):

public void DeletePersons(CommonParam commonParam, IEnumerable<int> ids, bool hardRemove = false)
    {
           var persons = Entities.per_person.Where(e => ids.Contains(e.personId)
            && (e.accountId == null || e.accountId == commonParam.AccountId)).ToList();

        if (hardRemove)
        { …
Run Code Online (Sandbox Code Playgroud)

.net c# unit-testing fakeiteasy

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

EntityFramework Core 6 升级无法加载类型 IAsyncQueryProvider

我已将 .NET Core 3.1 应用程序更新到 .NET 6,其中一个步骤是将 EntityFramwork Core 更新到版本 6.0.2。

不幸的是,我的许多单元测试现在都失败了,但有以下例外:

System.TypeLoadException:无法从程序集“Microsoft.EntityFrameworkCore,版本=6.0.2.0”加载类型“Microsoft.EntityFrameworkCore.Query.Internal.IAsyncQueryProvider”,

我不太确定为什么会发生这种情况。我已经阅读了迁移指南(https://learn.microsoft.com/en-us/aspnet/core/migration/31-to-60?view=aspnetcore-6.0&tabs=visual-studio),但还没有见过这样的事情。

以下是因此异常而失败的单元测试的一个示例:

[TestMethod]
public async Task IsPrivatKundeAsync_WithMatchingCriteria_ReturnsTrue()
{
    var data = new[] {
        new MyEntity { Partnernr = "1", Geburtstag = new DateTime(2000, 1, 1), Plz = "8000" },
        new MyEntity { Partnernr = "2", Geburtstag = new DateTime(2001, 2, 2), Plz = "8001" },
        new MyEntity { Partnernr = "3", Geburtstag = new DateTime(2002, 3, 3), Plz = "8002" },
    };

    var builder = …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework-core .net-6.0

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

C#Xml到Linq删除一个项目

我正在尝试将带有xml的项目移除到linq,但我无法让它工作:

XML

<books>
    <book>
        <title>Harry Potter und der Stein der Waisen</title>
        <isbn>1</isbn>
        <author>J. K. Rowling</author>
       <price>30</price>
    </book>
</books>
Run Code Online (Sandbox Code Playgroud)

DeleteItem

我正试图导航到特定元素,然后调用 .Remove()

public void DeleteItem(Book toRemove)
{
  var xmlDoc = this.xmlFileStorage.LoadXmlDocument();
  xmlDoc
      .Descendants("books")
          .Elements("book")
              .Where(x => 
                  x.Elements("title").Single(y => y.Value == toRemove.Title)
                        && x.Elements("author").Single(y => y.Value == toRemove.Author)
                        && x.Elements("isbn").Single(y => y.Value == toRemove.Isbn)
                        && x.Elements("price").Where(y => y.Value == toRemove.Price.ToString()))
                    .Remove();

    this.xmlFileStorage.SaveXmlDocument(xmlDoc);
}
Run Code Online (Sandbox Code Playgroud)

我不认为这.Single()是正确的方法......我如何从xml文档中获取确切的记录?

提前致谢

.net c# xml linq

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

加入后TSQL重复[奇怪的语法]

在我们古老的TSQL程序之一中,我发现这种结构会导致业务规则错误:

SELECT TOP 100 * 
FROM dbo.Table1 AS t1
LEFT JOIN dbo.Table2 AS t2
JOIN dbo.Table3 AS t3
       ON t3.c1 = t2.c1
       ON t2.c2 = t1.c2
Run Code Online (Sandbox Code Playgroud)

我将使用的正常语法是

SELECT TOP 100 * 
FROM dbo.Table1 AS t1
LEFT JOIN dbo.Table2 AS t2
    ON t2.c2 = t1.c2
JOIN dbo.Table3 AS t3
    ON t3.c1 = t2.c1
Run Code Online (Sandbox Code Playgroud)
  • 这个JOIN... ON... ON语法究竟是什么?
  • 这是一个交叉连接因为这on句话太迟了吗?
  • 为什么我在两个查询之间得到不同的结果?

提前致谢

t-sql sql-server sql-server-2008

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

如果调用静态记录器,如何进行单元测试

考虑一个try catch像这样的方法:

try
{
    person = this.personRepo.GetPerson(name);
}
catch (PersonException)
{
    LogHelper.LogDebug("PersonService", "No Person found!");
}
Run Code Online (Sandbox Code Playgroud)

在单元测试中,personRepo伪造的是FakeItEasy:

A.CallTo(() => this.personRepository.GetPerson(personName)).Throws(new PersonException("Person not found"));
Run Code Online (Sandbox Code Playgroud)

题:

如何检查静态记录器是否被调用?

.net c# logging unit-testing fakeiteasy

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