嗨,当我看到这段代码时,我一直在使用moq.
我必须在我的一个回购中设置一个回报.
mockIRole.Setup(r => r.GetSomething(It.IsAny<Guid>(), It.IsAny<Guid>(),
It.IsAny<Guid>())).Returns(ReturnSomething);
Run Code Online (Sandbox Code Playgroud)
我有三个参数,我只是在网上的一篇文章或博客中看到过这些参数.
It.Is <>或It.IsAny <>对象的用途是什么?如果我可以使用Guid.NewGuid()或其他类型,那么为什么要使用It.Is?
对不起,我不确定我的问题是否正确,或者我是否缺少一些测试知识.但似乎两种方式都没有错.
我目前对如何嘲笑感到困惑.
我正在使用Moq.为了模拟对象,我通常以这种方式编写
var mockIRepo = new Mock<IRepo>();
Run Code Online (Sandbox Code Playgroud)
但是,我需要为我的设置创建模拟对象.
Option1 以这种方式模拟仅包含属性的对象是否更好?
var object = Mock.Of<Object>()
Run Code Online (Sandbox Code Playgroud)
Option2 或者这样
var object = new Mock<Object>()
Run Code Online (Sandbox Code Playgroud)
我已经读过选项2有setupproperties这对我来说有点问题,因为我也可以在选项1中设置属性.
那有什么区别?或者,还有更好的方法?
我正在使用EF 6.1.0并且正在创建WCF服务.
首先,我创建了一个包含我的实体,Mappers和Context的类库,用于初始化EF.我还创建了一个包含上下文实例化的类,并拥有以下代码:
public IQueryable<[Entity]> GetAll()
{
return context.[Entity].AsQueryable();
}
Run Code Online (Sandbox Code Playgroud)
另一方面,我在同一个项目上创建了一个WCF服务,并在.svc文件中调用函数GetAll(),如下所示:
public List<[Entity]> GetList()
{
[iObject] repository = new [Object](new Context());
return repository.GetAll().ToList();
}
Run Code Online (Sandbox Code Playgroud)
该项目正在建设中.我甚至检查了配置,它位于正确的数据库中.但是,应该创建的数据库和表不存在,并且返回中显示错误"Sequence contains no matching element".
如果这个令人困惑,您可以使用Code First Entity Framework向我指出WCF服务的一些链接.
我正在使用nunit创建一个单元测试,所有这些代码在运行时都能正常工作.
我有HttpResponseMessage
下面这个受保护的代码,当它返回时我的控制器会调用它.
但是,错误:
"值不能为空.参数名称:请求"正在显示.
当我检查请求时,实际上是null
.
问题:如何编码我的单元测试以返回HttpResponseMessage
?
错误显示在此行中:
protected HttpResponseMessage Created<T>(T result) => Request.CreateResponse(HttpStatusCode.Created, Envelope.Ok(result));
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
[Route("employees")]
[HttpPost]
public HttpResponseMessage CreateEmployee([FromBody] CreateEmployeeModel model)
{
//**Some code here**//
return Created(new EmployeeModel
{
EmployeeId = employee.Id,
CustomerId = employee.CustomerId,
UserId = employee.UserId,
FirstName = employee.User.FirstName,
LastName = employee.User.LastName,
Email = employee.User.Email,
MobileNumber = employee.MobileNumber,
IsPrimaryContact = employee.IsPrimaryContact,
OnlineRoleId = RoleManager.GetOnlineRole(employee.CustomerId, employee.UserId).Id,
HasMultipleCompanies = EmployeeManager.HasMultipleCompanies(employee.UserId)
});
}
Run Code Online (Sandbox Code Playgroud) 运行者类型:Visual Studio(sln)
Visual Studio:Visual Studio 2008
目标:重建
配置:开发
平台:默认
--------------------------- -------------------------------------------------- -----对于
SSIS,有一个这样的警告:
MSBuild不支持项目文件"SB.SSIS.Package\SB.SSIS.Package.dtproj",无法构建.
对于SSRS,这里是警告:
MSBuild不支持项目文件"SB.Report\SB.Report.rptproj",无法构建.
-------------------------------------------------- --------------------------------
当我运行项目时.这是成功的但是没有文件应该在bin中.
在SSRS中,我不认为我仍然需要这个来构建因为.ds和.rdl文件仍然是相同的并且只在bin中传递.我对么?
但是对于SSIS,我认为应该建立起来.我忘记了一些步骤吗?
我一直在寻找一个确切的答案,但似乎大多数答案都是客户端调用并且超出了范围。
问题:我已经有一个访问令牌访问令牌。仅在给定访问令牌的情况下,如何使用 c# 代码获得声明?
我认为:以下是相同的问题,但没有我认为合适的答案。
我在下面有这个控制器.在页面加载时,执行下面看到的$ http服务.
现在,我如何从其他控制器调用并执行控制器的$ http.post(...)部分AGAIN.
controller: function ($scope, $element, $http) {
function par() {
var xxx= null;
xxx = $scope.$parent.$root.ParentItems['xxx'].xxx;
var det = { xxx: xxx};
return det;
}
$http.post('/api/values/entries/GoHere', par()).success(function (salData) {
var buildSHGraph = function (shData) {
//code code codes...
}
$scope.Array1 = [];
angular.forEach(salData, function (evt) {
//Code Code Codes
});
buildSHGraph($scope.Array1);
});
}
Run Code Online (Sandbox Code Playgroud) javascript jquery angularjs angularjs-directive angularjs-scope
我有这两个代码,我必须知道哪个更好用.我在想这是一样的.如果我没有弄错,第一个只有一次调用数据库,但是,我不知道检查repo!= null是否正确.
(1)
var repo = Repository
.Query()
.Where(ur => ur.CustomerId == customerId)
.SingleOrDefault();
if (repo != null)
{
// Update repo
repo.Name = "name here";
}
else
{
// code
}
Run Code Online (Sandbox Code Playgroud)
(2)
var repo = Repository
.Query()
.Any(ur => ur.CustomerId == customerId);
if (repo)
{
var result = Repository
.Query()
.Where(ur => ur.CustomerId == customerId)
.Single();
result.Name = "name here";
}
else
{
// code
}
Run Code Online (Sandbox Code Playgroud) c# ×6
unit-testing ×3
mocking ×2
moq ×2
testing ×2
access-token ×1
angularjs ×1
claims ×1
httprequest ×1
javascript ×1
jquery ×1
linq ×1
linq-to-sql ×1
nunit ×1
ssis ×1
teamcity ×1
token ×1
wcf ×1