in Education by
I've isolated the behaviour into the following test case. I'd be grateful to anyone who can tell me how to expect/verify a property set for a List property - it appears there's something going on inside It.Is(predicate) that isn't making a whole lot of sense to me right now. Sample code will run as a console app from VS2008 - you'll need to add a reference to Moq 2.6 (I'm on 2.6.1014.1) - please try uncommenting the different ExpectSet statements to see what's happening... using System; using Moq; using System.Collections.Generic; namespace MoqDemo { public interface IView { List Names { get; set; } } public class Controller { private IView view; public Controller(IView view) { this.view = view; } public void PopulateView() { List names = new List() { "Hugh", "Pugh", "Barney McGrew" }; view.Names = names; } public class MyApp { public static void Main() { Mock mockView = new Mock(); // This works - and the expectation is verifiable. mockView.ExpectSet(mv => mv.Names); // None of the following can be verified. // mockView.ExpectSet(mv => mv.Names, It.Is(o => o != null)); // mockView.ExpectSet(mv => mv.Names, It.Is>(names => names.Count == 3)); // mockView.ExpectSet(mv => mv.Names, It.IsAny>()); Controller controller = new Controller(mockView.Object); controller.PopulateView(); try { mockView.VerifyAll(); Console.WriteLine("Verified OK!"); } catch (MockException ex) { Console.WriteLine("Verification failed!"); Console.WriteLine(ex.Message); } Console.ReadKey(false); } } } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I'm not using the very latest version of Moq, so I don't have an overload of ExpectSet that takes two parameters, but I've had some success with this pattern: mockView.ExpectSet(mv => mv.Names).Callback(n => Assert.That(n != null)); The Assert (from NUnit) call in the callback will throw an exception if the value assigned to .Names doesn't match the predicate. It does make it hard to trace when a test fails, though. I agree that the ability to pass an It.Is or It.IsAny as the second parameter would be handy.

Related questions

0 votes
    I have a model with two foreign keys to create many to many relationship - I am not using many to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I have a model with two foreign keys to create many to many relationship - I am not using many to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I spent an evening trying to mock an object that implements IQueryable: public interface IRepo : IQueryable ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    In order to calculate confidence intervals and hypothesis tests, it is assumed that the errors are independent and ... R Programming Select the correct answer from above options...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    In my XSLT stylesheet I extract the value of the current month using a month-from-dateTime like this . ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    What are the best practices if you have a class which accepts some parameters but none of them are allowed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 5, 2022 in Education by JackTerrance
0 votes
    I'm trying to use the Android GraphView library (http://www.android-graphview.org/), but no matter ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    While at least some answers from every question seem to have been up-voted as a "helpful" answer: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    Greetings all, I'm trying to localize a .NET/C# project. I'm using string resource files and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    This smells buggy, but probably, someone can explain it: The following script doesn't work, the output is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    if a team developing stories in first 6 days and test them in following 2 days and fixing bug in remaining days, how the team is behaving?...
asked Nov 30, 2020 in Technology by Editorial Staff
...