'*.deps.json'文件应该与程序集一起分发还是在nuget包中分发?
AddPooledDbContextFactory我最近在 NET 5 自学文章中发现了这个概念,并热衷于正确实施它。但是,我不确定如何将它与我通常使用的泛型一起使用。
我当前的设置示例:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<TestDbContext>(
(s, o) => o.UseNpgsql(Configuration.GetConnectionString("DatabaseConnection"))
.UseLoggerFactory(s.GetRequiredService<ILoggerFactory>()));
// other code //
}
Run Code Online (Sandbox Code Playgroud)
我的存储库通用:
public class Repository<T> : IRepository<T> where T
{
private readonly TestDbContext _dbContext;
public Repository(TestDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task Create(T entity)
{
await _dbContext.Set<T>().AddAsync(entity);
await _dbContext.SaveChangesAsync();
}
// other methods //
}
Run Code Online (Sandbox Code Playgroud)
作为示例,这是通过以下方式调用的:
public class WeatherForecastController : ControllerBase
{
private readonly IRepository<Test> testRepo;
public WeatherForecastController(IRepository<Test> testRepo)
{
this.testRepo= testRepo;
}
[HttpGet]
public async …Run Code Online (Sandbox Code Playgroud) c# entity-framework entity-framework-core asp.net-core .net-5
嗨,我是git的新手,我不明白git reset和之间的基本区别是什么git revert.是否git revert还原了合并?
在ASP.NET Core Web应用程序(.NET Framework)中,有一个app.config文件包含:
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但是此文件在ASP.NET Core Web应用程序(.NET Core)项目中不可用.ASP.NET Core Web应用程序(.NET Framework)需要GC以server模式运行吗?
我想要模拟懒惰的界面,但我得到了object reference not set to an instance of an object例外.
这是被测试的课程:
public class ProductServiceService : IProductServiceService
{
private readonly Lazy<IProductServiceRepository> _repository;
private readonly Lazy<IProductPackageRepository> _productPackageRepository;
public ProductServiceService(
Lazy<IProductServiceRepository> repository,
Lazy<IProductPackageRepository> productPackageRepository)
{
_repository = repository;
_productPackageRepository = productPackageRepository;
}
public async Task<OperationResult> ValidateServiceAsync(ProductServiceEntity service)
{
var errors = new List<ValidationResult>();
if (!await _productPackageRepository.Value.AnyAsync(p => p.Id == service.PackageId))
errors.Add(new ValidationResult(string.Format(NameMessageResource.NotFoundError, NameMessageResource.ProductPackage)));
.
.
.
return errors.Any()
? OperationResult.Failed(errors.ToArray())
: OperationResult.Success();
}
}
Run Code Online (Sandbox Code Playgroud)
这是测试课
[Fact, Trait("Category", "Product")]
public async Task …Run Code Online (Sandbox Code Playgroud) 例如,我会得到一个小时的时间,类型DateTime是这样的
并且每次 30 分钟我都喜欢将值输入到一个List<DateTime>
so 中,我怎样才能将值放入一个看起来像这样的列表中?
我的代码
DateTime starTime = new DateTime();
DateTime endTimes = new DateTime();
DateTime interval = new DateTime();
List<DateTime> intervals = new List<DateTime>();
starTime = DateTime.ParseExact(fulldate + "00:00",
"yyyy/MM/dd HH:mm",
CultureInfo.InvariantCulture);
endTimes = DateTime.ParseExact(fulldate + "02:00",
"yyyy/MM/dd HH:mm",
CultureInfo.InvariantCulture); ;
interval = starTime;
for (int i = 0; i < 24; i++)
{
interval.AddHours(0.5);
intervals.Add(interval);
if (interval.ToString("HH:mm") == endTimes.ToString("HH:mm"))
{
break;
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个enum下拉列表:
@Html.EnumDropDownListFor(model => model.Type, "-- Choose --", new { @class = "postfix" })
Run Code Online (Sandbox Code Playgroud)
为枚举下拉列表生成的html代码是:
<select data-val="true" data-val-required="Select type of ..." id="Type" name="Type" class="valid">
<option selected="selected" value="0">-- Choose --</option>
<option value="1">?Hotel</option>
<option value="2">Flight</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我不希望optionLabel的值为0,因为此值使下拉列表有效并且不会显示任何错误消息.我怎么能阻止这个?
我正在尝试AnyAsync使用以下代码在我的存储库中模拟方法,但存储库总是返回false.
签名AnyAsync是:
Task<bool> AnyAsync<TEntity>(Expression<Func<TEntiry, bool>> predicate)
Run Code Online (Sandbox Code Playgroud)
我尝试了以下设置:
1:
mockCustomerRepository.Setup(r => r.AnyAsync(c => c.Email == "some@one.com"))
.ReturnsAsync(true);
Run Code Online (Sandbox Code Playgroud)
2:
Expression<Func<CustomerEntity, bool>> predicate = expr =>
expr.CustomerPerson.Email == "some@one.com";
mockCustomerRepository.Setup(r => r.AnyAsync(It.Is<Expression<Func<CustomerEntity, bool>>>
(criteria => criteria == predicate))).ReturnsAsync(true);
Run Code Online (Sandbox Code Playgroud)
3:
mockCustomerRepository.Setup(r => r.AnyAsync(It.IsAny<Expression<Func<CustomerEntity, bool>>>()))
.ReturnsAsync(true);
Run Code Online (Sandbox Code Playgroud)
我的测试:
public class Test
{
Mock<ICustomerRepository> mockCustomerRepository;
public Test()
{
mockCustomerRepository = new Mock<ICustomerRepository>();
}
[Fact]
public async Task CustomerTest()
{
var customer = ObjectFactory.CreateCustomer(email: "some@one.com");
var sut = new CustomerService(mockCustomerRepository.Object);
var result …Run Code Online (Sandbox Code Playgroud) 我想做的是添加一个新的管理员用户,并为其分配管理员角色。所以..我去了方法Startup.cs类,Configure并编写了以下代码:
var context = app.ApplicationServices.GetService<ApplicationDbContext>();
// Getting required parameters in order to get the user manager
var userStore = new UserStore<ApplicationUser>(context);
// Finally! get the user manager!
var userManager = new UserManager<ApplicationUser>(userStore);
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误消息:
严重性代码说明项目文件行抑制状态错误CS7036没有给出与UserManager.UserManager(IUserStore,IOptions,IPasswordHasher,IEnumerable>,IEnumerable>,ILookupNormalizer,IdentityErrorDescriber,IServiceProvider,ILogger>的必需形式参数'optionsAccessor'相对应的参数)'FinalProject..NETCoreApp,Version = v1.0 C:\ Users \ Or Natan \ Documents \ Visual Studio 2015 \ Projects \ FinalProject \ src \ FinalProject \ Startup.cs 101有效
这个错误在这里使我丧命。.显然,我需要userManager来创建新用户,但是我无法初始化该东西。
我有项目A,其对项目的依赖B,但也从没有提及B到A.我想建立和复制组件bin folder项目B,以bin folder项目A.我怎么能用post build事件做到这一点dotnet msbuild.
我找到了这个链接,但它适用于VS 2015及以下和MS-Build:
msbuild post-build-event visual-studio .net-core visual-studio-2017
c# ×5
asp.net-core ×3
.net-core ×2
mocking ×2
moq ×2
unit-testing ×2
.net-5 ×1
asp.net-mvc ×1
enums ×1
git ×1
linq ×1
msbuild ×1
user-roles ×1