I want to test the data inside the "item" object before it redirect to another action.
public ActionResult WebPageEdit(WebPage item, FormCollection form)
{
if (ModelState.IsValid)
{
item.Description = Utils.CrossSiteScriptingAttackCheck(item.Description);
item.Content = Utils.CrossSiteS...
TypeMock is too expensive for a hobbist like me :)
Moq or the next version of RhinoMocks have no plans on listening to the profiling API, why is that?
EDIT: This enables features such as:
Mocking non-virtual methods and
properties (!).
Mocking browser
environments.
simpler syntax which
is less fragile (and not having to go
trough...
I watched this Introduction to Moq video on Dimecasts.net. In the video, when the guy sets up his moq test, he has the following code:
[Test]
public void TestWithMock()
{
var mockEmailService = new Mock<IEmailService>();
mockEmailService.Expect(x =>
x.SendEmail(It.IsAny<string>,It.IsAny<string>)).Returns(true);
var ...
We are Silverlight Unit Test Framework for testing.
Which one will be better for my team? Rhino Mocks or Moq. No one has any experience with using a framework like this.
What are the pros and cons of using each framework in this environment?
...
I am having an issue using the Moq library to mock an Enum within my project. I am trying to test a class and one of the methods accepts an ENum. Is there any way to do this?
Here is the Enum I am trying to mock:
public enum PermissionType
{
Create = 0,
Read = 1,
Update = 2,
Delete = 3,
}
Here is the code I am trying ...
As part of a unit test I am trying to mock the return value of FormsIdentity.Ticket.UserData
The following will NOT work but it should give an idea of what I am trying to do:
var principal = Mock<IPrincipal>();
var formsIdentity = Mock<FormsIdentity>();
formsIdentity.Setup(a => a.Ticket.UserData).Returns("aaa | bbb | ccc");
principal.S...
We have a small wrapper class that uses ResourceManager to load string resources from assemblies.
We also have some unit tests that check it loads the correct details from the correct assemblies for different cultures, assemblies etc. Our tests are therefore currently dependant upon resources we have constructed for the test.
Is the...
Hi!
I'm using Nunit and Moq to test my asp.net mvc solution. Is this a good way to test that the model passed to the view is a correct object/collection?
[Test]
public void Start_Page_Should_Display_Posts()
{
var posts = new List<Post> {new Post {Id = 1}, new Post {Id = 2}};
var mock = new Mock<IRepository>();
mock.Setup(x...
I have a base class defined as:
Public MustInherit Class BaseRepository(Of T As Class)
and a class that inherits from this class, defined as:
Public Class CommunicationTypeRepository
Inherits BaseRepository(Of CommunicationType)
For testing purposes I have created a helper method that will use Moq to help fetching some ...
Hello!
We are trying to use PostSharp, more specifically the OnMethodInvocationAspect, to intercept the methods of a class.
The code runs fine, but when testing it with MOQ, it seems to be messing up with my mocks.
If I remove the aspects, all tests succeed. But, if I turn the aspects back on, the expectations on the MOQ mocks are not...
I am learning Moq, and I would like to mock an interface ISecureAsset that has a property Contexts which returns a list of SecurityContexts. I am testing a method on another class that accesses the Contexts property for authorization.
public interface ISecureAsset {
List<SecurityContext> Contexts { get; set; }
}
How can I do this ...
I am writing a number of unit tests for a logger class I created and I want to simulate the file class. I can't find the interface that I need to use to create the MOQ... so how do you successfully MOQ a class without an interface?
It also isn't clear to me how I can use dependency injection without having an interface available:
priv...
I am trying to embrace TDD and started learning about mocking. I need some advice on what i should test and how to make my classes more behavioral and not simple data containers (with a bunch of getters/setters).
Consider this class.
public class Post
{
List<Comment> Comments {get; private set;}
public void AddComment(string me...
How would I go about mocking an Image with Moq?
It has no constructors (is always generated from factory methods).
Basically I want to do something like this...
var image = new Mock<Image>();
image.Setup(i=>i.Save(someStream,ImageFormat.Jpeg);
var testableObject = new ObjectUnderTest(image.Object);
testableObject.MethodBeingTested();...
Do I have to rewrite my code to do this into an interface? Or is there an easier way? I am using Moq
...
I have a class like:
public class Store
{
public Store()
{
Products = new List<Product>();
}
public IList<Product> Products {get; private set;}
public void AddProduct(int id, string productCode)
{
Product p = new Product();
p.Id = id;
p.ProductCode = productCode;
//Validate before adding
...
I'm unit testing a demo application, which is a POP3 client. The POP3 client implements IDisposable, so I'm trying to test a 'using' cycle.
(I'm using nunit 2.5.2 and Moq 4.0)
/// <summary>
/// Unsuccesfull construct dispose cycle, no ILogger object given.
/// Expecting ArgumentNullException. Expecting TcpClient dispose t...
Dear all,
I'm new to using Moq and I cannot find the way for doing this.
I've a generateId private method, called
/// <summary>
/// Generates a call Id for external interfaces
/// </summary>
/// <returns></returns>
private string GenerateCallId()
{
return "EX" + SharedServicesClientProxy.Instance.GenerateId().ToString();
}
I wanted t...
I am new to Moq, so hopefully I am just missing something here. For some reason I am getting a TargetParameterCountException.
Can you see what I am doing wrong? Any questions? Please ask. :)
Here's my code:
[Test]
public void HasStudentTest_SaveToRepository_Then_HasStudentReturnsTrue()
{
var fakeStudents = new List<Stude...
Hi,
I want to Unit Test my application which use MSMQ but i found no way in order to Mock MessageQueue objects.
var queuePath = @".\Private$\MyQueue";
MessageQueue queue = null;
if (MessageQueue.Exists(queuePath))
{
queue = new MessageQueue(queuePath);
}
else
{
...