public void ShouldGetAdminAppOdsInstancesForUserSortedByName()
        {
            var users     = SetupUsers(2).ToList();
            var testUser1 = users[0];
            var testUser2 = users[1];

            var testInstances = SetupOdsInstanceRegistrations(6).OrderBy(x => x.Name).ToList();

            var testInstancesAssignedToUser1 = testInstances.Take(3).ToList();
            var testInstancesAssignedToUser2 = testInstances.Skip(3).Take(3).ToList();

            SetupUserWithOdsInstanceRegistrations(testUser1.Id, testInstancesAssignedToUser1);
            SetupUserWithOdsInstanceRegistrations(testUser2.Id, testInstancesAssignedToUser2);

            var command = new GetOdsInstanceRegistrationsByUserIdQuery(SetupContext);

            var resultsForUser1 = command.Execute(testUser1.Id).ToList();

            resultsForUser1.Count.ShouldBe(testInstancesAssignedToUser1.Count);
            resultsForUser1.Select(x => x.Name).ShouldBe(testInstancesAssignedToUser1.Select(x => x.Name));

            var resultsForUser2 = command.Execute(testUser2.Id).ToList();

            resultsForUser2.Count.ShouldBe(testInstancesAssignedToUser2.Count);
            resultsForUser2.Select(x => x.Name).ShouldBe(testInstancesAssignedToUser2.Select(x => x.Name));
        }
Ejemplo n.º 2
0
        public void ShouldAddOdsInstanceRegistrationsForUser()
        {
            var existingUser = SetupUsers(1).Single();

            var alreadyAddedInstances = SetupOdsInstanceRegistrations().OrderBy(x => x.Name).ToList();

            SetupUserWithOdsInstanceRegistrations(existingUser.Id, alreadyAddedInstances);

            var newInstancesToAdd = SetupOdsInstanceRegistrations().OrderBy(x => x.Name).ToList();

            var updateModel = new EditOdsInstanceRegistrationForUserModel
            {
                UserId = existingUser.Id,
                OdsInstanceRegistrations = newInstancesToAdd.Select(x => new OdsInstanceRegistrationSelection
                {
                    Name = x.Name,
                    OdsInstanceRegistrationId = x.Id,
                    Selected = true
                }).ToList()
            };

            var command = new EditOdsInstanceRegistrationForUserCommand();

            command.Execute(updateModel);

            var query   = new GetOdsInstanceRegistrationsByUserIdQuery(SetupContext);
            var results = query.Execute(existingUser.Id).ToList();

            results.Count.ShouldBe(newInstancesToAdd.Count);
            results.Select(x => x.Name).ShouldBe(newInstancesToAdd.Select(x => x.Name));
        }
        public void ShouldDeleteUser()
        {
            var existingUsers = SetupUsers(2, Role.Admin).ToList();

            var userToBeDeleted    = existingUsers[0];
            var userNotToBeDeleted = existingUsers[1];

            var testInstances = SetupOdsInstanceRegistrations(6).OrderBy(x => x.Name).ToList();

            var testInstancesAssignedToDeletedUser    = testInstances.Take(3).ToList();
            var testInstancesAssignedToNotDeletedUser = testInstances.Skip(3).Take(3).ToList();

            SetupUserWithOdsInstanceRegistrations(userToBeDeleted.Id, testInstancesAssignedToDeletedUser);
            SetupUserWithOdsInstanceRegistrations(userNotToBeDeleted.Id, testInstancesAssignedToNotDeletedUser);

            var queryInstances = new GetOdsInstanceRegistrationsByUserIdQuery(SetupContext);

            queryInstances.Execute(userToBeDeleted.Id).Count().ShouldBe(3);
            queryInstances.Execute(userNotToBeDeleted.Id).Count().ShouldBe(3);

            var queryRoles = new GetRoleForUserQuery();

            var deleteModel = new DeleteUserModel
            {
                Email  = userToBeDeleted.Email,
                UserId = userToBeDeleted.Id
            };

            var command = new DeleteUserCommand();

            command.Execute(deleteModel);

            var deletedUser = Query(userToBeDeleted.Id);

            deletedUser.ShouldBeNull();
            queryInstances.Execute(userToBeDeleted.Id).Count().ShouldBe(0);
            queryRoles.Execute(userToBeDeleted.Id).ShouldBeNull();

            var notDeletedUser = Query(userNotToBeDeleted.Id);

            notDeletedUser.UserName.ShouldBe(userNotToBeDeleted.UserName);
            notDeletedUser.Email.ShouldBe(userNotToBeDeleted.Email);
            queryInstances.Execute(userNotToBeDeleted.Id).Count().ShouldBe(3);
            queryRoles.Execute(userNotToBeDeleted.Id).ShouldBe(Role.Admin);
        }
Ejemplo n.º 4
0
        public void ShouldRemoveOdsInstanceRegistrationsForUser()
        {
            var existingUser = SetupUsers(1).Single();

            var alreadyAddedInstances = SetupOdsInstanceRegistrations(5).OrderBy(x => x.Name).ToList();

            SetupUserWithOdsInstanceRegistrations(existingUser.Id, alreadyAddedInstances);

            var query   = new GetOdsInstanceRegistrationsByUserIdQuery(SetupContext);
            var results = query.Execute(existingUser.Id).ToList();

            results.Count.ShouldBe(5);
            results.Select(x => x.Name).ShouldBe(alreadyAddedInstances.Select(x => x.Name));

            // Select only the first 3 instances

            var instancesToKeep = alreadyAddedInstances.Take(3).ToList();

            var updateModel = new EditOdsInstanceRegistrationForUserModel
            {
                UserId = existingUser.Id,
                OdsInstanceRegistrations = instancesToKeep.Select(x => new OdsInstanceRegistrationSelection
                {
                    Name = x.Name,
                    OdsInstanceRegistrationId = x.Id,
                    Selected = true
                }).ToList()
            };

            var command = new EditOdsInstanceRegistrationForUserCommand();

            command.Execute(updateModel);

            results = query.Execute(existingUser.Id).ToList();

            results.Count.ShouldBe(3);
            results.Select(x => x.Name).ShouldBe(instancesToKeep.Select(x => x.Name));
        }
        public void ShouldDeregisterOdsInstance()
        {
            var users     = SetupUsers(2).ToList();
            var testUser1 = users[0];
            var testUser2 = users[1];

            var testInstances = SetupOdsInstanceRegistrations(2).OrderBy(x => x.Name).ToList();
            var testInstanceToBeDeregistered    = testInstances[0];
            var testInstanceNotToBeDeregistered = testInstances[1];

            MockInstanceRegistrationSetup(testInstances);

            using (var database = new SqlServerUsersContext())
            {
                database.OdsInstances.Count().ShouldBe(2);
                database.Applications.Count().ShouldBe(2);
                database.Clients.Count().ShouldBe(2);
                database.ApplicationEducationOrganizations.Count().ShouldBe(2);
                database.ClientAccessTokens.Count().ShouldBe(2);
            }

            ShouldNotBeNull <SecretConfiguration>(x => x.OdsInstanceRegistrationId == testInstanceToBeDeregistered.Id);
            ShouldNotBeNull <SecretConfiguration>(x => x.OdsInstanceRegistrationId == testInstanceNotToBeDeregistered.Id);

            SetupUserWithOdsInstanceRegistrations(testUser1.Id, testInstances);
            SetupUserWithOdsInstanceRegistrations(testUser2.Id, testInstances);

            var queryInstances = new GetOdsInstanceRegistrationsByUserIdQuery(SetupContext);

            queryInstances.Execute(testUser1.Id).Count().ShouldBe(2);
            queryInstances.Execute(testUser2.Id).Count().ShouldBe(2);

            var deregisterModel = new DeregisterOdsInstanceModel
            {
                OdsInstanceId = testInstanceToBeDeregistered.Id,
                Name          = testInstanceToBeDeregistered.Name,
                Description   = testInstanceToBeDeregistered.Description
            };


            using (var sqlServerUsersContext = new SqlServerUsersContext())
            {
                var command = new DeregisterOdsInstanceCommand(SetupContext, sqlServerUsersContext);

                command.Execute(deregisterModel);
            }

            var deregisteredOdsInstance = SetupContext.OdsInstanceRegistrations.SingleOrDefault(x => x.Id == testInstanceToBeDeregistered.Id);

            deregisteredOdsInstance.ShouldBeNull();

            var notDeregisteredOdsInstance = SetupContext.OdsInstanceRegistrations.SingleOrDefault(x => x.Id == testInstanceNotToBeDeregistered.Id);

            notDeregisteredOdsInstance.ShouldNotBeNull();

            ShouldBeNull <SecretConfiguration>(x => x.OdsInstanceRegistrationId == testInstanceToBeDeregistered.Id);
            ShouldNotBeNull <SecretConfiguration>(x => x.OdsInstanceRegistrationId == testInstanceNotToBeDeregistered.Id);

            var instancesAssignedToUser1 = queryInstances.Execute(testUser1.Id).ToList();

            instancesAssignedToUser1.Count.ShouldBe(1);
            var onlyInstanceAssignedToUser1 = instancesAssignedToUser1.Single();

            onlyInstanceAssignedToUser1.Id.ShouldBe(testInstanceNotToBeDeregistered.Id);
            onlyInstanceAssignedToUser1.Name.ShouldBe(testInstanceNotToBeDeregistered.Name);
            onlyInstanceAssignedToUser1.Description.ShouldBe(testInstanceNotToBeDeregistered.Description);

            var instancesAssignedToUser2 = queryInstances.Execute(testUser2.Id).ToList();

            instancesAssignedToUser2.Count.ShouldBe(1);
            var onlyInstanceAssignedToUser2 = instancesAssignedToUser2.Single();

            onlyInstanceAssignedToUser2.Id.ShouldBe(testInstanceNotToBeDeregistered.Id);
            onlyInstanceAssignedToUser2.Name.ShouldBe(testInstanceNotToBeDeregistered.Name);
            onlyInstanceAssignedToUser2.Description.ShouldBe(testInstanceNotToBeDeregistered.Description);

            using (var database = new SqlServerUsersContext())
            {
                database.OdsInstances.Count().ShouldBe(2);
                database.Applications.Count().ShouldBe(1);
                database.Clients.Count().ShouldBe(1);
                database.ApplicationEducationOrganizations.Count().ShouldBe(1);
                database.ClientAccessTokens.Count().ShouldBe(1);
            }
        }