小编Dav*_*idS的帖子

为什么使用fluentvalidation而不是ASP.NET MVC验证

在哪种情况下你会选择FluentValidation(FV)而不是ASP.NET MVC 3方式

FV相对于MVC有什么优势?我意识到,对于后者,我们必须编写更多的代码,并且可以使用数据注释来丢弃代码.而且,使用FV编写自定义验证似乎比使用MVC更容易.但是,使用MVC可以使用数据注释并插入jQuery验证.

那么你认为什么会让你选择一个而不是另一个呢?有没有你甚至可以使用两者的情况?

validation fluentvalidation-2.0 asp.net-mvc-3

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

如何在 EF Core 6.0 中表示日期时间 - 没有时区的时间戳

我将 ASP.NET Core 项目从 3.1 迁移到 6.0。

我已复制旧迁移并将其粘贴到我们的新版本中

EF Core 3.1(旧)上的迁移

migrationBuilder.AddColumn<DateTime>(
                name: "CalendarStartDate",
                table: "DealOverview",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
Run Code Online (Sandbox Code Playgroud)

EF Core 6.0 中的迁移(新)

migrationBuilder.AlterColumn<DateTime>(
                name: "StartDate",
                table: "DealOverview",
                type: "timestamp without time zone",
                nullable: false,
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone");
Run Code Online (Sandbox Code Playgroud)

迁移失败,因为这一行

public DateTime StartDate { get; set; }
Run Code Online (Sandbox Code Playgroud)

已经改变。

我从这个包中走了出来:

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
Run Code Online (Sandbox Code Playgroud)

到这个包:

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.1" /> 
Run Code Online (Sandbox Code Playgroud)

c# postgresql entity-framework-core asp.net-core asp.net-core-6.0

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

Castle Windsor在运行时解决

我一直试图解决这个问题很长一段时间,我仍然没有更聪明.我有以下方法:

public IResult Parse(string[] args)
{
    var argumentOption = new ArgumentOption(_dataModelBinder);
    var boundArgumentOption = argumentOption.Bind(args);

    var bindingResults = boundArgumentOption.Validate(_argumentOptionValidator);

    // AREA OF INTEREST
    if (bindingResults.Any())
    {
        return new ErrorResult();
    }

    return new CreateReportResult(
        _resultActioner
        , boundArgumentOption.OutputFilePath
        , boundArgumentOption.PatientId
        , "database");
}
Run Code Online (Sandbox Code Playgroud)

我遇到麻烦的代码涉及到我正在创建的返回值,理想情况下我想留给温莎城堡处理.那么,我接下来要创建一个抽象工厂:

public interface IResultFactory
{
    IResult Create(int numOfErrors);
} 

public class ResultFactory : IResultFactory
{
    private readonly IWindsorContainer _container;

    public ResultFactory(IWindsorContainer container)
    {
        _container = container;
    }

    public IResult Create(int numOfErrors)
    {
        if (numOfErrors > 0)
        {
            return _container.Resolve<IResult>("ErrorResult"); …
Run Code Online (Sandbox Code Playgroud)

c# castle-windsor

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

使用 Clap 4 Rust 设置 Vec&lt;String&gt; 类型参数的默认值

在第 2 拍中,以下内容:

\n
.arg(\n   Arg::with_name("files")\n   .value_name("FILE")\n   .help("Input file(s)")\n   .multiple(true)\n   .default_value("-"),\n)\n
Run Code Online (Sandbox Code Playgroud)\n

将产生:

\n
USAGE:\n    catr [FLAGS] [FILE]...\n\nFLAGS:\n    -h, --help               Prints help information\n\n
Run Code Online (Sandbox Code Playgroud)\n

我想在 Clap 4 中使用deriveAPI 来表达这一点。

\n

所以,我得到了结构:

\n
pub struct Config{ // Define a public struct called Config.\n    /// The input files\n    #[arg(default_value_t= vec!["-".to_string()])]\n    files: Vec<String>,\n
Run Code Online (Sandbox Code Playgroud)\n

当我 时cargo build,我得到以下信息:

\n
[ 19:37:42 ] \xe2\x9d\xaf cargo build\n   Compiling catr v0.1.0 (/home/david/Work/Bitbucket/OReilly/Books/cmdlinerust/ch03/catr)\nerror[E0277]: `Vec<std::string::String>` doesn\'t implement `std::fmt::Display`\n  --> src/lib.rs:10:11\n   |\n10 |     #[arg(default_value_t=vec!["-".to_string()])]\n   |           ^^^^^^^^^^^^^^^ …
Run Code Online (Sandbox Code Playgroud)

rust clap

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

如何在asp.net mvc 2中使用fakeiteasy假冒用户登录以进行单元测试

我刚开始学习和使用ASP.NET MVC 2,并且更多地参与单元测试我的代码.我的问题是如何通过在我的测试中传入凭据来模拟用户登录.

我正在使用MSpec,并试图让我的头脑周围的假冒为了写我的测试.到目前为止,我相信我已经正确地编写了一个测试(它通过了测试条件),以供未经身份验证的用户尝试访问页面时使用.

Subject( typeof( HomeController ) )]
public class context_for_a_home_controller_for_not_logged_user
{
    protected static HomeController HomeController;

    Establish context = () =>
    {
        // Create controller
        HomeController = new HomeController();

        HomeController.ControllerContext = A.Fake<ControllerContext>();
    };
}

[Subject(typeof(HomeController))]
public class when_the_home_page_is_requested : context_for_a_home_controller_for_not_logged_user
{
    static ActionResult result;

    Because of = () => 
        result = HomeController.Index();

    It should_return_the_log_in_page_if_user_not_logged_in = () =>
        { result.ShouldBeAView().And().ShouldUseDefaultView(); };
}
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.但是,我想测试经过身份验证的用户何时命中主控制器的情况.我坚持如何模拟经过身份验证的用户,欢迎任何帮助或建议.

TIA,

大卫

intrinsics mspec asp.net-mvc-2

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

jqgrid数字格式化器使用

在我的格式化程序中,我有以下代码:

formatter: {
    number: { decimalSeparator: ".", thousandsSeparator: " ", decimalPlaces: 4, defaultValue: '0.0000' }
},
Run Code Online (Sandbox Code Playgroud)

在我的colModel中我有:

  { name: 'SalesPrice', index: 'SalesPrice', width: 90, align: 'left', formatter:'number', editable: true, editoptions:
                  {
                      readonly: true
                  }
                  }
Run Code Online (Sandbox Code Playgroud)

我的数据类型设置为"local"

当我第一次显示表单时,我得到"0.00"而不是"0.0000",正如我所希望的那样.此外,在内联编辑模式下,SalesPrice值会根据网格中的其他单元格而变化.更新后,SalesPrice值显示为整数.

我能做错什么?

编辑:更完整的代码

$("#customerOrderLineList").jqGrid({
    //      url: 'someUrl',
    datatype: 'local',
    formatter: {
        number: { decimalSeparator: ".", thousandsSeparator: " ", decimalPlaces: 4, defaultValue: '0.0000' }
    },
    //      mtype: 'POST',
    colNames: [ 'Part Number', 'Sales Price'],
    colModel: [
                  { name: 'PartNumber', index: 'PartNum', width: 90, align: 'left', …
Run Code Online (Sandbox Code Playgroud)

jqgrid jqgrid-formatter

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

AutoFixture设置夹具的声明方式背后的原理是什么?

我之前在SO 上问了一个类似的问题,我得到了答案.当时,为了方便起见,我机械地应用了答案,但现在我正试图弄清楚声明性地设置灯具的机制是怎样的.

因此,我目前正在研究Mark Seemann在没有公共建设者的情况下处理类型的博客文章,并将其转换为声明性的.它与我原来的查询非常相似,但我无法让它工作.请注意,给出的代码实际上不是生产代码,这是一个学习练习.

现在,如果它有所帮助,我已经在GitHub上获得了命令式代码,有问题的代码如下:

[Fact]
public static void CanOverrideCtorArgs()
{
    var fixture = new Fixture();

    var knownText = "This text is not anonymous";
    fixture.Register<int, IMyInterface>( i => new FakeMyInterface( i, knownText ) );

    var sut = fixture.Create<MyClass>();
}
Run Code Online (Sandbox Code Playgroud)

这类似于在此给出的代码.

因此,我的问题是我应该知道/阅读什么才能将这段命令式代码转换为声明性的.

c# autofixture

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

AutoFixture:PropertyData和异构参数

鉴于以下测试:

[Theory]
[PropertyData("GetValidInputForDb")]
public void GivenValidInputShouldOutputCorrectResult(
    string patientId
    , string patientFirstName
)
{
    var fixture = new Fixture();          

    var sut = fixture.Create<HtmlOutputBuilder>();

    sut.DoSomething();
    // More code
}
Run Code Online (Sandbox Code Playgroud)

我想将夹具创建封装在自己的类中,类似于:

[Theory]
[CustomPropertyData("GetValidInputForDb")]
public void GivenValidInputShouldOutputCorrectResult(
    string patientId
    , string patientFirstName
    , HtmlOutputBuilder sut
)
{
    sut.DoSomething();
    // More code
}
Run Code Online (Sandbox Code Playgroud)

问题是我正在使用PropertyData,后者提供两个输入参数.事实上,我正在尝试自动创建我的夹具作为参数导致异常.

这是CustomPropertyData:

public class CustomPropertyDataAttribute : CompositeDataAttribute
{
    public CustomPropertyDataAttribute(string validInput)
        :base(new DataAttribute[]
            {
                new PropertyDataAttribute(validInput),
                new AutoDataAttribute(new Fixture()
                    .Customize(new HtmlOutpuBuilderTestConvention() )), 
            })
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以解决这个问题?

c# xunit.net autofixture

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

在TeamCity中使用MSBuild复制文件

我有以下xml文件:

<?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" DefaultTargets="DeployPrototype" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <dotCover>..\..\..\plugins\dotCover\bin\dotCover.exe</dotCover>
      </PropertyGroup>
      <ItemGroup>
        <SourceFiles Include="..\Prototype\Site\Site\Bin\TestServer\Default.html;..\Prototype\Site\Site\Bin\TestServer\Site.xap"/>
        <DestinationFolder Include="C:\inetpub\wwwroot\ProjectName\Prototype"/>
      </ItemGroup>

      <Target Name="Build">
          <MSBuild Projects="../ProjectName.Web.sln" Properties="Configuration=testserver" />
          <Message Text="Building ProjectName solution" Importance="high" />
      </Target>

      <Target Name="TeamCity" DependsOnTargets="Build">
        <Message Text="Before executing MSpec command" Importance="low" />
        <Exec Command="..\packages\Machine.Specifications.0.4.10.0\tools\mspec-clr4.exe ..\Hosts\ProjectName.Hosts.Web.Specs\bin\ProjectName.Hosts.Web.Specs.dll --teamcity" />
        <Message Text="Ran MSpec" Importance="low" />
        <Exec Command="$(dotCover) c TestServerBuildAndRunTestsOnly_DotCover.xml" />
        <Message Text="##teamcity[importData type='dotNetCoverage' tool='dotcover' path='build\coverage.xml']" Importance="high" />
      </Target>

      <Target Name="DeployPrototype" DependsOnTargets="TeamCity">
        <Message Text="Before executing copy, source files are: @(MySourceFiles) and destination folder is: @(DestinationFolder)" Importance="low" …
Run Code Online (Sandbox Code Playgroud)

msbuild teamcity

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

使用FakeItEasy和FluentValidation伪造来自commonlibnet的Captcha

我正在使用commonlibrary中的Captcha类(http://commonlibrarynet.codeplex.com/).我的代码工作和一切,但现在我正在尝试编写单元测试.

我的验证规则是:

 RuleFor(x => x.CaptchaUserInput)
            .NotEmpty()
            .Must((x, captchaUserInput) => Captcha.IsCorrect(captchaUserInput, x.CaptchaGeneratedText))
            .WithMessage("Invalid captcha code");
Run Code Online (Sandbox Code Playgroud)

在我的设置代码中,我尝试执行以下操作:

A.CallTo(() => Captcha.IsCorrect()).Returns(true);
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误消息:

SetUp : FakeItEasy.Configuration.FakeConfigurationException : 

The current proxy generator can not intercept the specified method for the following reason:
- Static methods can not be intercepted.


at FakeItEasy.Configuration.DefaultInterceptionAsserter.AssertThatMethodCanBeInterceptedOnInstance(Metho    dInfo method, Object callTarget)
at FakeItEasy.Configuration.FakeConfigurationManager.CallTo(Expression`1 callSpecification)
at ProdMaster.Hosts.Web.Tests.Unit.Controllers.AccountControllerTests.SetUp() in     AccountControllerTests.cs: line 44 
Run Code Online (Sandbox Code Playgroud)

所以问题实际上是如何使用FakeItEasy伪造静态方法.

TIA,

大卫

captcha unit-testing common-library fluentvalidation fakeiteasy

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

事件的 Logstash 丢弃过滤器

在我的日志文件中,我有如下条目:

2014-06-25 12:36:18,176 [10] ((null)) INFO  [s=(null)] [u=(null)] Hello from Serilog, running as "David"! [Program] 
2014-06-25 12:36:18,207 [10] ((null)) WARN  [s=(null)] [u=(null)] =======MyOwnLogger====== Hello from log4net, running as David! [MyOwnLogger] 
2014-06-25 12:36:18,209 [10] ((null)) ERROR [s=(null)] [u=(null)] =======MyOwnLogger====== Hello from log4net, running as David! [MyOwnLogger] 
Run Code Online (Sandbox Code Playgroud)

日志级别分别为 INFO、WARN 和 ERROR。

我想做的是只将那些 ERROR 级别的条目输出到 Elasticsearch。这是我的 Logstash 配置文件:

input {
    file {
        path => "Somepath/*.log"
    }
}

# This filter doesn't work
filter {
  if [loglevel] != "error" { 
    drop { } 
  } …
Run Code Online (Sandbox Code Playgroud)

logstash

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