problem about moq-Collection of common programming errors


  • John MacIntyre
    c# unit-testing testing mocking moq
    So I copied the sample code from the Moq home page pretty much verbatim, and am getting a castle proxy exception.Here’s my code (as a console app for an easier sample)using System; using System.Collections.Generic; using System.Linq; using System.Text; using Moq;namespace MoqTestConsole {public interface ILoveThisFramework{bool DownloadExists(string s);}class Program{static void Main(string[] args){Mock<ILoveThisFramework> mock = new Mock<ILoveThisFramework>();// WOW! No record/repla

  • Rafael Steil
    c# generics mono moq castle-dynamicproxy
    I found a really strange problem while creating unit tests that only occurs with the Mono runtime (Xamarin on Mac included), but runs fine within Visual Studio. I isolated it as far as I could, and I reached a point that I can’t tell if it is a bug with Mono, Moq or Castle DinamicProxy, although it only crashes when using the Mono runtime. This is the code:using System; using System.Collections.Generic; using Moq;namespace ConsoleApplication1 {public interface ISomething<T>{List<T> D

  • chiccodoro
    asp.net unit-testing error-handling moq
    Short Version:If I create a System.Web.HttpException as follows:var exception = new HttpException(403, “Forbidden”);I would expect the following methods to return these values, but they don’t:var code = exception.GetHttpCode(); // is 0 var msg = exception.GetHtmlErrorMessage(); // is: nullEdit: In fact GetHttpCode() returns the correct number when being called the first time, but returns 0 when being called a second time:var code = exception.GetHttpCode(); // is 403 code = exception.GetHttpCode(

  • BryanGrimes
    c# unit-testing moq
    I have, what I think, is a pretty straight forward setup in which a search type is created and passed through a service layer and into a repository where a list of a domain type is returned. The search type does nothing but construct an expression tree in the repository method and basically the results from the database come back. Pretty simpleThe repository interface:public interface IDoNotSolicitRepo {IList<DNSContract> SelectWithCriteria(DNS_Search searchriteria); }The service imple

  • cedd
    c# reflection moq
    Is it possible to write code like the following. I’m trying to using Moq with objects that I’m reflecting on as part of a testing framework. The code below raises a “Unhandled expression type: ‘Goto'” exception from Moq, which I guess is expecting something different. It kind of looks like it should work though!private void button1_Click(object sender, EventArgs e){Ifoo = foo Foo();// Create input parameter for lambdaParameterExpression value = Expression.Parameter(typeof(IFoo), “value”);// cre

  • abatishchev
    c# .net unit-testing setup moq
    I have these mocks:_processWrapperMock = new Mock<IProcessWrapper>(MockBehavior.Strict); _processStartInfoMock = new Mock<IProcessStartInfo>();and a setup for the Start() method:_processWrapperMock.Setup(m => m.Start(_processStartInfoMock.Object)).Returns(new Process());and my _processWrapperMock instance is passed to the constructor for the object which contains the method I’m testing.var wrapper = new WrapperClassImTesting(_processWrapperMock.Object);I then execute the method wh

  • mosquito87
    asp.net-mvc asp.net-mvc-3 unit-testing moq mvcmailer
    I’d like to unit-test a method which is calling a method from the MvcMailer.I get the following error message:ArgumentNullException was unhandled by user code. Value cannot be null. Parameter name: routeDataThis is how I mock the Mailer with Moq:protected void InitializeMailer() {userMailer = new Mock<UserMailer>();userMailer.CallBase = true; }And my test method where (in the last line) the method is called which calls the mailer method:public void CreateUseraccountTest() {//Setup mailerus

  • NullUserException
    asp.net-mvc unit-testing asp.net-mvc-2 moq
    I’m using Moq to help in testing my ASP.NET MVC2 application.Problem: ArgumentException was unhandled by user code. Unable to obtain public key for StrongNameKeyPairThis code has been adapted from Scott Hanselman’s NerdDinner1.HomeController CreateHomeControllerAs(string userName){var mock = new Mock<ControllerContext>();mock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns(userName); // fails heremock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);var c

  • iCe
    c# tdd moq
    I´m trying to do TDD with an object that has a dependency on a COM Interface. I though about mocking the COM interface, while doing development testing, and do it real on the integration tests. However, I cannot mock the COM interface, I tried with Moq, and it throws an exception:System.TypeLoadException was unhandledby user code Message=Could not load type ‘Castle.Proxies.iTunesAppProxy’from assembly ‘DynamicProxyGenAssembly2,Version=0.0.0.0, Culture=neutral,PublicKeyToken=null’. The type ismar

  • Erik Dietrich
    c# asp.net unit-testing moq
    I am using hanselman tutorial to use Moq to create unit tests for my asp.net pages. I wrote the following code to test for ServerVariables in contextbase request class HttpContextBase contextbase = MoqHelper.FakeHttpContext(); contextbase.Request.ServerVariables.Add(“AUTH_TYPE”,”Forms”); <– error here contextbase.Request.ServerVariables.Add(“LOGON_USER”, “Tom”); contextbase.Request.ServerVariables.Add(“REQUEST_METHOD”, “GET”);But I am getting following exception. Please help.System.NullRefer

  • Tom Stickel
    moq mstest
    I am using MSTest to write unit tests, but I have been tasked with adding moq to the unit test. I understand that if an integration test is done in which a file system, a database is normally called, that mocking is essentially allowing for the testing without actually making those “real” calls. I have looked around and just need some help.I was starting with some basic utilities that I found and started with some basic testing of them with Asserts. However, I’m needing to take it to the next

  • James Hay
    c# unit-testing mocking moq
    I have a switch statement in a factory that returns a command based on the value of the enum passed in. Something like:public ICommand Create(EnumType enumType) {switch (enumType){case(enumType.Val1):return new SomeCommand();case(enumType.Val2):return new SomeCommand();case(enumType.Val3):return new SomeCommand();default:throw new ArgumentOutOfRangeException(“Unknown enumType” + enumType);} }I currently have a switch case for each value in the enum. I have unit tests for each of these cases. How