假设我们有一个
var dictionary= new Dictionary<int, IList<int>>();
Run Code Online (Sandbox Code Playgroud)
我想要的是输出它的排序版本,首先按键排序,然后按列表中的值排序.
例如
1 2, 1, 6
5 2, 1
2 1, 3
Run Code Online (Sandbox Code Playgroud)
变
1 1, 2, 6
2 1, 3
5 1, 2
Run Code Online (Sandbox Code Playgroud)
我尝试在里面做foreach,但显然改变你正在迭代的东西是个坏主意.
我正在使用Castle Windsor 3.0,它对我来说非常有效,直到我尝试注册控制器(我使用WCF工具和IoC作为存储库/服务层).这是我的控制器安装程序类:
public class ControllersInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
RegisterAllBasedOnWithCustomComponentRegistration(container, typeof(IController),
typeof(HomeController).Assembly,
cr => cr.LifeStyle.Transient);
}
private void RegisterAllBasedOnWithCustomComponentRegistration(IWindsorContainer container, Type baseType,
Assembly assemblyWithImplementations, Func<ComponentRegistration, ComponentRegistration<object>> customComponentRegistrationCb)
{
container.Register(
AllTypes.FromAssembly(assemblyWithImplementations)
.BasedOn(baseType)
.If(t => t.Name.EndsWith("Controller"))
.Configure(c => customComponentRegistrationCb(c)));
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器工厂:
public class WindsorControllerFactory : DefaultControllerFactory
{
private readonly IKernel _kernel;
public WindsorControllerFactory(IKernel kernel)
{
_kernel = kernel;
}
public override void ReleaseController(IController controller)
{
_kernel.ReleaseComponent(controller);
}
public override IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName) …Run Code Online (Sandbox Code Playgroud) 例如,我想测试以下事实:如果我给他n个来自不同线程的数据块,则我的多线程方法将调用存储库方法n次。当然,模拟不是线程安全的,甚至不应该是这样。
[Test]
public void CanSaveCustomersInParallel()
{
var customers = new List<List<Customer>>
{
new List<Customer>
{
new Customer {FirstName = "FirstName1"},
new Customer {FirstName = "FirstName2"}
},
new List<Customer>
{
new Customer {FirstName = "FirstName3"},
new Customer {FirstName = "FirstName4"}
}
};
_serviceCustomers.ParallelSaveBatch(customers);
_repoCustomers
.Verify(x => x.SaveBatch(It.IsAny<List<Customer>>()), Times.Exactly(2));
}
Run Code Online (Sandbox Code Playgroud)
当然,该测试有时会失败,有时不会失败。但这本质上是错误的。您能建议我如何重写吗?
我决定在Greg Young实施的例子中熟悉具体的CQRS 实施
我不明白的是这里服务的含义是什么,因为它似乎完全不同于我们常用的三层模式.
客户端更改收到的DTO并创建一个命令,该命令由其处理程序处理,该处理程序调用域对象的方法.
然后创建事件并将其存储在事件存储库中并发布以同步去除denormolized部分.
我找不到这个链中的服务.
我的同事告诉我,举例来说,如果我们不希望大数据存储为一个域的一部分,当我们存储在报道,但是当我们需要它在我们的领域,我们发布其返回从服务的东西的事件.
但我无法在脑海中清晰地形成这幅画面.
任何人都可以解释这里应该做什么服务?
假设我们有一个我们使用的外部服务器(例如电话站等)。我们还有下一个代码:
try
{
externalService.CreateCall(callParams);
}
catch (Exception ex)
{
_log.Error("Unexpected exception when trying execute an external code.", ex);
_callService.UpdateCallState(call, CallState.Disconnected, CallOutcome.Failed);
throw;
}
Run Code Online (Sandbox Code Playgroud)
理论上UpdateCallState可以抛出,但我们会使用该代码隐藏这个异常,并且只处理CreateCall以正确方式生成的异常。
问题是,对于这些情况,正确的模式是什么,以便我们正确对待所有异常?
如何对在其体内使用会话对象的方法进行单元测试?
我们说我有以下行动:
[HttpPost]
public JsonResult GetSearchResultGrid(JqGridParams gridParams, Guid campaignId, string queryItemsString)
{
var queryItems = new JavaScriptSerializer().Deserialize<IList<FilledQueryItem>>(queryItemsString);
IPageData pageData = gridParams.ToPageData();
var extraFieldLinker = SessionHandler.CurrentExtraFieldsLinker;
var searchParams = new SearchParamsModel(extraFieldLinker, queryItems);
IList<CustomerSearchResultRow> searchResults = null;
searchResults = _customerService.SearchCustomersByUrlAndCampaign(campaignId,
searchParams.SearchString,
searchParams.AddressFilterPredicate,
pageData);
return GetGridData<CustomerSearchResultGridDefinition, CustomerSearchResultRow>(searchResults, pageData);
}
Run Code Online (Sandbox Code Playgroud)
由于会话的原因,我进行了以下单元测试:
[Test]
public void CanGetSearchResultGrid()
{
//Initialize
var mockJqGridParams = new Mock<JqGridParams>();
var mockPageData = new Mock<IPageData>();
IPagedList<CustomerSearchResultRow> mockPagedResult = new PagedList<CustomerSearchResultRow>(mockPageData.Object);
var guid= Guid.NewGuid();
const string searchString =
"[{\"Caption\":\"FirstName\",\"ConditionType\":\"contains\",\"Value\":\"d\",\"NextItem\":\"Last\"}]";
Func<Address,bool> addressFilterPredicate = (x …Run Code Online (Sandbox Code Playgroud) 请考虑以下结构:Customer-> Orders-> OrderLines-> Quantity和Customer是聚合根.
假设我们想要更改一个OrderLine的数量,我们将如何做?客户会有这样的方法:
public ChangeQuantity(Order order, OrderLine orderLine, int quantity)
{
order.OrderLines.First(...).Quantity = quantity;
}
Run Code Online (Sandbox Code Playgroud)
或者实施是:
public ChangeQuantity(Order order, OrderLine orderLine, int quantity)
{
order.ChangeQuantity(orderLine, quantity);
}
Run Code Online (Sandbox Code Playgroud)