我们有机器规格,我们有specflow.Specflow将文本描述转换为单元测试.但是有没有任何工具可以使用NUnit灯具并创建类似于Specflow输入的文本描述?基本上与specflow正在做的相反.
我准备调整关于灯具名称和测试方法名称的单元测试格式.但我宁愿不使用任何超级花哨的语法,如机器规格,而只是简单的NUnit测试夹具.原因是测试很重要,需要可重构等.文本格式不像单元测试那样重构友好.
例如:
[TestFixture]
class Given_Four
{
private Calculator c;
[SetUp]
public void Setup()
{
c = new Calculator(4);
}
[Test]
public void When_adding_two_then_sum_should_be_six()
{
c.Add(2)
Assert.That(c.Display, Is.EqualTo(6));
}
}
Run Code Online (Sandbox Code Playgroud)
再次,这只是一个例子.基本上任何格式的都可以工作,只要该工具创建该测试夹具的文本描述.我一直在谷歌上搜索,但一无所获.难道你知道有这样的工具吗?
我注意到Resharper在"通用实践和代码改进"下的建议:将局部变量或字段转换为常量.
我也注意到在比尔瓦格纳的书" 有效的C#:50改进你的C#的具体方法 "中,有一个语言成语" 首选只读取const ",其中作者解释了使用consts的风险.
我的问题不是关于readonly和const之间的区别以及何时使用它们,而是为什么一个源将const作为常见的练习/代码改进而另一方面第二个将readonly视为一个成语?
我有以下课程:
public interface IServiceA
{
string MethodA1();
}
public interface IServiceB
{
string MethodB1();
}
public class ServiceA : IServiceA
{
public IServiceB serviceB;
public string MethodA1()
{
return "MethodA1() " +serviceB.MethodB1();
}
}
public class ServiceB : IServiceB
{
public string MethodB1()
{
return "MethodB1() ";
}
}
Run Code Online (Sandbox Code Playgroud)
我使用Unity for IoC,我的注册看起来像这样:
container.RegisterType<IServiceA, ServiceA>();
container.RegisterType<IServiceB, ServiceB>();
Run Code Online (Sandbox Code Playgroud)
当我解析一个ServiceA实例时,serviceB将是null.我该如何解决这个问题?
c# ioc-container inversion-of-control unity-container property-injection
我想获得一个MyAttribute使用T4/EnvDTE 装饰的项目中所有公共方法的列表.
我知道这可以用反射来实现,但我不希望加载的组装和反映了它在T4模板,相反,我想用现有的代码文件作为来源.
以下是我在互联网上找到的样板代码,它获取对当前项目的引用
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="System.Core.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
<#
IServiceProvider _ServiceProvider = (IServiceProvider)Host;
if (_ServiceProvider == null)
throw new Exception("Host property returned unexpected value (null)");
EnvDTE.DTE dte = (EnvDTE.DTE)_ServiceProvider.GetService(typeof(EnvDTE.DTE));
if (dte == null)
throw new Exception("Unable to retrieve EnvDTE.DTE");
Array activeSolutionProjects = (Array)dte.ActiveSolutionProjects;
if (activeSolutionProjects == null)
throw new Exception("DTE.ActiveSolutionProjects returned null"); …Run Code Online (Sandbox Code Playgroud) 我正在使用swagger/swashbuckle为Web Api 2中实现的api生成文档.
唯一识别的xml文档标签是<summary>,<remarks>和<param>.
这意味着我无法使用<para>标记在新行或段落中格式化我的文本,所有内容都在文档的Implementation Notes条目中生成为连续的长段落.
有没有办法做到这一点?
我有3个表PostText,PostImage和PostVideo.现在我将来自上述三个表的数据组合成一个名为的单个数组userposts.
现在userposts我只想访问以offset 15开头的10条记录.
我怎样才能做到这一点?
我试过了userposts.first(10).它给了我前十条记录,但我想要从offset-15开始的10条记录.
提前致谢.
我经常不使用T4模板; 通常在我这样做时正在编辑其他项目(特别是SubSonic和T4MVC).经验总是令人不快(这也是我不经常使用它们的原因).
这些是我所知道的工具,它们都不符合要求.
我第一次尝试使用它时,我认为Visual Studio 2010已经崩溃了.结果我没等多久(编辑器窗口出现花了2分多钟).叫我挑剔,但这一点让我脱离了这个工具.
我有一个修改过的T4MVC模板.安装Tangible的T4编辑器后,模板失败并出现多个错误.如果我然后卸载Tangible的T4编辑器,模板将再次运行.因此,编辑器会改变Visual Studio中T4的行为.也许显然,这是完全不可接受的.
我错过了还有其他T4编辑吗?是否有其他人使用这些工具,遇到这些相同的问题,并成功使用它们?
我还应该说,对我来说最重要的功能就是区分作为模板一部分运行的代码和获得输出的代码/文本.其他一切都是肉汁.
我查看了并发集合,但它们似乎在引擎盖下使用了正常锁定..Net框架中是否有任何使用此锁定构造的好例子?
我最初看过ConcurrentDictionary.我看到它使用普通锁,但BlockingCollection类在其内部方法中使用SpinWait.
使用 .NET 6 Minimal API,我尝试multipart/form-data在 POST 方法中进行处理。但是,使用以下代码:
app.MapPost("/tickets", async (IFreshdeskApiService s, [FromForm] CreateTicketDto dto) => await s.Add(dto))
.Accepts<CreateTicketDto>("multipart/form-data");
Run Code Online (Sandbox Code Playgroud)
我收到 400 错误请求,正文为:
{
"error": "Expected a supported JSON media type but got \"multipart/form-data; boundary=--------------------------391539519671819893009831\"."
}
Run Code Online (Sandbox Code Playgroud)
我切换到非最小API(即使用app.MapControllers()),但是有什么方法可以在最小API中处理这个问题吗?
我有一个任务,我需要找到数组中所有数字的乘积,我不知道如何做到这一点.
int[] numbers = new int[SIZE];
Console.WriteLine("Type in 10 numbers");
Console.WriteLine("To stop, type in 0");
for (int input = 0; input < SIZE; input++)
{
userInput = Console.ReadLine();
numberInputed = int.Parse(userInput);
if (numberInputed == ZERO)
{
numberInputed = ONE;
break;
}
else
{
numbers[input] = numberInputed;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我试图找到数组中所有数字的乘积的地方.
foreach (int value in numbers)
{
prod *= value;
}
Console.WriteLine("The product of the values you entered is {0}", prod);
Run Code Online (Sandbox Code Playgroud)
我在foreach声明中做错了什么?提前致谢
编辑,省略我声明的值
const int SIZE = 10;
const int ZERO = …Run Code Online (Sandbox Code Playgroud) c# ×5
arrays ×2
t4 ×2
.net ×1
.net-6.0 ×1
asp.net-core ×1
const ×1
envdte ×1
limit ×1
line-breaks ×1
minimal-apis ×1
nunit ×1
offset ×1
readonly ×1
resharper ×1
rest ×1
ruby ×1
specflow ×1
spinlock ×1
spinwait ×1
swagger ×1
swagger-ui ×1
swashbuckle ×1
unit-testing ×1