Esempio n. 1
0
        public void Test()
        {
            var handler = new DummyHandler();

            Assert.That(handler.TaskHandlerKey, Is.EqualTo("Dummy"));

            handler.OnHandleTask = (dp) =>
            {
                Assert.That(dp.S, Is.EqualTo("aaa"));
            };

            var bgTask = handler.ToBackgroundTask(new DummyParams {
                S = "aaa"
            });

            Assert.That(bgTask.HandlerKey, Is.EqualTo("Dummy"));

            handler.HandleTask(bgTask);
        }
Esempio n. 2
0
        public void SuspendWithNoSecondaryId()
        {
            var oldContext = new RequestContextData(RequestContext.GetContext());

            try
            {
                var mockHandler = new Mock <DummyHandler>();

                var handler = new DummyHandler();

                var bgTask = handler.ToBackgroundTask(new DummyParams()
                {
                    S = "SuspendRestore"
                });

                var primaryUa = new UserAccount()
                {
                    Name = "primaryId"
                };

                var primaryId = new IdentityInfo(primaryUa.Id, primaryUa.Name);

                var contextData = new RequestContextData(primaryId, RequestContext.GetContext().Tenant, "XYZ", null)
                {
                    TimeZone = "XYZTZ"
                };

                RequestContext.SetContext(contextData);

                using (new SecurityBypassContext())
                {
                    // Suspend
                    IEntity suspendedtask = handler.CreateSuspendedTask(bgTask);
                }
            }
            finally
            {
                RequestContext.SetContext(oldContext);
            }
        }
Esempio n. 3
0
        public void SuspendRestore()
        {
            var mockHandler = new Mock <DummyHandler>();

            var handler = new DummyHandler();

            var primaryUa = new UserAccount()
            {
                Name = Guid.NewGuid().ToString()
            };

            primaryUa.Save();
            var secondaryUa = new UserAccount()
            {
                Name = Guid.NewGuid().ToString()
            };

            secondaryUa.Save();

            var primaryId   = new IdentityInfo(primaryUa.Id, primaryUa.Name);
            var secondaryId = new IdentityInfo(secondaryUa.Id, secondaryUa.Name);

            var contextData = new RequestContextData(primaryId, RequestContext.GetContext().Tenant, "XYZ", secondaryId)
            {
                TimeZone = "XYZTZ"
            };

            var oldContext = new RequestContextData(RequestContext.GetContext());

            try
            {
                RequestContext.SetContext(contextData);


                using (new SecurityBypassContext())
                {
                    // Suspend
                    IEntity        suspendedtask;
                    BackgroundTask bgTask;


                    bgTask = handler.ToBackgroundTask(new DummyParams()
                    {
                        S = "SuspendRestore"
                    });

                    suspendedtask = handler.CreateSuspendedTask(bgTask);
                    suspendedtask.Save();

                    Assert.That(handler.annotateSuspendedTask_calls, Is.EqualTo(1));

                    var castTask = suspendedtask.As <SuspendedTask>();
                    Assert.That(castTask.StCulture, Is.EqualTo("XYZ"));
                    Assert.That(castTask.StTimezone, Is.EqualTo("XYZTZ"));
                    Assert.That(castTask.StIdentity.Id, Is.EqualTo(primaryUa.Id));
                    Assert.That(castTask.StSecondaryIdentity.Id, Is.EqualTo(secondaryUa.Id));

                    IEnumerable <BackgroundTask> restoredTasks;

                    //Restore
                    restoredTasks = handler.RestoreSuspendedTasks();

                    Assert.That(handler.restoreTaskData_Calls, Is.EqualTo(1));
                    Assert.That(restoredTasks.Count(), Is.EqualTo(1));

                    var context = restoredTasks.First().Context;

                    Assert.That(context.Culture, Is.EqualTo("XYZ"));
                    Assert.That(context.TimeZone, Is.EqualTo("XYZTZ"));
                    Assert.That(context.Identity.Id, Is.EqualTo(primaryId.Id));
                    Assert.That(context.SecondaryIdentity.Id, Is.EqualTo(secondaryId.Id));

                    var parameter = restoredTasks.First().GetData <DummyParams>();
                    Assert.That(parameter.S, Is.EqualTo("restored"));
                }
            }
            finally
            {
                RequestContext.SetContext(oldContext);
            }
        }