#pragma warning restore CS8603 // Possible null reference return.

    private static Func <IFixture> GetFactory(AutoDataOptions options, Type[] cusomizations)
    {
        return(() =>
        {
            IFixture fixture = new Fixture();

            if (cusomizations != null)
            {
                foreach (Type customizationType in cusomizations)
                {
                    if (typeof(ISpecimenBuilder).IsAssignableFrom(customizationType))
                    {
                        var specimentBuilder = Activator.CreateInstance(customizationType) as ISpecimenBuilder;
                        fixture.Customizations.Add(specimentBuilder);
                    }
                    else if (typeof(ICustomization).IsAssignableFrom(customizationType))
                    {
                        var customization = Activator.CreateInstance(customizationType) as ICustomization;
                        fixture = fixture.Customize(customization);
                    }
                    else
                    {
                        throw new InvalidEnumArgumentException($"{customizationType.FullName} does not implement ICustomization or ISpecimentBuilder");
                    }
                }
            }

            fixture = fixture.Customize(new AutoNSubstituteCustomization()
            {
                ConfigureMembers = (options & AutoDataOptions.SkipMembers) != AutoDataOptions.SkipMembers
            });

            if ((options & AutoDataOptions.UseEFMemoryContext) == AutoDataOptions.UseEFMemoryContext)
            {
                fixture = fixture.Customize(new InMemoryContextCustomization()
                {
                    AutoCreateDatabase = true,
                    OmitDbSets = true
                });
            }
            else if ((options & AutoDataOptions.UseEFSQLiteContext) == AutoDataOptions.UseEFSQLiteContext)
            {
                fixture = fixture.Customize(new SqliteContextCustomization()
                {
                    AutoCreateDatabase = true,
                    AutoOpenConnection = true,
                    OmitDbSets = true
                });
            }
            return fixture;
        });
    }
 public AutoDataNSubstituteAttribute(AutoDataOptions options = AutoDataOptions.Default, params Type[] customizations)
     : base(GetFactory(options, customizations))
 {
     this._skipLiveTest = (options & AutoDataOptions.SkipLiveTest) == AutoDataOptions.SkipLiveTest;
 }