我有两个对象是父对象和子列表.在我的父母流利的nhibernate映射中,我想加载子列表.
但是,我希望这是有条件的,子表中的列称为"IsDeleted",我只想返回"IsDeleted"为false的子项.
是否可以设置映射来执行此操作?如果不是可以在标准的nhibernate中做到这一点?
谢谢
我是嘲笑/测试的新手,想要知道测试时应该达到什么水平.例如,在我的代码中,我有以下对象:
public class RuleViolation
{
public string ErrorMessage { get; private set; }
public string PropertyName { get; private set; }
public RuleViolation( string errorMessage )
{
ErrorMessage = errorMessage;
}
public RuleViolation( string errorMessage, string propertyName )
{
ErrorMessage = errorMessage;
PropertyName = propertyName;
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个相对简单的对象.所以我的问题是:
是否需要进行单元测试?
如果它做我测试什么,怎么做?
谢谢
我一直在研究mvc的视图模型,我正在寻找最好的方法来实现它们.我读过很多不同的文章,但似乎没有一个明确的"最佳方式".到目前为止,我可能有一个具有以下属性的Customer模型:
其中location是数据库中位置表的外键.
我希望能够编辑此客户,但只能编辑名字,姓氏和位置.我对编辑中的标题并不感到烦恼.因此,在我看来,我需要传递一个客户和一个选定的列表.
从我读过的内容来看,我有以下几种选择(可能还有更多).
所以我的问题基本上哪个是最好的?
1)
添加一个选择列表ViewData["Location"],只是创建一个强类型的客户视图?
2)
创建一个视图模型,我传递客户并选择列表(数据访问在控制器中完成):
public class ViewModelTest
{
public Customer Customer { get; set; }
public SelectList Locations { get; set; }
public ViewModelTest(Customer customer, SelectList locations)
{
Customer = customer;
Locations = locations;
}
}
Run Code Online (Sandbox Code Playgroud)
3)
创建一个视图模型,我在其中传递客户和位置列表,并在视图模型中创建选择列表.
public class ViewModelTest
{
public Customer Customer { get; set; }
public SelectList Locations { get; set; }
public ViewModelTest(Customer customer, List<Location> locations, string selectedLocation)
{
Customer = customer;
Locations = …Run Code Online (Sandbox Code Playgroud) 我在测试控制器时遇到了困难.原来我的测试控制器看起来像这样:
SomethingController CreateSomethingController()
{
var somethingData = FakeSomethingData.CreateFakeData();
var fakeRepository = FakeRepository.Create();
var controller = new SomethingController(fakeRepository);
return controller;
}
Run Code Online (Sandbox Code Playgroud)
这对于大多数测试都很好,直到我得到了Request.IsAjaxRequest()代码的一部分.所以我不得不模拟HttpContext和HttpRequestBase.所以我的代码然后改为看起来像:
public class FakeHttpContext : HttpContextBase
{
bool _isAjaxRequest;
public FakeHttpContext( bool isAjaxRequest = false )
{
_isAjaxRequest = isAjaxRequest;
}
public override HttpRequestBase Request
{
get
{
string ajaxRequestHeader = "";
if ( _isAjaxRequest )
ajaxRequestHeader = "XMLHttpRequest";
var request = new Mock<HttpRequestBase>();
request.SetupGet( x => x.Headers ).Returns( new WebHeaderCollection
{
{"X-Requested-With", ajaxRequestHeader}
} );
request.SetupGet( x …Run Code Online (Sandbox Code Playgroud) 我发现以下问题将Delphi Real48转换为C#double,但我想转向其他方式,C#转向Delphi.
有谁知道如何做到这一点?我试过逆向工程代码,但没有太多运气.
更新:
我正在使用C#代码,它将采用double并将其转换为Real48(大小为6的byte []).
谢谢
我正在尝试在.NET MVC网站中实现自定义主体和自定义标识.我创建了一个自定义主体类,它继承自IPrincipal和继承自IIdentity的自定义标识.
当用户登录时,我将Thread.CurrentPrincipal和HttpContext.Current.User都设置为我的自定义主体.当我通过调试器查看时,使用所有属性设置值.
但是,一旦请求完成,我尝试并请求任何其他页面,Thread.CurrentPrincipal和HttpContext.Current.User的类型为System.Security.Principal.GenericPrincipal,而不是我的自定义主体.
我是否需要做任何"额外"操作才能将我的自定义主体从线程或HttpContext中取出?
谢谢
在观看MIX 11演讲之后我才开始关注knockoutjs,它看起来非常有前途.
我可以理解如何将模型作为json传递回控制器并更新/保存模型,但是如何将模型传递给我的视图并使其可观察?
例如,如果我有以下类:
public class Person {
public string FirstName { get; set; }
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我可以使用JsonResult从我的控制器作为json传递它,所以我发送类似于我的视图:
{
firstName : "Bob",
lastName : "Jones"
};
Run Code Online (Sandbox Code Playgroud)
现在,如何使属性可观察并使其成为我的代码中的viewModel?
我有一个CSV字符串,我想把它分成一个数组.但是,CSV是字符串和数字的混合,其中字符串用引号括起来,可能包含逗号.
例如,我可能有如下CSV:
1,"Hello",2,"World",3,"Hello, World"
Run Code Online (Sandbox Code Playgroud)
我想它,所以字符串分为:
1
"Hello"
2
"World"
3
"Hello, World"
Run Code Online (Sandbox Code Playgroud)
如果我使用String.Split(',');我得到:
1
"Hello"
2
"World"
3
"Hello
World"
Run Code Online (Sandbox Code Playgroud)
有这么简单的方法吗?已编写的库或是否必须按字符解析字符串?
我有一个CSLA对象正在从数据库返回数据,但是当我更改对象的任何属性时,对象仍然说IsDirty ="false".虽然当我创建一个新对象时,它会报告IsDirty ="true".我确信它只是我的代码中缺少的一些简单的东西.以下是我的目标:
[Serializable()]
[ObjectFactory( FactoryNames.SiteFactoryName )]
public class Site : BusinessBase<Site>
{
#region Business Methods
public static PropertyInfo<int> IdProperty = RegisterProperty<int>( p => p.Id );
public int Id
{
get { return GetProperty( IdProperty ); }
set { LoadProperty( IdProperty, value ); }
}
public static PropertyInfo<string> NameProperty = RegisterProperty<string>( p => p.Name );
public string Name
{
get { return GetProperty( NameProperty ); }
set { LoadProperty( NameProperty, value ); }
}
public static PropertyInfo<string> CodeProperty = RegisterProperty<string>( …Run Code Online (Sandbox Code Playgroud) 是否可以将OData与POCO一起使用,还是仅限于LinqToEntities?
我找到的所有示例似乎只使用实体框架.
也被视为WCF服务的替代品或是否打算并行运行?
谢谢
asp.net-mvc ×5
c# ×3
.net ×2
asp.net ×2
mocking ×2
unit-testing ×2
arrays ×1
csla ×1
csv ×1
delphi ×1
double ×1
iprincipal ×1
knockout.js ×1
nhibernate ×1
odata ×1
orm ×1
security ×1
string ×1
testing ×1
viewmodel ×1
wcf ×1
web-services ×1