我有一个模拟,我已经设置这样.我需要返回传入的相同值.CreatePersonName
mock.Setup(m => m.CreatePersonName(It.IsAny<PersonName>()))
.Returns(// what do i put here?);
Run Code Online (Sandbox Code Playgroud) 我在我的一个数据库表中有一个这样的列
DateCreated, datetime, default(GetDate()), not null
Run Code Online (Sandbox Code Playgroud)
我试图使用实体框架在这个表上插入这样的...
PlaygroundEntities context = new PlaygroundEntities();
Person p = new Person
{
Status = PersonStatus.Alive,
BirthDate = new DateTime(1982,3,18),
Name = "Joe Smith"
};
context.AddToPeople(p);
context.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我收到以下错误
The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated.
Run Code Online (Sandbox Code Playgroud)
所以我尝试将StoreGeneratedPattern设置为计算...同样的事情,然后身份......同样的事情.有任何想法吗?
这可能看起来像一个微不足道的问题但是当我为resharper安装了stylecop插件时,我的评论被格式化为这样
/// <summary>
/// Gets the gift item.
/// </summary>
/// <param name="uid">
/// The uid.
/// </param>
/// <param name="upc">
/// The upc.
/// </param>
/// <returns>
/// </returns>
Gift GetGift(long uid, string upc);
Run Code Online (Sandbox Code Playgroud)
而不是
/// <summary>Gets the gift item.</summary>
/// <param name="uid">The uid.</param>
/// <param name="upc">The upc.</param>
/// <returns></returns>
Gift GetGift(long uid, string upc);
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到任何方法来关闭这种类型的格式.
我需要能够检测图像是否被破坏,并在图像链接断开时替换为默认图像.我知道我可以使用图像代理执行此操作,但希望能够使用javascript动态执行此操作.
我正试图像这样向我的MVC控制器注入一个依赖项
private static void RegisterContainer(IUnityContainer container)
{
container
.RegisterType<IUserService, UserService>()
.RegisterType<IFacebookService, FacebookService>();
}
Run Code Online (Sandbox Code Playgroud)
UserService类有一个像这样的构造函数...
public UserService(): this(new UserRepository(), new FacebookService())
{
//this a parameterless constructor... why doesnt it get picked up by unity?
}
public UserService(IUserRepository repository, IFacebookService facebook_service)
{
Repository=repository;
this.FacebookService=facebook_service;
}
Run Code Online (Sandbox Code Playgroud)
我得到的例外是以下......
当前类型Repositories.IUserRepository是一个接口,无法构造.你错过了类型映射吗?
看起来它正在尝试将一个构造函数注入到服务中,但是默认就足够了吗?为什么它不映射到无参数构造函数?
我找不到任何关于如何实际实现jquery中的自定义事件的好资源.就像他们如何模拟事件冒泡等.
我在整个代码中看到一个模式,其中lambda表达式显示为未覆盖代码覆盖率,调试器会逐步执行代码并且没有条件块.
public CollectionModel()
{
List<Language> languages = LanguageService.GetLanguages();
this.LanguageListItems =
languages.Select(
s =>
new SelectListItem { Text = s.Name, Value = s.LanguageCode, Selected = false }). // <-- this shows as not covered
AsEnumerable();
}
Run Code Online (Sandbox Code Playgroud)
这有点奇怪.有任何想法吗?
我有这样的表结构......

当我将其导入实体框架时,它看起来像这样......

我需要做的是从LINQ构建一个查询,该查询将返回每个唯一商店的列表,其中填充了喜欢该商店的人员列表.(很简单,对吧?)
捕捉:我需要将列表过滤到人员列表中作为列表传递给linq查询的朋友(来自facebook,因此关系不在db中)...
还有一件事:如果商店是请求数据的人的最爱,我需要返回(uid如下所示)
好的,另外一件事:我需要将最喜欢一个项目的朋友排序的列表返回到最低(下面的ui在这方面是错误的)
这是我需要的linq查询的方法签名
public List<Store> GetTopStoresFilteredByFriends
(int uid, List<int> friends, int size = 10){
}
Run Code Online (Sandbox Code Playgroud)
要返回看起来像这样的用户界面......

我有一堆Linq to Entity方法具有相同的select语句,所以我认为我会聪明并将其分离到它自己的方法来减少冗余......但是当我试图运行代码时,我得到了以下内容错误...
此方法无法转换为商店表达式
这是我创建的方法......
public User GetUser(DbUser user, long uid)
{
return new User
{
Uid = user.uid,
FirstName = user.first_name,
LastName = user.last_name
};
}
Run Code Online (Sandbox Code Playgroud)
我打电话给这样的方法......
public User GetUser(long uid)
{
using (var entities = new myEntities()) {
return
entities.DbUsers.Where( x => x.uid == uid && x.account_status == ( short )AccountStatus.Active ).
Select( x => GetUser( x, uid ) ).FirstOrDefault( );
}
}
Run Code Online (Sandbox Code Playgroud)
更新:这是内联工作的代码
public User GetUser(long uid, long uid_user)
{
using (var entities = new myEntities())
{ …Run Code Online (Sandbox Code Playgroud) 这可能是一个非常简单的问题,但是我可以在带有IIS的Windows Server 2008环境中使用node.js吗?是否有"Microsoft"库或其他更好的解决方案?
c# ×5
javascript ×2
jquery ×2
.net ×1
asp.net-mvc ×1
iis ×1
lambda ×1
linq ×1
mocking ×1
moq ×1
node.js ×1
resharper ×1
stylecop ×1
unit-testing ×1
windows ×1