GetOrganisationBySimpleSearchTerm_SearchIsValid_AndNoConflictingOrganisationUserExists_ReturnsOrganisation(
            string existingUserId, string userId, Core.Shared.UserStatus userStatus, Core.Shared.OrganisationStatus organisationStatus)
        {
            var organisation = A.Fake <Organisation>();

            A.CallTo(() => organisation.TradingName).Returns("A Company");
            A.CallTo(() => organisation.OrganisationStatus).Returns(organisationStatus.ToDomainEnumeration <OrganisationStatus>());

            A.CallTo(() => context.Organisations)
            .Returns(dbContextHelper.GetAsyncEnabledDbSet(new List <Organisation> {
                organisation
            }));

            var organisationUser = new OrganisationUser(new Guid(userId), new Guid(existingUserId), userStatus.ToDomainEnumeration <UserStatus>());

            A.CallTo(() => context.OrganisationUsers)
            .Returns(dbContextHelper.GetAsyncEnabledDbSet(new List <OrganisationUser>
            {
                organisationUser
            }));

            var result = await FindMatchingOrganisationsDataAccess().GetOrganisationsBySimpleSearchTerm("A", new Guid(userId));

            Assert.Single(result);
            Assert.Equal(organisation, result.Single());
        }
Esempio n. 2
0
        private OrganisationUser OrganisationUser(UserStatus userStatus = UserStatus.Pending, Guid?organisationId = null, Guid?userId = null)
        {
            if (!organisationId.HasValue)
            {
                return(A.Fake <OrganisationUser>());
            }

            return(new OrganisationUser(userId ?? Guid.NewGuid(), organisationId.Value, userStatus.ToDomainEnumeration <Domain.User.UserStatus>()));
        }
Esempio n. 3
0
        public async Task UserDoesNotExist_ThrowsException(UserStatus userStatus)
        {
            var organisationUserId = Guid.NewGuid();

            A.CallTo(() => dataAccess.GetOrganisationUser(organisationUserId))
            .Returns((OrganisationUser)null);

            await Assert.ThrowsAnyAsync <Exception>(
                () =>
                UpdateOrganisationUserStatusHandler()
                .HandleAsync(new UpdateOrganisationUserStatus(organisationUserId, userStatus)));
        }
        public async void SingleOrganisationUserForUser_ShouldGetRequest(Core.Shared.UserStatus userStatus)
        {
            var organisationId = Guid.NewGuid();
            var userId         = Guid.NewGuid();

            var organisationUser = new OrganisationUser(userId, organisationId,
                                                        userStatus.ToDomainEnumeration <UserStatus>());

            A.CallTo(() => context.OrganisationUsers)
            .Returns(Data(new List <OrganisationUser>
            {
                organisationUser
            }));

            var result = await GetManageableOrganisationUsersDataAccess().GetManageableUsers(organisationId);

            Assert.Equal(organisationUser, result.Single());
        }
 public async Task <int> ChangeOrganisationUserStatus(OrganisationUser organisationUser, Core.Shared.UserStatus status)
 {
     organisationUser.UpdateUserStatus(status.ToDomainEnumeration <UserStatus>());
     return(await context.SaveChangesAsync());
 }
        public async void MultipleOrganisationUsersForOneUser_ShouldNotRetrieveAnyRejectedOrganisationUsers_WhenNonRejectedOrganisationUserAlsoExists(Core.Shared.UserStatus previousUserStatus, Core.Shared.UserStatus currentUserStatus)
        {
            var organisationId = Guid.NewGuid();
            var userId         = Guid.NewGuid();

            var previousOrganisationUser = new OrganisationUser(userId, organisationId, previousUserStatus.ToDomainEnumeration <UserStatus>());
            var currentOrganisationUser  = new OrganisationUser(userId, organisationId, previousUserStatus.ToDomainEnumeration <UserStatus>());

            A.CallTo(() => context.OrganisationUsers)
            .Returns(Data(new List <OrganisationUser>
            {
                previousOrganisationUser,
                currentOrganisationUser
            }));

            var result = await GetManageableOrganisationUsersDataAccess().GetManageableUsers(organisationId);

            Assert.Equal(currentOrganisationUser, result.Single());
        }
Esempio n. 7
0
        public async Task OrganisationUserExists_AndIsNotCurrentUser_ShouldVerifyAuthorization_BeforeChangingOrgansiationUserStatus(UserStatus userStatus)
        {
            var userId             = Guid.NewGuid();
            var organisationId     = Guid.NewGuid();
            var organisationUserId = Guid.NewGuid();
            var organisationUser   = OrganisationUser(userStatus, organisationId, Guid.NewGuid());

            A.CallTo(() => userContext.UserId)
            .Returns(userId);

            A.CallTo(() => dataAccess.GetOrganisationUser(organisationUserId))
            .Returns(organisationUser);

            await
            UpdateOrganisationUserStatusHandler()
            .HandleAsync(new UpdateOrganisationUserStatus(organisationUserId, userStatus));

            A.CallTo(() => weeeAuthorization.EnsureInternalOrOrganisationAccess(A <Guid> ._))
            .MustHaveHappened(Repeated.Exactly.Once)
            .Then(
                A.CallTo(() => dataAccess.ChangeOrganisationUserStatus(organisationUser, userStatus))
                .MustHaveHappened(Repeated.Exactly.Once));
        }
Esempio n. 8
0
        public async Task OrganisationUserExists_AndIsCurrentUser_ShouldThrowInvalidOperationException(UserStatus userStatus)
        {
            var userId             = Guid.NewGuid();
            var organisationId     = Guid.NewGuid();
            var organisationUserId = Guid.NewGuid();
            var organisationUser   = OrganisationUser(userStatus, organisationId, userId);

            A.CallTo(() => dataAccess.GetOrganisationUser(organisationUserId))
            .Returns(organisationUser);

            A.CallTo(() => userContext.UserId)
            .Returns(userId);

            await Assert.ThrowsAnyAsync <InvalidOperationException>(() => UpdateOrganisationUserStatusHandler()
                                                                    .HandleAsync(new UpdateOrganisationUserStatus(organisationUserId, userStatus)));
        }
Esempio n. 9
0
        public async void GetOrganisationUsers_SameUserRejectedMultipleTimesForOneOrganisation_ButAlsoHasAnotherStatus_ReturnsTheOtherStatus(Core.Shared.UserStatus status)
        {
            using (var dbWrapper = new DatabaseWrapper())
            {
                // Add AspNet user
                var modelHelper = new ModelHelper(dbWrapper.Model);
                var aspNetUser  = modelHelper.CreateUser("My username", IdType.Guid);
                dbWrapper.Model.SaveChanges();

                // Add organisation
                var uniqueOrgName = "Test Org " + Guid.NewGuid();
                var organisation  = Organisation.CreateSoleTrader(uniqueOrgName);
                organisation.CompleteRegistration();
                dbWrapper.WeeeContext.Organisations.Add(organisation);
                dbWrapper.WeeeContext.SaveChanges();

                // Add same organisation user multiple times, rejected
                var rejectedOrganisationUsers = new List <Domain.Organisation.OrganisationUser>
                {
                    new Domain.Organisation.OrganisationUser(Guid.Parse(aspNetUser.Id),
                                                             organisation.Id,
                                                             UserStatus.Rejected),
                    new Domain.Organisation.OrganisationUser(Guid.Parse(aspNetUser.Id),
                                                             organisation.Id,
                                                             UserStatus.Rejected),
                    new Domain.Organisation.OrganisationUser(Guid.Parse(aspNetUser.Id),
                                                             organisation.Id,
                                                             UserStatus.Rejected)
                };

                var otherOrganisationUser = new Domain.Organisation.OrganisationUser(Guid.Parse(aspNetUser.Id),
                                                                                     organisation.Id,
                                                                                     status.ToDomainEnumeration <UserStatus>());

                dbWrapper.WeeeContext.OrganisationUsers.AddRange(rejectedOrganisationUsers);
                dbWrapper.WeeeContext.OrganisationUsers.Add(otherOrganisationUser);
                dbWrapper.WeeeContext.SaveChanges();

                var dataAccess = new FindMatchingUsersDataAccess(dbWrapper.WeeeContext);

                var result = (await dataAccess.GetOrganisationUsers(new UserFilter()))
                             .Where(ou => ou.OrganisationName == uniqueOrgName);

                Assert.Single(result);

                var organisationUser = result.Single();
                Assert.Equal(status, organisationUser.Status);
            }
        }
Esempio n. 10
0
        public async void GetOrganisationUsers_WithStatusFilter_ReturnsFilteredResults(Core.Shared.UserStatus status)
        {
            using (var dbWrapper = new DatabaseWrapper())
            {
                // Add AspNet users
                var modelHelper  = new ModelHelper(dbWrapper.Model);
                var activeUser   = modelHelper.CreateUser(fixture.Create <string>(), IdType.Guid, fixture.Create <string>().Substring(0, 10), fixture.Create <string>().Substring(0, 10));
                var inactiveUser = modelHelper.CreateUser(fixture.Create <string>(), IdType.Guid, fixture.Create <string>().Substring(0, 10), fixture.Create <string>().Substring(0, 10));
                var pendingUser  = modelHelper.CreateUser(fixture.Create <string>(), IdType.Guid, fixture.Create <string>().Substring(0, 10), fixture.Create <string>().Substring(0, 10));
                var rejectedUser = modelHelper.CreateUser(fixture.Create <string>(), IdType.Guid, fixture.Create <string>().Substring(0, 10), fixture.Create <string>().Substring(0, 10));
                dbWrapper.Model.SaveChanges();

                // Add organisation
                var organisationName = fixture.Create <string>();
                var organisation     = Organisation.CreateSoleTrader(organisationName);
                organisation.CompleteRegistration();
                dbWrapper.WeeeContext.Organisations.Add(organisation);
                dbWrapper.WeeeContext.SaveChanges();

                // Add organisation users
                var organisationUsers = new List <Domain.Organisation.OrganisationUser>
                {
                    new Domain.Organisation.OrganisationUser(Guid.Parse(activeUser.Id), organisation.Id, UserStatus.Active),
                    new Domain.Organisation.OrganisationUser(Guid.Parse(inactiveUser.Id), organisation.Id, UserStatus.Inactive),
                    new Domain.Organisation.OrganisationUser(Guid.Parse(pendingUser.Id), organisation.Id, UserStatus.Pending),
                    new Domain.Organisation.OrganisationUser(Guid.Parse(rejectedUser.Id), organisation.Id, UserStatus.Rejected)
                };

                dbWrapper.WeeeContext.OrganisationUsers.AddRange(organisationUsers);
                dbWrapper.WeeeContext.SaveChanges();

                var dataAccess = new FindMatchingUsersDataAccess(dbWrapper.WeeeContext);

                var filter = new UserFilter {
                    Status = status, OrganisationName = organisationName
                };

                var result = await dataAccess.GetOrganisationUsers(filter);

                UserSearchData organisationUser;
                if (status == Core.Shared.UserStatus.Active)
                {
                    Assert.Single(result.Where(r => r.FirstName == activeUser.FirstName));
                    organisationUser = result.Single(r => r.FirstName == activeUser.FirstName);
                }
                else
                {
                    Assert.Single(result);
                    organisationUser = result.Single();
                }

                Assert.Equal(status, organisationUser.Status);
            }
        }
Esempio n. 11
0
        public async void JoinOrganisation_OrganisationUserExistsWithNonRejectedStatus_ReturnsFailure_AndDoesNotSaveAnyChanges(Core.Shared.UserStatus userStatus)
        {
            var organisationId = Guid.NewGuid();
            var userId         = Guid.NewGuid();

            A.CallTo(() => context.OrganisationUsers)
            .Returns(contextHelper.GetAsyncEnabledDbSet(new List <OrganisationUser>
            {
                ValidOrganisationUser(userId, organisationId, userStatus)
            }));

            var result =
                await JoinOrganisationDataAccess()
                .JoinOrganisation(new OrganisationUser(userId, organisationId, UserStatus.Pending));

            Assert.False((result).Successful);

            A.CallTo(() => context.SaveChangesAsync())
            .MustNotHaveHappened();
        }
Esempio n. 12
0
 private OrganisationUser ValidOrganisationUser(Guid userId, Guid organisationId, Core.Shared.UserStatus userStatus)
 {
     return(new OrganisationUser(userId, organisationId, userStatus.ToDomainEnumeration <UserStatus>()));
 }