Example #1
0
        public PushNotificationCommandHandlerTests()
        {
            repository  = new FakeRepository();
            userContext = new FakeUserContext();
            userContext.SetFakeUser();
            FakeClock.Setup();

            sut = new ApnsNotificationCommandHandler(repository, userContext);
        }
        public CommandPermissionAuthorizerTests()
        {
            commandPermissionCache         = Substitute.For <ICommandPermissionCache>();
            permissionAuthorizationMatcher = Substitute.For <IPermissionAuthorizationMatcher>();
            userContext = new FakeUserContext();

            sut = new CommandPermissionAuthorizer(commandPermissionCache,
                                                  permissionAuthorizationMatcher, userContext);
        }
        public UserPermissionAuthorizerTests()
        {
            userContext = new FakeUserContext();
            permissionAuthorizationMatcher = Substitute.For <IPermissionAuthorizationMatcher>();
            userPermissionResolver         = Substitute.For <IUserPermissionResolver>();

            permissionType1Id = Guid.Parse("0F292EFD-792E-48EC-93DF-CD99EEDB5885");

            sut = new UserPermissionAuthorizer(userContext, permissionAuthorizationMatcher,
                                               userPermissionResolver);
        }
Example #4
0
        public UserPermissionAuthorizerTests()
        {
            userContext = new FakeUserContext();
            permissionAuthorizationMatcher = Substitute.For <IPermissionAuthorizationMatcher>();
            userPermissionResolver         = Substitute.For <IUserPermissionResolver>();
            permissionTypeRegistry         = Substitute.For <IPermissionTypeRegistry>();

            permissionTypeRegistry.GetPermissionTypeById(Guid.Parse("0F292EFD-792E-48EC-93DF-CD99EEDB5885"))
            .Returns(new PermissionType(Guid.Parse("0F292EFD-792E-48EC-93DF-CD99EEDB5885"), "permission"));

            sut = new UserPermissionAuthorizer(userContext, permissionAuthorizationMatcher,
                                               userPermissionResolver, permissionTypeRegistry);
        }
Example #5
0
        public void PCLock()
        {
            Exception ex = null;
            int jobId = 1;
            long flag = Interlocked.CompareExchange(ref s_flag, 1, 0);
            var un = "fixed_unique_name";
            if (flag == 1)
            {
                Concurrent();
                return;
            }

            try
            {

                using (var uc = new FakeUserContext(un))
                {
                    bool failed = false;
                    var resolver = new RejectConcurrentEditsConflictResolver();
                    try
                    {
                        s_pcAttempt.Increment();
                        Exec(jobId, 1, 1, resolver); // test can get the lock
                        s_pcAttemptSuccess.Increment();
                    }
                    catch (ConcurrencyException)
                    {

                    }
                    catch
                    {
                        failed = true;
                        return;
                    }

                    if (!failed)
                    {
                        try
                        {
                            s_pcPost.Increment();
                            Exec(jobId, 1, 0, resolver); // test can update after acquiring
                            s_pcPostSuccess.Increment();
                        }
                        catch (Exception e)
                        {
                            ex = e;
                        }
                    }

                }
            }
            finally
            {
                try
                {
                    EnsureJobIsNotLocked(1, ex, un);
                }
                finally
                {
                    Interlocked.Exchange(ref s_flag, 0);
                }
            }
        }
Example #6
0
        private void Worker(int jobId, double lockChance, IConflictResolver resolver)
        {
            using (var uc = new FakeUserContext())
            {
                Exception ex = null;
                try
                {
                    Exec(jobId, lockChance, s_conflictGuarantee, resolver);
                }
                catch (Exception e)
                {
                    ex = e;
                }

                EnsureJobIsNotLocked(jobId, ex, uc.Identity.Name);
            }

        }