我已经更新了我的.gitignore文件,现在我想更新索引.我想执行git rm --cached命令.但是我怎么能通过TortoiseGit来做呢?
我创建Web API已有一段时间了,很高兴能够测试CQRS处理程序(由Mediatr管理)而无需接触任何类型的基础架构代码(控制器,requets等)。在执行控制器应该做的事情时非常薄:请求和响应之间的通信:
[HttpGet("requests")]
public async Task<IEnumerable<AbsenceRequest>> GetAbsenceRequests(GetAbsenceRequests.Query query)
{
return await _mediator.Send(query);
}
Run Code Online (Sandbox Code Playgroud)
但是仍然存在我的Handlers测试无法涵盖的情况。这里有几个例子:
ASP.NET Core使请求输入响应输出集成测试非常容易(由于使用了TestServer),我可以在集成测试中介绍这两种情况。
让我困扰的问题是我应该通过发送请求并声明响应来保持Handlers测试还是测试动作。
我真的很喜欢Handler测试。它们很可爱,清晰而且易于编写。测试整个请求的功能要强大得多,但同时它却是一个相对较低级别的方法,因此杂乱无章,您必须处理http和json。
我发现此选择非常令人困惑,并且想知道推荐的方法是什么。
我想指定一个环境变量,以便可以验证它是否是阶段/生产/开发环境(ASPNETCORE_Environment或自定义环境)。默认情况下是八达通吗?还是必须手动设置?
我真的很喜欢使用静态方法(特别是对于helpers类).但是由于静态方法不是顽固的,最终它们是一种不好的做法,不是吗?所以我必须在静态方法使用方便性和可测试性之间做出选择.有任何妥协吗?
在我的C#编码体验期间,我看到了许多代码片段,其中使用了IDictionary [index] setter来添加新值:
var dictionary = new Dictonary<long, string>();
...
dictionary[1] = "one"; //assume we want to add new value here
Run Code Online (Sandbox Code Playgroud)
因此,不使用dictionary.Add(1,"one")开发人员通过索引器调用重写旧值(如果存在)(等于AddOrUpdate操作);
我认为当您尝试将值设置为已存在的键时,字典应该抛出异常(就像当您尝试获取非现有键时它会抛出).这是一个争论性的陈述,但我想将我的观点与你的观点进行比较.
有一个并行编程的法则,但我找不到它的链接.简而言之,它告诉您:如果您的程序按顺序执行1/3(在一个线程中),您只能将应用程序性能提高3倍.
Abstract Factory/Factory方法的经典实现基于多态性.但在最低级别,我们必须有一些不基于多态性的工厂,并打破开放原则:
public Device Create(string deviceName)
{
switch (deviceName)
{
case "Device1": return new Device1();
case "Device2": return new Device2()'
default: throw new NotSupportedDeviceException(deviceName);
}
}
Run Code Online (Sandbox Code Playgroud)
这种工厂有什么特别的名字吗?
当我创建一个新的ASP.NET MVC项目时,会创建两个带下划线的文件:Views/_ViewStart.cshtml和Views/Shared/_Layout.cshtml.下划线是什么意思?
让我们假设我已经通过Activator.CreateInstance实例化了泛型类型.如果我在编译时没有T(但我把它作为Type实例),有没有办法将它强制转换为ISomeInterface?
这是一个示例:
public static IPropertyAssertions<T> ShouldHave<T>(this T subject)
{
var implementedInterfaces = subject.GetType().GetInterfaces();
foreach (var interfaceType in implementedInterfaces)
{
if (!interfaceType.IsGenericType)
continue;
var genericType = interfaceType.GetGenericTypeDefinition();
if (genericType == typeof(IEnumerable<>))
{
var genericTypeArg = genericType.GetGenericArguments()[0];
var collectionPropertyAssertionsType = typeof (CollectionPropertyAssertions<>);
Type makeme = collectionPropertyAssertionsType.MakeGenericType(genericTypeArg);
return (IPropertyAssertions<ToDo: specify argument type here>) Activator.CreateInstance(makeme);
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
所以我有可以调用的扩展方法IEnumerable<T>.在这种情况下,我想不返回,CollectionPropertyAssertions<IEnumerable<T>>但CollectionPropertyAssertions<T>T是枚举元素的类型.
.net ×4
c# ×3
asp.net-core ×1
asp.net-mvc ×1
cqrs ×1
generics ×1
git ×1
mediatr ×1
razor ×1
tortoisegit ×1