小编Aca*_*uza的帖子

枚举应该以0还是1开头?

想象一下,我定义了以下枚举:

public enum Status : byte
{
    Inactive = 1,
    Active = 2,
}
Run Code Online (Sandbox Code Playgroud)

使用枚举的最佳做法是什么?它应该1像上面的例子一样开始,还是以0(没有显式值)开头,如下所示:

public enum Status : byte
{
    Inactive,
    Active
}
Run Code Online (Sandbox Code Playgroud)

.net c# enums

131
推荐指数
9
解决办法
6万
查看次数

实体框架4.1的假DbContext测试

我正在使用本教程伪造我的DbContext并测试:http://refactorthis.wordpress.com/2011/05/31/mock-faking-dbcontext-in-entity-framework-4-1-with-a-generic -repository /

但我必须更改FakeMainModuleContext实现以在我的控制器中使用:

public class FakeQuestiona2011Context : IQuestiona2011Context
{
    private IDbSet<Credencial> _credencial;
    private IDbSet<Perfil> _perfil;
    private IDbSet<Apurador> _apurador;
    private IDbSet<Entrevistado> _entrevistado;
    private IDbSet<Setor> _setor;
    private IDbSet<Secretaria> _secretaria;
    private IDbSet<Pesquisa> _pesquisa;
    private IDbSet<Pergunta> _pergunta;
    private IDbSet<Resposta> _resposta;

    public IDbSet<Credencial> Credencial { get { return _credencial ?? (_credencial = new FakeDbSet<Credencial>()); } set { } }
    public IDbSet<Perfil> Perfil { get { return _perfil ?? (_perfil = new FakeDbSet<Perfil>()); } set { } }
    public IDbSet<Apurador> Apurador { get …
Run Code Online (Sandbox Code Playgroud)

.net tdd asp.net-mvc unit-testing entity-framework

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

什么是SUT,它来自哪里?

我看到很多人都在谈论SUT这个术语,但不明白为什么他们使用这个术语.

SUT是你想要测试的吗?

这个术语来自哪里,它意味着什么?

例如,在这个测试中,我的SUT是什么?

[TestMethod]
public void UsersAction_should_return_IndexAction()
{
    const long id = 1;

    UsersViewModel viewModel = new UsersViewModel()
    {
        SelectedUsers = new long[] { 1, 2, 3, 4 }
    };

    ActionResult result = _controller.Users(id, viewModel);

    result.AssertActionRedirect().ToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)

.net c# unit-testing naming terminology

39
推荐指数
4
解决办法
3万
查看次数

为什么.Net最佳实践将自定义属性设计为密封?

我正在阅读Pro C#2010和 Andrew Troelsen 的.Net 4平台.

在第15章关于属性存在一个注释:

注意:出于安全原因,将所有自定义属性设计为密封被视为.Net最佳实践.

作者没有解释原因,有人可以解释原因吗?

.net c# attributes

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

Visual Studio(.sln)构建运行器和MSBuild之间的差异

我正在尝试将TeamCity设置为使用.Net进行配置并配置我拥有的构建运行程序:

  1. Visual Studio(sln)
  2. 的MSBuild
  3. Visual Studio 2003

有什么不同?为什么三个构建在同一类型的项目上工作?(2003年只有2003年,我相信,为什么?)

考虑到这个问题,我们为.exe文件提供了这个构建运行器:

  1. .NET Process Runner
  2. 命令行

"命令行"构建运行器不适用于任何.net程序集?为什么选择.Net Process Runner?

.net msbuild teamcity continuous-integration visual-studio

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

如何将Set.Lazy与Setter一起使用到POCO实体中列表的延迟初始化?

我想在我的Entites中使用System.Lazy来懒惰初始化我的列表:

public class Questionary
{
    private Lazy<List<Question>> _questions = new Lazy<List<Question>>(() => new List<Question>());

    public IList<Question> Questions { get { return _questions.Value; } set { _questions.Value = value; } }
}
Run Code Online (Sandbox Code Playgroud)

问题出在我的SETTER上,得到这个错误:属性' System.Lazy<T>.Value'没有setter

如果我想做MyInstance.Questions = new List<Question> { ... }

我该怎么办?

更新:

我试图避免这种情况:

private IList<Question> _questions;

//Trying to avoid that ugly if in my getter:
public IList<Question> Questions { get { return _questions == null ? new List<Question>() : _questions; } set { _questions = value …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework lazy-initialization c#-4.0

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

Backbone.js只适用于单页面应用程序吗?

我正在为我的UI搜索一个简单的架构,它将具有一些基本的javascript函数:select all checkbox,图像裁剪,一些弹出窗口和一些其他插件.

我找到了这篇文章:用模块组织你的Backbone.js应用程序

我的申请不是SPA(单页申请).我想知道,即使我的应用程序不是SPA,Backbone.js与jQuery是否会帮助我.

javascript architecture user-interface web-applications backbone.js

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

我可以通过C#中的引用传递原始类型吗?

我知道C#中的Reference传递复杂类型,而Value传递基本类型.我可以通过C#中的引用传递原始类型吗?

更新:

谢谢你的回答,但我的例子是?

void test(object x) {

}

long y = 1;

test(ref y);
Run Code Online (Sandbox Code Playgroud)

抛出此异常:'ref'参数类型与参数类型不匹配

.net c#

14
推荐指数
5
解决办法
9978
查看次数

什么是Visual Studio在初始化测试项目时创建的"Local.testsettings"和"TraceAndTestImpact.testsettings"文件?

当使用visual studio创建一个新的测试项目时,会创建这两个文件,这些文件的目的是什么?如果要使用Visual Studio运行测试,显然不需要这些文件.

mstest visual-studio

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

什么是使用Stubs和Mocks的正确方法?

这是我的例子:

[TestMethod]
public void NewAction_should_return_IndexAction()
{
    NewViewModel viewModel = new NewViewModel()
    {
        Name = "José Inácio Santos Silva",
        Email = "joseinacio@joseinacio.com",
        Username = "joseinacio"
    };

    //IsUserRegistered is used to validate Username, Username is unique.
    _mockAuthenticationService.Setup(x => x.IsUserRegistered(viewModel.Username )).Returns(false);

    //IsUserRegistered is used to validate Email, Email is unique.
    _mockUsuarioRepository.Setup(x => x.GetUserByEmail(viewModel.Email));
    _mockDbContext.Setup(x => x.SaveChanges());
    _mockUsuarioRepository.Setup(x => x.Add(It.IsAny<User>()));

    _userController = new UserController(_mockUsuarioRepository.Object, _mockDbContext.Object, _mockAuthenticationService.Object);

    ActionResult result = _userController.New(viewModel);

    result.AssertActionRedirect().ToAction("Index");

    _mockAuthenticationService.VerifyAll();
    _mockUsuarioRepository.VerifyAll();
    _mockDbContext.VerifyAll();
}
Run Code Online (Sandbox Code Playgroud)

我已经阅读了一些教程,他们说每次测试我们应该使用一个模拟.

但看看我的测试,它使用3次嘲讽 …

.net c# testing unit-testing mocking

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