using AutoFixture; using TableModel = Bit.Core.Models.Table; using Bit.Core.Models; using System.Collections.Generic; using Bit.Core.Enums; using AutoFixture.Kernel; using System; using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Core.Repositories.EntityFramework; using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures; using Bit.Test.Common.AutoFixture.Attributes; using Bit.Test.Common.AutoFixture; namespace Bit.Core.Test.AutoFixture.UserFixtures { internal class UserBuilder : ISpecimenBuilder { public object Create(object request, ISpecimenContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var type = request as Type; if (type == typeof(TableModel.User)) { var fixture = new Fixture(); var providers = fixture.Create>(); var user = fixture.WithAutoNSubstitutions().Create(); user.SetTwoFactorProviders(providers); return user; } else if (type == typeof(List)) { var fixture = new Fixture(); var users = fixture.WithAutoNSubstitutions().CreateMany(2); foreach (var user in users) { var providers = fixture.Create>(); user.SetTwoFactorProviders(providers); } return users; } return new NoSpecimen(); } } internal class UserFixture : ICustomization { public virtual void Customize(IFixture fixture) { fixture.Customizations.Add(new IgnoreVirtualMembersCustomization()); fixture.Customizations.Add(new GlobalSettingsBuilder()); fixture.Customizations.Add(new UserBuilder()); fixture.Customizations.Add(new OrganizationBuilder()); } } internal class EfUser : UserFixture { public override void Customize(IFixture fixture) { base.Customize(fixture); fixture.Customizations.Add(new EfRepositoryListBuilder()); fixture.Customizations.Add(new EfRepositoryListBuilder()); fixture.Customizations.Add(new EfRepositoryListBuilder()); } } internal class EfUserAutoDataAttribute : CustomAutoDataAttribute { public EfUserAutoDataAttribute() : base(new SutProviderCustomization(), new EfUser()) { } } internal class InlineEfUserAutoDataAttribute : InlineCustomAutoDataAttribute { public InlineEfUserAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization), typeof(EfUser) }, values) { } } }