﻿using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace SnapMark.Web.Test.Controllers
{
    public abstract class BaseControllerTest
    {
        protected IServiceProvider CreateServiceProvider(params object[] objects)
        {
            var serviceCollection = new ServiceCollection();

            foreach (var obj in objects)
            {
                if (obj.GetType().GetInterfaces().Contains(typeof(ILoggerFactory)))
                {
                    serviceCollection.AddSingleton(typeof(ILoggerFactory), obj);
                }
                else
                {
                    serviceCollection.AddSingleton(obj.GetType().GetTypeInfo().BaseType, obj);
                }
            }

            return serviceCollection.BuildServiceProvider();
        }
    }
}
