lundi 16 octobre 2017

Parametrized tests using Nunit 3.x

I am having following scenario while testing and I want to ask you guys if there is shortcut for testing this.

[Test]
[TestCaseSource(nameof(MlTestCases))]
[TestCaseSource(nameof(QaTestCases))]
public void EditBetSlip_ShouldConvertOddsFromAmericanToDecimal(string selectionId)
{
    // Arrange
    var betSlipRequest = new PostBetSlipRequest
    {
        OddStyle = OddStyle.American.ToString(),
        Selections = new List<PostOneSelectionRequest>
        {
            new PostOneSelectionRequest
            {
                DisplayOdds = $"+{Fixture.Create<int>()}",
                Id = selectionId.Replace("#", "%23"),
            },
        },
        Bets = new List<PostOneBetRequest>
        {
            new PostOneBetRequest
            {
                OddStyle = OddStyle.American.ToString(),
                Id = 0,
                Stake = 10,
            },
        },
    };

    // Act
    _client.EditBetslip(betSlipRequest);
    var response = _client.RefreshBetslip(new GetBetSlipRequest { OddStyle = OddStyle.European.ToString() });
    var betslip = response.DeserializedBody;

    // Assert
    Assert.IsTrue(response.StatusCode == HttpStatusCode.OK);

    foreach (var selection in betslip.Selections)
    {
        Assert.DoesNotThrow(() => decimal.Parse(selection.DisplayOdds));
    }
}

Now I need to make the same test again but simply flip the OddStyle of PostBetSlipRequest and GetBetSlipRequest. I tried with [Values] attribute but it doesn't work the way I want.

What I want is to execute all these two test case sources once with American - European and another time with European - American is it possible?

Aucun commentaire:

Enregistrer un commentaire