当我IReadOnlyList在我的代码中实现时,我的单元测试抛出了一个AutoMapperMappingException.
从挖掘文章和文档,我的猜测是AutoMapper需要特殊的readonly类型编码.这会是什么样的?
注意:我尝试Mapper.AssertConfigurationIsValid();了另一篇文章建议,但没有改进.
测试名称:CreateOrder_ValidContract_CreatesNewOrder测试FullName:ACME.Maintenance.Domain.Test.OrderServiceTest.CreateOrder_ValidContract_CreatesNewOrder测试源:C:\ Users\me\documents\visual studio 2015\Projects\ACME.Maintenance\ACME.Maintenance.Domain.Test\OrderServiceTest. cs:第65行测试结果:测试持续时间失败:0:00:00.0233941
结果StackTrace:位于C:\ Users\me\documents\visual studio 2015\Projects\ACME.Maintenance\ACME中ACME.Maintenance.Domain.ContractService.GetById(String contractId)的lambda_method(Closure,ContractDto,Contract,ResolutionContext). Maintenance.Domain\ContractService.cs:位于C:\ Users\me\documents\visual studio 2015\Projects\ACME.Maintenance\ACME.Maintenance.Domain中的ACME.Maintenance.Domain.Test.OrderServiceTest.CreateOrder_ValidContract_CreatesNewOrder()的第34行. Test\OrderServiceTest.cs:第69行结果消息:测试方法ACME.Maintenance.Domain.Test.OrderServiceTest.CreateOrder_ValidContract_CreatesNewOrder引发异常:AutoMapper.AutoMapperMappingException:缺少类型映射配置或不支持的映射.
映射类型:ContractDto - > Contract
ACME.Maintenance.Domain.DTO.ContractDto - > ACME.Maintenance.Domain.Contract
Mapper.Initialize(cfg => cfg.CreateMap<ContractDto, Contract>());
Mapper.Initialize(cfg => cfg.CreateMap<PartDto, Part>());
[TestMethod]
public void CreateOrder_ValidContract_CreatesNewOrder()
{
//Arrange
var orderService = new OrderService();
var contractService = new ContractService(_contractRepository);
var contract = contractService.GetById(ValidContractId);
// Act
var newOrder = orderService.CreateOrder(contract);
// Assert
Assert.IsInstanceOfType(newOrder, typeof(Order));
Guid guidOut;
Assert.IsTrue(Guid.TryParse(newOrder.OrderId, out guidOut));
Assert.AreEqual(newOrder.Status, ContractStatus.New);
Assert.IsInstanceOfType(newOrder.Items, …Run Code Online (Sandbox Code Playgroud) 我正在使用 firefox webdriver 运行 firefox 41.0.2 Nunit 3.4.1 selenium 2.47.0 specflow 2.1.0 我的测试并行运行。
几天过去了,我的测试在通过 jenkins 运行时未能完成,运行卡在一个进程上并且无法继续运行的其余部分。在运行 20 多个场景时,我间歇性地能够在本地重现错误。我收到以下异常,以前有人见过这个问题吗?
OpenQA.Selenium.WebDriverException :抛出一个带有空响应的异常,将 HTTP 请求发送到远程 WebDriver 服务器的 URL http://localhost:7056/hub/session/d0a83b9c-bd79-4218-8eac-dc8b273f8f40/element/% 7B84966a91-06c4-42dd-98c0-278ed35e3667%7D/属性/值。
异常状态为 ConnectFailure,消息为:无法连接远程服务器 ----> System.Net.WebException : 无法连接远程服务器 ----> System.Net.Sockets.SocketException : 无法建立连接,因为目标机器主动拒绝它 127.0.0.1:7056
+++++++++++++++++++ 堆栈跟踪:在 OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 在 OpenQA.Selenium.Firefox.FirefoxDriverCommandExecutor.Execute(Command commandToExecute)在 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary
2 parameters) at OpenQA.Selenium.Remote.RemoteWebElement.GetAttribute(String attributeName) at TeamHours.Automation.StandAlone.WebComponents.Pages.WeeklySalesForecastPage.<Save>b__0(IWebElement s) in c:\Program Files (x86)\Jenkins\jobs\Automation Build Develop\workspace\TeamHours.Automation.StandAlone.WebComponents\Pages\WeeklySalesForecastPage.cs:line 38 at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() 在 System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 谓词)在 TeamHours.Automation.StandAlone.WebComponents.Pages.WeeklySalesForecastPage.Save() in c:\Program Files (x86)\Jenkins\jobs\Automation Build …
我是hibernate的新手.我需要了解以下问题:
(1)什么是hibernate映射中的subselect?
(2)如何在hbm文件中映射subselect?
(3)如果我使用subselect检索值,那么如何在java Action类中获取检索到的值.
我有一个包含3列的表,ID,Name和ParentID.ID列包含运行编号,该编号也用作主键.ID也将是节点的Name属性.Name列包含将成为treenode的Text属性的字符串,而ParentID是包含节点的父ID的列.
这是我的表格的样子:
ID Name ParentID
======================
1 A 0
2 A1 1
3 B 0
4 C 0
5 A2 1
6 B1 3
Run Code Online (Sandbox Code Playgroud)
此表显示节点A是节点A1和A2的父节点.ParentID等于"0"表示节点的父节点是根节点(硬编码).例如,节点A,B和C是根节点的子节点.
在填充树视图之前,我按ParentID对行进行排序.我使用这两种方法填充树视图(这里的TreeNode节点是填充到树中的子节点):
private void SearchParent(TreeView tree, String parentID, TreeNode node)
{
// Post: call TraverseParent method to search parent
TreeNodeCollection collection = tree.Nodes;
// Search parent recursively
foreach (TreeNode n in collection)
{
TraverseParent(n, parentID, node);
}
}
private void TraverseParent(TreeNode potentialParent, String parentID, TreeNode node)
{
// Post: search for parent. …Run Code Online (Sandbox Code Playgroud) 我正在尝试为一个看起来像这样的方法编写一个单元测试:
public int Save(IEnumerable<int> addedIds, IEnumerable<int> removedIds)
{
var existingIds = repository.Get();
IEnumerable<int> ids = existingIds.Except(removedIds).Union(addedIds));
return repository.Create(ids);
}
Run Code Online (Sandbox Code Playgroud)
Moq的测试看起来像这样:
repository.Setup(r => r.Get()).Returns(CreateList());
service.Save(addedIds, removedIds);
repository.Verify(r => r.Create(It.Is<IEnumerable<int>>(l => VerifyList(l))));
Run Code Online (Sandbox Code Playgroud)
由于此错误,此操作失败,并且VerifyList()永远不会被调用:
模拟上的预期调用至少一次,但从未执行过:
r => r.Create(It.Is<IEnumerable'1>(list => VerifyList(list)))执行调用:
IRepo.Create(System.Linq.Enumerable+<UnionIterator>d__88'1[System.Int32])
由于调用的类型不是,IEnumerable<int>但事实上System.Linq.Enumerable+<UnionIterator>d__88'1[System.Int32]),测试失败.(逐步完成测试,一切正常,结果如预期)
如果我调用ids.ToList()测试中的方法,结果如下:
模拟上的预期调用至少一次,但从未执行过:
r => r.Create(It.Is<List'1>(l => VerifyList(l)))执行调用:
IRepo.Create(System.Collections.Generic.List'1[System.Int32])
这有什么办法吗?或者我做错了什么?
编辑:事实证明我在我的VerifyList方法中有一个错误,所以它返回false,但是Moq没有给我这些信息.类型差异是红鲱鱼..
对于我的log4net解决方案,我有一个使用CallerInfo属性的API包装器,例如
public void Write(string message,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0)
Run Code Online (Sandbox Code Playgroud)
但是,我也使用Unity Interception,以便我可以执行前/后响应的跟踪日志记录,例如在Invoke方法中使用如下所示的ICallHandler.
public class TraceCallHandler : ICallHandler
{
...
public IMethodReturn Invoke(IMethodInvocation input,
GetNextHandlerDelegate getNext)
{
//---- Trace method inputs
this.LogInfoBeforeInvoke(input);
//---- invoking the target method
InvokeHandlerDelegate next = getNext();
IMethodReturn methodReturn = next(input, getNext);
//---- invoking the target method
this.LogInfoAfterInvoke(methodReturn.ReturnValue);
}
}
Run Code Online (Sandbox Code Playgroud)
注意:上面的代码绝不是完整/正确的...但只是想告诉你我为Unity Interception做了些什么.
我的问题/挑战是这样的:当我最终调用log.Write(...)时,我想要目标的调用者信息,而不是我的TraceCallHandler信息.
例如,对于方法名称,我可以这样做:
string methodName = input.MethodBase.Name;
Run Code Online (Sandbox Code Playgroud)
如何获取来电者的文件路径和来电者的线路号码?甚至可以通过反思来做吗?
谢谢!
我正在构建一个从xml提要中获取数据的网站.我正在构建它作为MVC AP.NET应用程序.例如,我将需要应用程序每隔2分钟从位于提供程序服务器上的xml文件中获取数据.然后将存储这些数据.我的问题是,从网站上传到服务器的那一刻起,我希望这些程序不会中断.我想在main方法(?)中使用一个计时器来每2分钟获取一次数据.但我在这里搜索了其他主题,我发现使用AppFabric将是解决方案.问题是我是一个绝对的初学者,我发现很难使用它...是否有另一种更简单的方法来实现从xml文件连续更新数据?
我试图在活动中的片段内隐藏键盘时遇到这些错误:
错误:无法解析getSystemService
无法解析Context
无法解析getCurrentFocus()
InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
Run Code Online (Sandbox Code Playgroud) 因此,我是一个老派的Visual Studio用户,刚刚迁移到Visual Studio Code,我认为我在这里缺少一些东西。但是,我将在这里解释我的经历:
使用Visual Studio,我总是可以右键单击一个解决方案,然后重新构建并运行它,这确实很棒。但是,在Visual Studio Code中,没有重建(至少我知道)。因此,现在我必须先进行dotnet clean,然后进行dotnet clean,并且由于它是一个多步骤的过程,所以有时我会忘记一个步骤,然后我的代码开始表现得很怪异。例如,下面的代码
Person.Name = someNameVariable
Run Code Online (Sandbox Code Playgroud)
如果这只是我的代码中添加的新行,则V代码将执行该行代码,但是当我在Person.Name上放置监视时,它始终为Null。现在,这可能是因为它仍在执行旧代码。但是,该行为不是很明显,使我感觉我的代码可能存在一些问题。所以我有两个问题:
c# ×8
winforms ×2
android ×1
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
automapper ×1
hibernate ×1
interception ×1
keyboard ×1
log4net ×1
moq ×1
reflection ×1
selenium ×1
treeview ×1
unit-testing ×1