Question: I am trying to improve my unit testing skills and i was wondering if someone could tell me the best way of writing a test for writing a test for "sorted odd numbers of a given array of integers". At the moment I am passing the data into the test with params but I would to verify the output is correct aswell.

```
    [Theory]
    [InlineData(1,2,3,4)]
    public void SortArrayOddNumber(params int[] number)
    {
        var s = number.Where(n => (n % 2) == 0).OrderBy(n=>n);
    }

```

Answer: 
You should pass your input array and expected array as parameters in your tests .

You can use InlineData like this :

```
    [Theory]
    [InlineData(new[] { 0, 1, 2, 3, 4 }, new[] { 0, 2, 4 })]
    [InlineData(new[] { 0, 1, 3, 4 }, new[] { 0, 4 })]
    public void Should_return_odd_numbers_in_ascending_order(int[] input, int[] expectedSortedArray)
    {
        var result = input.SortOddNumbers();

        result.Should().BeEquivalentTo(expectedSortedArray, opt => opt.WithStrictOrdering());
    }

```

Or you can use MemberData like this :

```
    public static IEnumerable<object[]> Data => new List<object[]>
    {
       new object[] {new[] {0, 1, 2, 3, 4}, new[] {0, 2, 4}},
       new object[] {new[] {0, 1, 3, 4}, new[] {0, 4}}
    };

    [Theory, MemberData(nameof(Data))]
    public void Should_return_odd_numbers_in_ascending_order(int[] input, int[] expectedSortedArray)
    {
        var result = input.SortOddNumbers();

        result.Should().BeEquivalentTo(expectedSortedArray, opt => opt.WithStrictOrdering());
    }

```

And SortOddNumbers Extension method :

```
public static class NumberExtensions
{
    public static int[] SortOddNumbers(this int[] input)
    {
        return input.Where(i => (i % 2) == 0).OrderBy(i => i).ToArray();
    }
}

```
First of all, you are writing the logic inside the test.

You want to test a separate class instead.

Second, where would you pass the expected result?

You can either find a way to pass multiple data to your test, like Arsalan said in his answer, or your assertion should check that all numbers are odd and that they are in ascending order.

You can look at `FluentAssertions` library, and write your test like this:

```cs
// The class/method you are testing
public class MyLogic
{
  public int[] SortOddNumbers(int[] input)
  {
    return input.Where(n => (n%2) == 1).OrderBy(n => n).ToArray();
  }
}

```

And the test:

```cs
public class MyLogic.Tests
{

  [Theory]
  [InlineData(6,1,2,3,10,9,8)]
  public void SortOddNumbers_ShouldReturn_OddNumbersInAscendingOrder(params int[] input)
  {
    // Arrange
    var logic = new MyLogic();
    // Act
    var actual = logic.SortOddNumbers(input);
    // Assert
    actual.Should().OnlyContain(x => x % 2 == 1);
    actual.Should().BeInAscendingOrder(x => x);
  }
}

```

Edit: To find multiple ways (and inspiration) on how to pass data to your tests, here is an excellent article by Andrew Lock: <https://andrewlock.net/creating-parameterised-tests-in-xunit-with-inlinedata-classdata-and-memberdata/>