我用EF6和我的Base存储库Save()看起来像这样
public void Save()
{
try
{
Context.SaveChanges();
}
catch (DbEntityValidationException ex)
{
//Do Stuff
}
catch (Exception exception)
{
//Do stuff.
}
else
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
DbEntityValidationException如果对象保存无效,则是EF的预期错误.现在我正在使用新的.NET Core 2项目,我需要知道EF Core中的预期实体验证错误类型是什么.
c# entity-framework entity-framework-core asp.net-core asp.net-core-2.0
我想对被测试的类订阅的依赖项引发的事件进行单元测试。为了设置上下文,我有以下接口和类。
ITestedService.cs
public interface ITestedService
{
Task Start();
Task Stop();
}
Run Code Online (Sandbox Code Playgroud)
IDependency.cs
public interface IDependency
{
event EventHandler<SoAndSoEventArgs> SomethingHappened;
Task Start();
Task Stop();
}
Run Code Online (Sandbox Code Playgroud)
ISecondDependency
public interface ISecondDependency
{
Task DoYourJob(SoAndSo soAndSo);
}
Run Code Online (Sandbox Code Playgroud)
测试服务.cs
public class TestedService : ITestedService
{
readonly IDependency m_dependency;
readonly ISecondDependency m_secondDependency;
public TestedService(
IDependency dependency,
ISecondDependency secondDependency)
{
m_dependency = dependency;
m_secondDependency = secondDependency;
}
public async Task Start()
{
m_dependency.SomethingHappened += OnSomethingHanppened;
await m_dependency.Start();
}
private async void OnSomethingHanppened(object sender, SoAndSoEventArgs args)
{
SoAndSo …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我们使用 C# 字典在内存中缓存大型业务对象。
我正在将巨大的多轮引用 C# 对象(JSON 序列化时约为 300KB)转换为 DTO,以用于 Redis 缓存的 JSON 序列化/反序列化。
由于参数化构造函数,我的业务层中的某些类型似乎无法轻松初始化。
有没有一种方法可以在不序列化的情况下进行 Redis 缓存?这样可以返回我缓存的相同对象吗?
如何在 win 10 Visual Studio 2015 Simulator 的默认分辨率列表中添加/更改分辨率
我想将图像上传到 S3 存储桶。它是一个 HTTP 请求吗?或者我是否必须使用 AWS 工具包和 SDK 或其他东西。文档似乎很整洁/