© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
2 replies
Saiyanslayer

Parameterized Unit Testing Class Types

I have the following test in xUnit:
    [Fact]
    public async Task QaTrackUrls_Should_Connect() {
        var context = new QaTrackContext();
        //var property = typeof(IModelBase).GetProperty("RequestUrl").GetValue(model).ToString();

        var result = await context.GetAsync<ServiceEventModel>(ServiceEventsModel.RequestUrl);

        Assert.True(result.IsSuccess);
    }
    [Fact]
    public async Task QaTrackUrls_Should_Connect() {
        var context = new QaTrackContext();
        //var property = typeof(IModelBase).GetProperty("RequestUrl").GetValue(model).ToString();

        var result = await context.GetAsync<ServiceEventModel>(ServiceEventsModel.RequestUrl);

        Assert.True(result.IsSuccess);
    }


I want to parameterize the test by giving classes (like ServiceEventsModel) instead of writing each one manually. so far, I've tried this:
    [Theory]
    [InlineData(typeof(ServiceEventsModel))]
    public async Task QaTrackUrls_Should_Connect(Type model) {
        var context = new QaTrackContext();
        var property = typeof(IModelBase).GetProperty("RequestUrl").GetValue(model).ToString();

        var result = await context.GetAsync<model>(property);

        Assert.True(result.IsSuccess);
    }
    [Theory]
    [InlineData(typeof(ServiceEventsModel))]
    public async Task QaTrackUrls_Should_Connect(Type model) {
        var context = new QaTrackContext();
        var property = typeof(IModelBase).GetProperty("RequestUrl").GetValue(model).ToString();

        var result = await context.GetAsync<model>(property);

        Assert.True(result.IsSuccess);
    }

but
context.GetAsync<model>
context.GetAsync<model>
gives an error
 'model' is a variable but is used like a type 
 'model' is a variable but is used like a type 
making it typeof(model) doesn't work and creates more errors.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

unit testing
C#CC# / help
2y ago
Unit testing
C#CC# / help
2y ago
✅ Unit testing
C#CC# / help
3y ago
Unit testing FakeItEasy
C#CC# / help
2y ago