小编Rub*_*ink的帖子

为什么不是xUnit.net的FactAttribute AttributeUsage.Inheritable?

以前没有编写单元测试框架,在我看来,如果程序集中的某些类型都需要针对类似的事情进行测试,那么可继承的Fact属性会使编写抽象测试类或测试接口变得更容易.

事实是否不可继承有设计理由吗?我认为使用属性来识别测试方法的其他测试框架(NUnit,MSTest,MbUnit等)也是类似的设计.我错过了什么?

这是xunit(版本1.9.1.1600)的FactAttribute的开头:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class FactAttribute : Attribute
{
Run Code Online (Sandbox Code Playgroud)

我试图理解为什么它看起来不像以下那样:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class FactAttribute : Attribute
{ 
Run Code Online (Sandbox Code Playgroud)

c# mbunit nunit mstest xunit.net

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

使用NInject时,在注入a a ctor arg时解析IEnumerable <T>会失败,但在执行Get <IEnumerable <T >>()时则不会

当我为IEnumerable设置绑定时使用NInject时,如果我直接请求IEnumerable,它将起作用,但如果另一个绑定对象需要IEnumerable则不行.这是设计的吗?

class Program {
    static void Main(string[] args){
        var k = new StandardKernel();
        k.Bind<IEnumerable<int>>().ToMethod(GetInts);
        k.Bind<IFoo>().To<Foo>(); //Has an IEnumberable<int> constructor arg
        var works = k.Get<IEnumerable<int>>(); //returns the array of ints
        var tst = k.Get<IFoo>(); //Empty integer array is passed in by ninject???
        tst.Get(); //returns an empty integer array????
        return;
    }

    public static int[] GetInts(IContext ctx){
        return new int[] {1,2,3,4,5};
    }
}


public interface IFoo{
    IEnumerable<int> Get();
}


public class Foo : IFoo{
    private int[] _vals;

    public Foo(IEnumerable<int> vals){
        _vals = vals.ToArray(); …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection ninject

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

xUnit v1测试出现在xUnit GUI(xunit.gui.clr4.exe)中但不出现在VS 2012 Test Explorer中

我有一个F#类库,其中包含使用NuGet安装的"xUnit.net"和"xUnit.net Runners"软件包.我有以下代码:

module XUnitTest

open Xunit

[<Fact>]
let Test () =
    do Assert.True (1 = 2)
    ()
Run Code Online (Sandbox Code Playgroud)

当我运行xUnit GUI(NuGet添加到(projectdirectory)\ packages\xunit.runners.1.9.1\tools的xunit.gui.clr4.exe)并加载由该项目构建的程序集时,Test()方法出现,并在我按预期运行时失败.

但是,我无法让测试出现在VS 2012的测试资源管理器中,无论我重建,重启等多少次.如果我单击全部运行,弹出构建输出窗口但没有其他任何事情发生.

为此,我还安装了xUnit.net Extensions,但我不认为它们对我正在尝试做的事情是必要的.这也没有帮助.

如果我能提供更多信息,请告诉我,谢谢你的阅读!

c# f# xunit.net visual-studio-2012 test-explorer

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

如何在C#中验证值集合是唯一的(不包含重复项)

当然有一种简单的方法来验证一组值没有重复[ 在C#/ .NET中使用默认Comparisoncollection's' Type?不必直接内置,但应简短有效.

我看了很多,但我一直在打算使用collection.Count() == collection.Distinct().Count()哪些对我来说效率低下.我对结果不感兴趣,并且一旦发现重复就想要拯救,如果是这样的话.

(如果有人可以指出重复的话,我想删除这个问题和/或答案)

.net c# collections ienumerable unique

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

处理AutoFixture和Moq之间的样本创建不一致

我在我的测试约定中使用AutoMoqCustomization.

请考虑以下代码.在我将一个构造函数添加到其中一个具体类之前,一切都很有效.当我这样做时,我得到"找不到无参数构造函数".我们知道AutoFixture没有构造函数的问题,因为它向我提供了测试对象one,该对象被证明可以从IThings分配......没有失败.所以一定是moq.

builder有点意义,因为我假设是由moq生成并传递给GetCommands方法.所以我想我可以看到控件已经从AutoFixture传递到moq.

这样可以解决原因,但我该怎么做呢?有没有办法指示moq如何处理ThingOne或有没有办法指示AutoFixture忽略moq for IThingBuilders而是做一些Fixtury?

public class TestClass
{
    public interface IThingBuilders
    {
        T1 Build<T1>() where T1 : IThings;
    }
    public interface IThings
    {
    }
    public class ThingOne : IThings
    {
        public ThingOne(string someparam)
        {
        }
    }
    public class ThingTwo : IThings
    {
    }
    public class SomeClass
    {
        public List<IThings> GetCommands(IThingBuilders builder)
        {
            var newlist = new List<IThings>();
            newlist.Add(builder.Build<ThingOne>());
            newlist.Add(builder.Build<ThingTwo>());
            return newlist;
        }
    }
    [Theory, BasicConventions]
    public void WhyCannotInstantiateProxyOfClass(ThingOne one, …
Run Code Online (Sandbox Code Playgroud)

moq autofixture

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

使用 CQRS 和 EventStore 时如何更新/迁移数据?

所以我目前正在研究 CQRS 架构和 EventStore“模式”。

它将应用程序打开到可扩展性和灵活性以及测试的新维度。

但是我仍然坚持如何正确处理数据迁移。

这是一个具体的用例:

假设我想管理一个包含文章和评论的博客。

在写入端,我使用 MySQL,在读取端 ElasticSearch,现在每次处理命令时,我都会在写入端持久化数据,在读取端调度一个事件来持久化数据。

现在让我们说我有某种 ViewModel 被调用ArticleSummary,它包含一个 id 和一个标题。

我有一个新的功能请求,要将文章标签包含到我的 中ArticleSummary,我会向模型添加一些字典以包含标签。

鉴于我的写入层中已经存在标签,我需要更新或使用新的“表”来正确使用新包含的数据。

我知道 EventLog Replay 策略包括重放所有事件以“更新”所有 ViewModel,但是,严肃地说,当我们有十亿行时它是否可行?

有没有经过验证的策略?任何反馈?

events domain-driven-design data-migration cqrs

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

在F#中定义我自己的预处理器指令

我有一个F#脚本,我打算在家里和工作中使用它.脚本在两个地方的工作方式都相似,但是,我在工作中遇到了一系列问题(主要是关于防火墙和http代理),所以我想在一个案例和一个案例中以稍微不同的方式运行我的脚本其他.

我想,理想情况下我会在FSI级别设置一个特殊的标志(指令),所以我可能需要#if AT_WORK处理一些尖锐的角落情况.

怎么做到这一点?

.net f# fsi

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

如何在xunit/autofixture中组合PropertyData和AutoNSubstituteData属性?

我正在使用[AutoNSubstituteData]这里发布的属性:

AutoFixture,xUnit.net和Auto Mocking

我想将它与[PropertyData("")]xunit扩展的属性结合起来.

这是我的测试:

public static IEnumerable<string[]> InvalidInvariant
{
    get
    {
        yield return new string[] { null };
        yield return new [] { string.Empty };
        yield return new [] { " " };
    }
}

[Theory, AutoNSubstituteData, PropertyData("InvalidInvariant")]
public void TestThatGuardsAreTriggeredWhenConnectionStringArgumentIsInvalid(
    IDeal deal,
    IDbConnection conn,
    IDb db,
    ISender sender,
    string invalidConnString,
    string query)
{
    deal.Init.Group.Returns(Group.A);
    deal.Aggr.Group.Returns(Group.A);
    deal.Product.Commodity.Returns(Product.Commodity.E);

    var sut = new Handler(db, sender);
    Assert.Throws<ArgumentException>(() => 
        sut.HandleDeal(deal, conn, invalidConnString, query));
}
Run Code Online (Sandbox Code Playgroud)

有没有办法组合这些属性或获得所需的功能(模拟一切,除了invalidConnstring,应该填充属性数据)?

unit-testing mocking xunit.net autofixture nsubstitute

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

使用对多个客户端的乐观并发检查实现事件存储

我正在尝试使用符合我所看到的各种 Greg Young 启发示例的实践和原则来实现一个事件溯源系统。

我了解版本检查逻辑是如何工作的,并且在保存聚合时,如果当前版本与预期版本不匹配,则意味着另一个会话/客户端应用程序在您之前更新了聚合。

我也知道您可以制定一种在保存并发事件时追溯解决冲突的方法,这个问题与这样做无关。

我想了解的是,在使用 nosql 数据库(例如 ravendb)作为事件存储的特定实现中,我将如何确保写入的事件不会因竞争条件而与版本号重叠。

以下代码来自一个示例项目来说明:

Repository<TAggregate>存储库类中有一个保存方法

    public void Save(AggregateRoot aggregate, int expectedVersion)
    {
        if (aggregate.GetUncommittedChanges().Any())
        {
            lock (_lockStorage)
            {
                var item = new T();

                if (expectedVersion != -1)
                {
//issue if two processes get to this line of code below together 
//and both have the same 'version to be expected' then start writing together
                    item = GetById(aggregate.Id); 
                    if (item.Version != expectedVersion)
                    {
                        throw new ConcurrencyException(string.Format("Aggregate {0} has been previously modified",
                                                                     item.Id));
                    } …
Run Code Online (Sandbox Code Playgroud)

optimistic-concurrency ravendb event-sourcing

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

使用 kafka 作为事件存储来补充事件源聚合

越来越多的文章谈论 kafka 作为事件存储并在使用 cqrs 和事件源构建的应用程序中使用它。如何查询kafka(作为事件存储)某个聚合的事件以完成写入端的操作?

cqrs event-sourcing apache-kafka

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