我是Moq的新手,所以希望我在这里错过了一些东西.出于某种原因,我得到一个TargetParameterCountException.
你能看出我做错了什么吗?任何问题?请问.:)
这是我的代码:
[Test]
public void HasStudentTest_SaveToRepository_Then_HasStudentReturnsTrue()
{
var fakeStudents = new List<Student>();
fakeStudents.Add(new Student("Jim"));
mockRepository.Setup(r => r.FindAll<Student>(It.IsAny<Predicate<Student>>()))
.Returns(fakeStudents.AsQueryable<Student>)
.Verifiable();
// in persistence.HasStudent(), repo.FindAll(predicate) is throwing
// 'TargetParameterCountException' ; not sure why
persistence.HasStudent("Jim");
mockRepository.VerifyAll();
}
Run Code Online (Sandbox Code Playgroud)
这是Persistence的HasStudent方法:
public bool HasStudent(string name)
{
// throwing the TargetParameterCountException
var query = Repository.FindAll<Student>(s => s.Name == name);
if (query.Count() > 1)
throw new InvalidOperationException("There should not be multiple Students with the same name.");
return query.Count() == 1;
}
Run Code Online (Sandbox Code Playgroud) 所以我想在Ruby中创建一个相对于其所在目录的文件路径。
我有一个项目,无论项目解压缩到哪个目录,我都希望它能够找到文件。(例如,说代码在不同的机器上运行)我一生都无法解决。
似乎要求我可以做到这一点:
require File.dirname(__FILE__) + '/comparison'
Run Code Online (Sandbox Code Playgroud)
对于与src文件夹不同目录的文件,该怎么办?
而不是列出
file = 'C:/whole path/long/very_long/file.txt'
Run Code Online (Sandbox Code Playgroud)
我想说:
file = 'file.txt'
Run Code Online (Sandbox Code Playgroud)
要么
file = File.helpful_method + 'file.txt'
Run Code Online (Sandbox Code Playgroud) 我希望能够在Ruby中将对象扩展为Enumerable,以便成为周一的无限列表(例如).
所以它会产生:3月29日,4月5日,4月12日......等等
我怎样才能在Ruby中实现它?
我是Haskell的初学者,我很难搞清楚一些代码.我需要做什么才能在我的代码的IO部分获得正确的类型?
提前致谢.
loadPeople :: FilePath -> IO [Person]
loadPeople file = do
lines <- getLines file
map parsePerson lines
getLines :: FilePath -> IO [String]
getLines = liftM lines . readFile
parsePerson :: String -> Person
parsePerson line = ...........
Run Code Online (Sandbox Code Playgroud)
map 在Leksah中用红色加下划线,我收到的编译错误是:
src\Main.hs:13:3:
Couldn't match expected type `IO [Person]'
against inferred type `[Person]'
In the expression: map parsePerson lines
In the expression:
do { lines <- getLines file;
map parsePerson lines }
In the definition of `loadPeople':
loadPeople file
= …Run Code Online (Sandbox Code Playgroud) 我已经尝试了很长时间在我的计算机上运行SQL Server Express来练习我的C#/ SQL,但我仍然没有让它工作.
是否有其他程序可以用来设置SQL数据库来练习?如果是这样,哪些是最好的Vista?
编辑:要清楚我不是SQL编程的新手,我暂时没有做任何事情,并希望保持新鲜感.所以我想要一些具有SQL形式的大部分功能的东西,我会专业地使用它.
我是Java的新手,我正在尝试用日期来做事.首先我开始使用Date类,我发现它基本上已被弃用,所以我切换到了Calendar.
现在我得到了奇怪的价值观.例如,12月的月值是0,而不是12.而在那些给我0月12日的日历上,它也提前了一年.
有点奇怪!
我错过了什么?
谢谢你的帮助.
-GG
编辑示例:
所以我正在从这样的文件中读出一些线条:Johnny Graham HF 12-2-1973 Black
我解析它,然后为我设置的日历:
int year = Integer.parseInt(stringVersionOfYear); // this value is 1973
Run Code Online (Sandbox Code Playgroud)
后来当我用这样一条线去回去年份时:
calendar.get(Calendar.YEAR)
Run Code Online (Sandbox Code Playgroud)
价值是1974年...而月份是0
cal.get(Calendar.MONTH)
编辑2:
我正在创建这样的日历:
Calendar outputCalendar = Calendar.getInstance();
outputCalendar.set(year, month, day);
Run Code Online (Sandbox Code Playgroud) 我正在制作一个二十一点的卡片,我想要在卡片中处理它如何在赌场,
即所有玩家获得一张牌,经销商一张面朝下,玩家获得另一张牌,经销商一张面朝上
但是我看起来是暴力干的:(如何重做?
void BlackJack::newHand()
{
resetHands();
for (unsigned int i = 0; i < players.size(); i++)
players[i]->addCard(deck->nextCard());
Card* c = deck->nextCard();
c->setVisible(false); // dealer gets a face down card
dealer->addCard(c);
for (unsigned int i = 0; i < players.size(); i++)
players[i]->addCard(deck->nextCard());
dealer->addCard(deck->nextCard());
}
Run Code Online (Sandbox Code Playgroud) 我可以使用的最简单的密码保护形式是什么,不需要超级安全,只要防止痞子?理想情况下,它可以添加到由HTML和javascript组成的网站上.
它还需要在所有浏览器中工作(不能正确地允许用户只需切换浏览器,以便他们可以访问受密码保护的站点的内容!)
Javascript的提示函数似乎被IE过滤掉了,所以这是不可能的.
我有这段代码,它有效:
val directions = rs.map(_.direction) // Direction extends Enumeration
directions == directions.sorted.reverse
Run Code Online (Sandbox Code Playgroud)
我想改为做这样的事情:
ratings.map(_.direction).isInBackwardsOrder
class RichSeq[T](seq: Seq[T]) {
def isInBackwardsOrder = seq == seq.sorted.reverse
}
object RichSeq {
implicit def seq2richSeq[T](seq: Seq[T]) = new RichSeq[T](seq)
}
Run Code Online (Sandbox Code Playgroud)
我不断收到以下编译错误:
could not find implicit value for parameter ord: Ordering[T]
def isInBackwardsOrder = seq == seq.sorted.reverse
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它可以找到参数ord的隐含值,当它是原始形式时,但是一旦我将它拉入实用程序类就找不到它.
谢谢你的帮助,Alex
c# ×2
java ×2
ruby ×2
.net ×1
blackjack ×1
c++ ×1
dry ×1
enumerable ×1
file ×1
haskell ×1
html ×1
implicit ×1
io ×1
javascript ×1
logging ×1
mocking ×1
monads ×1
moq ×1
refactoring ×1
scala ×1
sql ×1
tomcat ×1
typechecking ×1
unit-testing ×1