Example #1
0
        public virtual async Task <ActionResult> Delete(DeleteAccountAsAdminViewModel model)
        {
            var user = UserService.FindByUsername(model.AccountName);

            if (user == null || user.IsDeleted)
            {
                return(View("DeleteUserAccountStatus", new DeleteUserAccountStatus()
                {
                    AccountName = model.AccountName,
                    Description = $"Account {model.AccountName} not found.",
                    Success = false
                }));
            }
            else
            {
                var admin  = GetCurrentUser();
                var status = await _deleteAccountService.DeleteAccountAsync(
                    userToBeDeleted : user,
                    userToExecuteTheDelete : admin,
                    signature : model.Signature,
                    orphanPackagePolicy : model.ShouldUnlist?AccountDeletionOrphanPackagePolicy.UnlistOrphans : AccountDeletionOrphanPackagePolicy.KeepOrphans,
                    commitAsTransaction : true);

                return(View("DeleteUserAccountStatus", status));
            }
        }
            public async Task DeleteDeletedAccount()
            {
                // Arrange
                string username   = "******";
                var    controller = GetController();

                var fakes    = Get <Fakes>();
                var testUser = fakes.CreateUser(username);

                testUser.IsDeleted = true;

                GetMock <IUserService>()
                .Setup(stub => stub.FindByUsername(username, false))
                .Returns(testUser);

                var model = new DeleteAccountAsAdminViewModel()
                {
                    AccountName = username
                };

                // act
                var result = await controller.Delete(model);

                // Assert
                AssertNotFoundResult(result, username);
            }
            public async Task DeleteNotExistentAccount()
            {
                // Arrange
                var username   = "******";
                var controller = GetController();

                var model = new DeleteAccountAsAdminViewModel()
                {
                    AccountName = username
                };

                // Act
                var result = await controller.Delete(model);

                // Assert
                AssertNotFoundResult(result, username);
            }
            public async Task DeleteHappyAccount(bool shouldUnlist)
            {
                // Arrange
                string username   = "******";
                var    controller = GetController();
                var    fakes      = Get <Fakes>();
                var    testUser   = fakes.CreateUser(username);

                testUser.IsDeleted = false;
                testUser.Key       = 1;
                var adminUser = fakes.Admin;

                controller.SetCurrentUser(adminUser);

                var expectedStatus = new DeleteAccountStatus();

                GetMock <IDeleteAccountService>()
                .Setup(stub => stub.DeleteAccountAsync(
                           testUser,
                           adminUser,
                           shouldUnlist ? AccountDeletionOrphanPackagePolicy.UnlistOrphans : AccountDeletionOrphanPackagePolicy.KeepOrphans))
                .ReturnsAsync(expectedStatus);

                var model = new DeleteAccountAsAdminViewModel()
                {
                    AccountName  = username,
                    ShouldUnlist = shouldUnlist
                };

                // act
                var result = await controller.Delete(model);

                var status = ResultAssert.IsView <DeleteAccountStatus>(result, "DeleteAccountStatus");

                // Assert
                Assert.Equal(expectedStatus, status);
            }
Example #5
0
        public virtual async Task <ActionResult> Delete(DeleteAccountAsAdminViewModel model)
        {
            var accountToDelete = UserService.FindByUsername(model.AccountName) as TUser;

            if (accountToDelete == null || accountToDelete.IsDeleted)
            {
                return(View("DeleteAccountStatus", new DeleteAccountStatus()
                {
                    AccountName = model.AccountName,
                    Description = $"Account {model.AccountName} not found.",
                    Success = false
                }));
            }
            else
            {
                var admin  = GetCurrentUser();
                var status = await DeleteAccountService.DeleteAccountAsync(
                    userToBeDeleted : accountToDelete,
                    userToExecuteTheDelete : admin,
                    orphanPackagePolicy : model.ShouldUnlist?AccountDeletionOrphanPackagePolicy.UnlistOrphans : AccountDeletionOrphanPackagePolicy.KeepOrphans);

                return(View("DeleteAccountStatus", status));
            }
        }