Example #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);
        }
Example #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);
 }
Example #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);
 }
Example #5
0
 public static int EnqueuedCount(this ITestFixture fixture)
 {
     return(fixture.Get <JobStorage>()
            .As <MemoryStorage>()
            .Data
            .GetEnumeration <JobDto>()
            .Count());
 }
 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();
Example #7
0
        public static ITestFixture ClearFabricator(this ITestFixture fixture)
        {
            MiruTest.Log.Information($"Running _.{nameof(ClearFabricator)}()");

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

            return(fixture);
        }
Example #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);
 }
Example #10
0
        public HtmlGeneratorTest()
        {
            _ = new ServiceCollection()
                .AddMiruHtml()
                .AddMiruTestFixture()
                .BuildServiceProvider()
                .GetRequiredService <ITestFixture>();

            _htmlGenerator = _.Get <HtmlGenerator>();
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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]);
        }
Example #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);
        }
Example #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);
        }
Example #20
0
 public static SelfImprovFabricator Fab(this ITestFixture fixture)
 {
     return(fixture.Get <SelfImprovFabricator>());
 }
Example #21
0
        public static void Logout(this ITestFixture fixture)
        {
            MiruTest.Log.Information("Logging out the current user");

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