小编Mar*_*sF8的帖子

使用 EF Core 和内存数据库进行单元测试

我正在使用 ASP.NET Core 2.2、EF Core 和 MOQ。正如您在以下代码中所看到的,我有两个测试,并且同时运行,两个数据库名称均为“MovieListDatabase” 我在其中一个测试中出现错误并显示此消息:

Message: System.ArgumentException : An item with the same key has already 
been added. Key: 1
Run Code Online (Sandbox Code Playgroud)

如果我分别运行每一个,它们都会通过。

而且,在两个测试中使用不同的数据库名称,例如“MovieListDatabase1”和“MovieListDatabase2”并且同时运行它再次通过。

我有两个问题:为什么会发生这种情况?以及如何重构我的代码以在两个测试中重用内存数据库并使我的测试看起来更简洁?

 public class MovieRepositoryTest
{
    [Fact]
    public void GetAll_WhenCalled_ReturnsAllItems()
    {

        var options = new DbContextOptionsBuilder<MovieDbContext>()
            .UseInMemoryDatabase(databaseName: "MovieListDatabase")
            .Options;

        // Insert seed data into the database using one instance of the context
        using (var context = new MovieDbContext(options))
        {
            context.Movies.Add(new Movie { Id = 1, Title = "Movie 1", YearOfRelease = 2018, Genre = "Action" }); …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing entity-framework moq .net-core

18
推荐指数
4
解决办法
2万
查看次数

ng-bootstrap无法在角度4中工作

我是角度4的新手,我正在尝试配置bootstrap.我安装了ng-bootstrap:

https://ng-bootstrap.github.io/#/getting-started

我在页面上做了所有的事情,但我在页面上看不到引导程序.这是我的代码:

SRC /应用程序/ app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { FormsModule } from '@angular/forms';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';

@NgModule({
  declarations: [
    AppComponent
  ],
imports: [
   BrowserModule,
   FormsModule,  // add  this
   NgbModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

SRC /应用程序/ app.component.html

<div class="container">

<h1 class="text-primary">{{title}} </h1>

<h2 class="text-primary">My Heroes</h2>
<ul class="heroes">
  <li *ngFor="let hero of heroes"
    [class.selected]="hero === selectedHero"
    (click)="onSelect(hero)"> …
Run Code Online (Sandbox Code Playgroud)

twitter-bootstrap bootstrap-4 ng-bootstrap angular angular4-forms

15
推荐指数
1
解决办法
3万
查看次数

模拟EF核心dbcontext和dbset

我正在使用ASP.NET Core 2.2,EF Core和MOQ。当我运行测试时,出现此错误:

消息:System.NotSupportedException:在非虚拟(在VB中可重写)成员上的无效设置:x => x.Movies

我做错了什么?

public class MovieRepositoryTest
{
    private readonly MovieRepository _sut;

    public MovieRepositoryTest()
    {
        var moviesMock = CreateDbSetMock(GetFakeListOfMovies());
        var mockDbContext = new Mock<MovieDbContext>();
        mockDbContext.Setup(x => x.Movies).Returns(moviesMock.Object);
        _sut = new MovieRepository(mockDbContext.Object);
    }

    [Fact]
    public void GetAll_WhenCalled_ReturnsAllItems()
    {
        //Act
        var items = _sut.GetAll();

        //Assert
        Assert.Equal(3, items.Count());
    }

    private IEnumerable<Movie> GetFakeListOfMovies()
    {
        var movies = new List<Movie>
        {
            new Movie {Id = 1, Title = "Movie 1", YearOfRelease = 2018, Genre = "Action"},
            new Movie {Id = 2, …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing moq entity-framework-core asp.net-core

8
推荐指数
3
解决办法
5089
查看次数

使用AngularJS和HTML 5验证URL

大家早上好:

看起来像一个非常常见的问题,但谷歌搜索几个小时后,我无法弄清楚:如何验证包括www没有的URL http.

这些是我做的:

  1. 使用输入类型url:它不接受www.google.com;
  2. 将输入类型更改为text并使用ng-pattern:我仍然得到www.google.com无效;
  3. 改变了不同的正则表达式但仍然没有工作.

因此,当我单击提交按钮时,如果表单无效,我会显示警告(true true,false valid).这是我的Plunker

谢谢您的帮助

html regex validation angularjs

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

无法运行 Swagger UI

我有一个 .NetCore Web API 项目。我正在尝试使用 Swagger 来实现它。所有配置看起来都不错,但是当我运行我的项目时,我收到 404 错误,页面未找到。

这是我的代码:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton(_config);
        services.AddTransient<IRestHelper, RestHelper>();
        // Add framework services.
        services.AddApplicationInsightsTelemetry(_config);

        services.AddMvc();
        services.AddSwaggerGen(config =>
        {
            config.SwaggerDoc("v1", new Info { Title = "Slack Relay API", Version = "v1" });
        });
    }


     public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(_config.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseApplicationInsightsRequestTelemetry();

        app.UseApplicationInsightsExceptionTelemetry();
        app.UseMvc();
        app.UseSwagger(c =>
        {
            c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value);
        });

        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs");
        });
    }
Run Code Online (Sandbox Code Playgroud)

我的 Web API 基本 url 是: …

asp.net-web-api swagger swagger-ui asp.net-core asp.net-core-webapi

2
推荐指数
1
解决办法
8309
查看次数

OIDC 云代理与 SIOP 边缘代理

我们正在启动一个带有去中心化身份 (DID) 的 POC(概念证明),并获得了一份讨论要使用的身份验证方法的文档:

OIDC 云代理与 SIOP 边缘代理。

不明白那两个东西是什么?以及使用一种或另一种的优点或缺点是什么。

我知道 OpenId Connect 但不知道这两个,任何解释或阅读链接都将不胜感激。

谢谢

openid-connect hyperledger-indy decentralized-identity decentralized-identifiers

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