想象一下,我定义了以下枚举:
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) 我正在使用本教程伪造我的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) 我看到很多人都在谈论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) 我正在阅读Pro C#2010和 Andrew Troelsen 的.Net 4平台.
在第15章关于属性存在一个注释:
注意:出于安全原因,将所有自定义属性设计为密封被视为.Net最佳实践.
作者没有解释原因,有人可以解释原因吗?
我正在尝试将TeamCity设置为使用.Net进行配置并配置我拥有的构建运行程序:
有什么不同?为什么三个构建在同一类型的项目上工作?(2003年只有2003年,我相信,为什么?)
考虑到这个问题,我们为.exe文件提供了这个构建运行器:
"命令行"构建运行器不适用于任何.net程序集?为什么选择.Net Process Runner?
我想在我的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) 我正在为我的UI搜索一个简单的架构,它将具有一些基本的javascript函数:select all checkbox,图像裁剪,一些弹出窗口和一些其他插件.
我找到了这篇文章:用模块组织你的Backbone.js应用程序
我的申请不是SPA(单页申请).我想知道,即使我的应用程序不是SPA,Backbone.js与jQuery是否会帮助我.
javascript architecture user-interface web-applications backbone.js
我知道C#中的Reference传递复杂类型,而Value传递基本类型.我可以通过C#中的引用传递原始类型吗?
更新:
谢谢你的回答,但我的例子是?
void test(object x) {
}
long y = 1;
test(ref y);
Run Code Online (Sandbox Code Playgroud)
抛出此异常:'ref'参数类型与参数类型不匹配
当使用visual studio创建一个新的测试项目时,会创建这两个文件,这些文件的目的是什么?如果要使用Visual Studio运行测试,显然不需要这些文件.
这是我的例子:
[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 ×8
c# ×6
unit-testing ×3
architecture ×1
asp.net-mvc ×1
attributes ×1
backbone.js ×1
c#-4.0 ×1
enums ×1
javascript ×1
mocking ×1
msbuild ×1
mstest ×1
naming ×1
tdd ×1
teamcity ×1
terminology ×1
testing ×1