Ejemplo n.º 1
0
        public static ITestFixture StopServer(this ITestFixture fixture)
        {
            MiruTest.Log.Debug("Stopping App's Server");

            fixture.Get <IHost>().StopAsync().GetAwaiter().GetResult();
            fixture.Get <IHost>().Dispose();

            MiruTest.Log.Debug("App's Server stopped");

            return(fixture);
        }
Ejemplo n.º 2
0
        public static ITestFixture StartServer2(this ITestFixture fixture)
        {
            var host2 = fixture.Get <IHost>();

            try
            {
                host2.Start();
            }
            catch (Exception exception)
            {
                throw new MiruTestConfigException(
                          "Could not start host for the App. Check the Inner Exception and your Program.cs/Startup.cs configurations",
                          exception.InnerException ?? exception);
            }

            // var server = fixture.Get<IServer>();
            //
            // var addresses = server.Features.Get<IServerAddressesFeature>().Addresses;
            //
            // if (addresses.Count == 0)
            //     throw new MiruTestConfigException(
            //         "The App's Server has no http addresses associated to it. Maybe the App is already running in another process?");

            return(fixture);
        }
 public static int EnqueuedCount(this ITestFixture fixture)
 {
     return(fixture.Get <JobStorage>()
            .GetMonitoringApi()
            .EnqueuedJobs("default", 0, 1000)
            .Count);
 }
Ejemplo n.º 4
0
 public static bool EnqueuedOneJobFor <TJob>(this ITestFixture fixture) where TJob : IJob
 {
     return(fixture.Get <JobStorage>()
            .As <MemoryStorage>()
            .Data
            .GetEnumeration <JobDto>()
            .Count(job => job.InvocationData.Contains(typeof(TJob).FullName !)) == 1);
 }
Ejemplo n.º 5
0
 public static int EnqueuedCount(this ITestFixture fixture)
 {
     return(fixture.Get <JobStorage>()
            .As <MemoryStorage>()
            .Data
            .GetEnumeration <JobDto>()
            .Count());
 }
Ejemplo n.º 6
0
 public static IEnumerable <TJob> EnqueuedJobs <TJob>(this ITestFixture fixture) where TJob : IMiruJob =>
 fixture.Get <JobStorage>()
 .GetMonitoringApi()
 .EnqueuedJobs("default", 0, 1000)
 .Select(result => result.Value)
 .Where(enqueueJob => enqueueJob.Job.Args[0].GetType() == typeof(TJob))
 .Select(enqueueJob => (TJob)enqueueJob.Job.Args[0])
 .ToList();
Ejemplo n.º 7
0
        public static ITestFixture ClearFabricator(this ITestFixture fixture)
        {
            MiruTest.Log.Information($"Running _.{nameof(ClearFabricator)}()");

            fixture.Get <Fabricator>().Clear();

            return(fixture);
        }
Ejemplo n.º 8
0
        public static ITestFixture MigrateDatabase(this ITestFixture fixture)
        {
            MiruTest.Log.Information($"Running _.{nameof(MigrateDatabase)}()");

            fixture.Get <IDatabaseMigrator>().UpdateSchema();

            return(fixture);
        }
 public static bool EnqueuedOneJobFor <TJob>(this ITestFixture fixture) where TJob : IMiruJob
 {
     return(fixture.Get <JobStorage>()
            .GetMonitoringApi()
            .EnqueuedJobs("default", 0, 1000)
            .Select(result => result.Value)
            .Count(enqueueJob => enqueueJob.Job.Args[0].GetType() == typeof(TJob)) == 1);
 }
Ejemplo n.º 10
0
        public HtmlGeneratorTest()
        {
            _ = new ServiceCollection()
                .AddMiruHtml()
                .AddMiruTestFixture()
                .BuildServiceProvider()
                .GetRequiredService <ITestFixture>();

            _htmlGenerator = _.Get <HtmlGenerator>();
        }
Ejemplo n.º 11
0
        public static T Make <T>(this ITestFixture fixture, params Action <T>[] customizations) where T : class
        {
            var made = fixture.Get <Fabricator>().Make <T>();

            foreach (var customization in customizations)
            {
                customization(made);
            }

            return(made);
        }
Ejemplo n.º 12
0
        public static ITestFixture ClearQueue(this ITestFixture fixture)
        {
            MiruTest.Log.Information($"Running _.{nameof(ClearQueue)}()");

            var storage = fixture.Get <JobStorage>().As <MemoryStorage>();

            var jobs = storage.Data.GetEnumeration <JobDto>();

            storage.Data.Delete(jobs);

            return(fixture);
        }
Ejemplo n.º 13
0
        public static IEnumerable <T> MakeManySaving <T>(this ITestFixture fixture, int howMany = 3, Action <T> customizations = null) where T : class
        {
            MiruTest.Log.Information($"Making and saving {howMany} {typeof(T).FullName}");

            var entities = fixture.Get <Fabricator>().MakeMany(howMany, customizations);

            MiruTest.Log.Debug(() => $"Made:{Environment.NewLine}{entities.Inspect()}");

            MiruTest.Log.Debug(() => $"Saving the {howMany} entities");

            fixture.Save(entities);

            return(entities);
        }
Ejemplo n.º 14
0
        public static string EnqueuedRawJob <TJob>(this ITestFixture fixture) where TJob : IJob
        {
            var job = fixture.Get <JobStorage>().As <MemoryStorage>()
                      .Data
                      .GetEnumeration <JobDto>()
                      .FirstOrDefault(job => job.InvocationData.Contains(typeof(TJob).FullName !));

            if (job == null)
            {
                throw new ShouldAssertException($"No job queued found of type {typeof(TJob).FullName}");
            }

            return(job.InvocationData);
        }
Ejemplo n.º 15
0
        public static bool ScheduledOneTaskFor <TTask>(this ITestFixture fixture) where TTask : ScheduledTask
        {
            var scheduler   = fixture.Get <Quartz.IScheduler>();
            var triggerKeys = scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .AnyGroup());

            //  triggerKeys.Result.Where(r => scheduler.GetTrigger(r))

            foreach (var triggerKey in triggerKeys.Result)
            {
                var triggerdetails = scheduler.GetTrigger(triggerKey);
                var Jobdetails     = scheduler.GetJobDetail(triggerdetails.Result.JobKey);
            }
            //Pegar o Jobdetails e filtar por tipo == typeof(TTask)
            return(true);
        }
        public static TJob EnqueuedJob <TJob>(this ITestFixture fixture) where TJob : IMiruJob
        {
            var entry = fixture.Get <JobStorage>()
                        .GetMonitoringApi()
                        .EnqueuedJobs("default", 0, 1000)
                        .Select(result => result.Value)
                        .FirstOrDefault(enqueueJob => enqueueJob.Job.Args[0].GetType() == typeof(TJob));

            if (entry == null)
            {
                throw new ShouldAssertException($"No job queued found of type {typeof(TJob).FullName}");
            }

            return((TJob)entry.Job.Args[0]);
        }
Ejemplo n.º 17
0
        public static IEnumerable <string> EnqueuedRawJobs <TJob>(this ITestFixture fixture) where TJob : IJob
        {
            var jobs = fixture.Get <JobStorage>().As <MemoryStorage>()
                       .Data
                       .GetEnumeration <JobDto>()
                       .Where(job => job.InvocationData.Contains(typeof(TJob).FullName !))
                       .Select(job => job.InvocationData)
                       .ToList();

            if (jobs.Count == 0)
            {
                throw new ShouldAssertException($"No job queued found of type {typeof(TJob).FullName}");
            }

            return(jobs);
        }
        public static IEnumerable <TJob> EnqueuedJobs <TJob>(this ITestFixture fixture) where TJob : IMiruJob
        {
            var entry = fixture.Get <JobStorage>()
                        .GetMonitoringApi()
                        .EnqueuedJobs("default", 0, 1000)
                        .Select(result => result.Value)
                        .Where(enqueueJob => enqueueJob.Job.Args[0].GetType() == typeof(TJob))
                        .Select(enqueueJob => (TJob)enqueueJob.Job.Args[0])
                        .ToList();

            if (entry.Count == 0)
            {
                throw new ShouldAssertException($"No job queued found of type {typeof(TJob).FullName}");
            }

            return(entry);
        }
Ejemplo n.º 19
0
        public static async Task <TUser> MakeUserAsync <TUser>(
            this ITestFixture fixture,
            string password = "******",
            Action <TUser> customizations = null)
            where TUser : UserfyUser
        {
            using var scope = fixture.Get <IMiruApp>().WithScope();

            var userManager = scope.Get <UserManager <TUser> >();

            var user = scope.Get <Fabricator>().Make(customizations);

            user.UserName = user.Email;

            await userManager.CreateAsync(user, password);

            return(user);
        }
Ejemplo n.º 20
0
 public static SelfImprovFabricator Fab(this ITestFixture fixture)
 {
     return(fixture.Get <SelfImprovFabricator>());
 }
Ejemplo n.º 21
0
        public static void Logout(this ITestFixture fixture)
        {
            MiruTest.Log.Information("Logging out the current user");

            fixture.Get <IUserSession>().Logout();
        }
Ejemplo n.º 22
0
 public static MongFabricator Fab(this ITestFixture fixture)
 {
     return(fixture.Get <MongFabricator>());
 }
Ejemplo n.º 23
0
 public static TUser CurrentUser <TUser>(this ITestFixture fixture) where TUser : IUser
 {
     return(fixture.Get <IUserSession <TUser> >().User().GetAwaiter().GetResult());
 }
Ejemplo n.º 24
0
 public static EmailSent LastEmailSent(this ITestFixture fixture)
 {
     return(fixture.Get <MemorySender>().Last());
 }
Ejemplo n.º 25
0
 public static long CurrentUserId(this ITestFixture fixture)
 {
     return(fixture.Get <IUserSession>().CurrentUserId);
 }
Ejemplo n.º 26
0
 public static IEnumerable <T> MakeMany <T>(this ITestFixture fixture, Action <T> customizations) where T : class
 {
     return(fixture.Get <Fabricator>().MakeMany(3, customizations));
 }
Ejemplo n.º 27
0
 public static T Make <T>(this ITestFixture fixture, Action <T> customizations = null) where T : class
 {
     return(fixture.Get <Fabricator>().Make(customizations));
 }
Ejemplo n.º 28
0
 public static Faker Faker(this ITestFixture fixture)
 {
     return(fixture.Get <Faker>());
 }
Ejemplo n.º 29
0
 public static SkeletonFabricator Fab(this ITestFixture fixture)
 {
     return(fixture.Get <SkeletonFabricator>());
 }
Ejemplo n.º 30
0
 public static IEnumerable <EmailSent> AllEmailsSent(this ITestFixture fixture)
 {
     return(fixture.Get <MemorySender>().All());
 }