Dealing with TargetWithLayout in XUNIT

106 views Asked by At

I have a class,

public class CreateLoggingRuleFactory : ILoggingRuleFactory
{
    public LoggingRule CreateDefaultLoggingRule(string ruleName 
         , LogLevel minimumLevel, LogLevel maximumLevelName,TargetWithLayout targetWithoutStackTrace)
    {
        // blah blah
        var defaultLoggerRule = new LoggingRule(ruleName, minimumLevel targetWithoutStackTrace);
        return defaultLoggerRule;
    }

TargetWithLayout is from NLog API.

I want to make a integration test for it. So I have an uncompleted code

 public class CreateLoggingRuleFactorIntegrationTests
{

    [Theory]
    [InlineData(new object[] {"ConsoleLoggerFactory.MyConsoleLogger", LogLevel.Trace,LogLevel.Debug,ClassData(typeof(TargetWithLayout)})]
    public void CreateLoggingRuleFactory_CreateDefaultLogger_Should_Create_LoggingRule_Class()
    {
        // ARRANGE
        var createLoggingRuleFactory = new CreateLoggingRuleFactory();
        var defaultLoggerRule = createLoggingRuleFactory.CreateDefaultLoggingRule
            ();
        Assert.Equal(typeof(LoggingRule), defaultLoggerRule.GetType());
    }

My question is that I don't know how to pass the object TargetWithLayout to the test method.

1

There are 1 answers

0
AudioBubble On BEST ANSWER

Eventually I figure it out. We need to pass the instance of TargetWithLayout Something as an argument to the method.