# Do Nothing

Use `DoNothing` to explicitly arrange a method or property so that calling it does nothing. All logic inside the method or property body is skipped.

While mocks with [Loose](https://www.telerik.com/products/justmock/documentation/basic-usage/mock-behaviors/loose) or [RecursiveLoose](https://www.telerik.com/products/justmock/documentation/basic-usage/mock-behaviors/recursiveloose) behavior already skip void calls by default, `DoNothing` makes that intent explicit in your test. This improves readability and lets you chain further expectations such as `MustBeCalled()` on the same arrangement.

We will use the following interface for the examples in this article:

#### Sample setup

```C#
public interface IFoo
{
    int Bar { get; set; }
    void VoidCall();
}
```

```VB
Public Interface IFoo
    Property Bar() As Integer
    Function VoidCall()
End Interface
```

## Skip the Logic of a Method

Before describing the usage of the `DoNothing` method, let's first see an example to illustrate it.

#### Example 1: Sample usage of DoNothing on a void method

```C#
[TestMethod]
public void SimpleExampleWithDoNothing()
{
    // Arrange
    var foo = Mock.Create<IFoo>();

    Mock.Arrange(() => foo.VoidCall()).DoNothing().MustBeCalled();

    // Act
    foo.VoidCall();

    // Assert
    Mock.Assert(foo);
}
```

```VB
<TestMethod()>
Public Sub SimpleExampleWithDoNothing()
    ' Arrange
    Dim foo = Mock.Create(Of IFoo)()

    Mock.Arrange(Function() foo.VoidCall()).DoNothing().MustBeCalled()

    ' Act
    foo.VoidCall()

    ' Assert
    Mock.Assert(foo)
End Sub
```

In the example, we mark `foo.VoidCall()` with `DoNothing` and `MustBeCalled`. In this way, we indicate that a call to `foo.VoidCall` must be ignored and nothing should happen, but still the method should be called during the execution of the test.

You can use `DoNothing` with **non-void calls** as well. For the example we will be using the following `Foo` class:

#### Sample setup\_\_

```C#
public class Foo
{
    public int Echo(int num)
    {
        return num;
    }
}
```

```VB

Public Class Foo
    Function Echo(num As Integer) As Integer
        Throw New NotImplementedException
    End Function
End Class
```

#### Example 2: Sample usage of DoNothing with non-void method

```C#
[TestMethod]
public void DoNothingWithNonPublicCalls()
{
    // Arrange
    var foo = Mock.Create<Foo>();

    Mock.Arrange(() => foo.Echo(Arg.AnyInt)).DoNothing();

    // Act
    foo.Echo(10);
}
```

```VB
<TestMethod()>
Public Sub DoNothingWithNonPublicCalls()
    ' Arrange
    Dim foo = Mock.Create(Of Foo)()
    Mock.Arrange(Function() foo.Echo(Arg.AnyInt)).DoNothing()

    ' Act
    foo.Echo(10)
End Sub
```

## Skip the Logic of a Property Setter

`DoNothing` can be also used on a call to a property set.

#### Example 4: Usage of DoNothing on property setter

```C#
[TestMethod]
public void AssertDoNothingOnPropertySet()
{
    // Arrange
    var foo = Mock.Create<IFoo>();

    Mock.ArrangeSet(() => foo.Bar = 1).DoNothing().MustBeCalled();

    // Act
    foo.Bar = 1;

    // Assert
    Mock.Assert(foo);
}
```

```VB
<TestMethod()>
Public Sub DAssertDoNothingOnPropertySet()
    'Arrange
    Dim foo = Mock.Create(Of IFoo)()
    Mock.ArrangeSet(Sub() foo.Bar = 0).DoNothing().MustBeCalled()

    'Act
    foo.Bar = 0

    'Assert
    Mock.Assert(foo)
End Sub
```

## See Also

* [Call Original](https://www.telerik.com/products/justmock/documentation/basic-usage/mock/call-original)
* [Do Instead](https://www.telerik.com/products/justmock/documentation/basic-usage/mock/do-instead)
* [Must Be Called](https://www.telerik.com/products/justmock/documentation/basic-usage/mock/must-be-called)
* [Raise](https://www.telerik.com/products/justmock/documentation/basic-usage/mock/raise)
* [Raises](https://www.telerik.com/products/justmock/documentation/basic-usage/mock/raises)
* [Returns](https://www.telerik.com/products/justmock/documentation/basic-usage/mock/returns)
* [Throws](https://www.telerik.com/products/justmock/documentation/basic-usage/mock/throws)
