Beispiel #1
0
        public async void CreateAsync_Works_DataMatches(
            TableModel.Organization organization,
            SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
            List <EfRepo.OrganizationRepository> suts)
        {
            var savedOrganizations = new List <TableModel.Organization>();

            foreach (var sut in suts)
            {
                var postEfOrganization = await sut.CreateAsync(organization);

                sut.ClearChangeTracking();

                var savedOrganization = await sut.GetByIdAsync(organization.Id);

                savedOrganizations.Add(savedOrganization);
            }

            var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);

            savedOrganizations.Add(await sqlOrganizationRepo.GetByIdAsync(sqlOrganization.Id));

            var distinctItems = savedOrganizations.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #2
0
        public async void GetByIdentifierAsync_Works_DataMatches(TableModel.Organization organization,
                                                                 SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
                                                                 List <EfRepo.OrganizationRepository> suts)
        {
            var returnedOrgs = new List <TableModel.Organization>();

            foreach (var sut in suts)
            {
                var postEfOrg = await sut.CreateAsync(organization);

                sut.ClearChangeTracking();

                var returnedOrg = await sut.GetByIdentifierAsync(postEfOrg.Identifier.ToUpperInvariant());

                returnedOrgs.Add(returnedOrg);
            }

            var postSqlOrg = await sqlOrganizationRepo.CreateAsync(organization);

            returnedOrgs.Add(await sqlOrganizationRepo.GetByIdentifierAsync(postSqlOrg.Identifier.ToUpperInvariant()));

            var distinctItems = returnedOrgs.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #3
0
        public async void CreateAsync_Works_DataMatches(
            Send send,
            User user,
            Organization org,
            SendCompare equalityComparer,
            List <EfRepo.SendRepository> suts,
            List <EfRepo.UserRepository> efUserRepos,
            List <EfRepo.OrganizationRepository> efOrgRepos,
            SqlRepo.SendRepository sqlSendRepo,
            SqlRepo.UserRepository sqlUserRepo,
            SqlRepo.OrganizationRepository sqlOrgRepo
            )
        {
            var savedSends = new List <Send>();

            foreach (var sut in suts)
            {
                var i = suts.IndexOf(sut);

                if (send.OrganizationId.HasValue)
                {
                    var efOrg = await efOrgRepos[i].CreateAsync(org);
                    sut.ClearChangeTracking();
                    send.OrganizationId = efOrg.Id;
                }
                var efUser = await efUserRepos[i].CreateAsync(user);
                sut.ClearChangeTracking();

                send.UserId = efUser.Id;
                var postEfSend = await sut.CreateAsync(send);

                sut.ClearChangeTracking();

                var savedSend = await sut.GetByIdAsync(postEfSend.Id);

                savedSends.Add(savedSend);
            }

            var sqlUser = await sqlUserRepo.CreateAsync(user);

            if (send.OrganizationId.HasValue)
            {
                var sqlOrg = await sqlOrgRepo.CreateAsync(org);

                send.OrganizationId = sqlOrg.Id;
            }

            send.UserId = sqlUser.Id;
            var sqlSend = await sqlSendRepo.CreateAsync(send);

            var savedSqlSend = await sqlSendRepo.GetByIdAsync(sqlSend.Id);

            savedSends.Add(savedSqlSend);

            var distinctItems = savedSends.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
        public async void ReplaceAsync_Works_DataMatches(
            TableModel.OrganizationUser postOrgUser,
            TableModel.OrganizationUser replaceOrgUser,
            TableModel.User user,
            TableModel.Organization org,
            OrganizationUserCompare equalityComparer,
            List <EfRepo.OrganizationUserRepository> suts,
            List <EfRepo.UserRepository> efUserRepos,
            List <EfRepo.OrganizationRepository> efOrgRepos,
            SqlRepo.OrganizationUserRepository sqlOrgUserRepo,
            SqlRepo.UserRepository sqlUserRepo,
            SqlRepo.OrganizationRepository sqlOrgRepo
            )
        {
            var savedOrgUsers = new List <TableModel.OrganizationUser>();

            foreach (var sut in suts)
            {
                var i          = suts.IndexOf(sut);
                var postEfUser = await efUserRepos[i].CreateAsync(user);
                var postEfOrg  = await efOrgRepos[i].CreateAsync(org);
                sut.ClearChangeTracking();

                postOrgUser.UserId         = replaceOrgUser.UserId = postEfUser.Id;
                postOrgUser.OrganizationId = replaceOrgUser.OrganizationId = postEfOrg.Id;
                var postEfOrgUser = await sut.CreateAsync(postOrgUser);

                sut.ClearChangeTracking();

                replaceOrgUser.Id = postOrgUser.Id;
                await sut.ReplaceAsync(replaceOrgUser);

                sut.ClearChangeTracking();

                var replacedOrganizationUser = await sut.GetByIdAsync(replaceOrgUser.Id);

                savedOrgUsers.Add(replacedOrganizationUser);
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(user);

            var postSqlOrg = await sqlOrgRepo.CreateAsync(org);

            postOrgUser.UserId         = replaceOrgUser.UserId = postSqlUser.Id;
            postOrgUser.OrganizationId = replaceOrgUser.OrganizationId = postSqlOrg.Id;
            var postSqlOrgUser = await sqlOrgUserRepo.CreateAsync(postOrgUser);

            replaceOrgUser.Id = postSqlOrgUser.Id;
            await sqlOrgUserRepo.ReplaceAsync(replaceOrgUser);

            var replacedSqlUser = await sqlOrgUserRepo.GetByIdAsync(replaceOrgUser.Id);

            var distinctItems = savedOrgUsers.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
        public async void ReplaceAsync_Works_DataMatches(TableModel.OrganizationSponsorship postOrganizationSponsorship,
                                                         TableModel.OrganizationSponsorship replaceOrganizationSponsorship, TableModel.Organization sponsoringOrg,
                                                         List <EfRepo.OrganizationRepository> efOrgRepos,
                                                         SqlRepo.OrganizationRepository sqlOrganizationRepo,
                                                         SqlRepo.OrganizationSponsorshipRepository sqlOrganizationSponsorshipRepo,
                                                         OrganizationSponsorshipCompare equalityComparer, List <EfRepo.OrganizationSponsorshipRepository> suts)
        {
            postOrganizationSponsorship.InstallationId             = null;
            postOrganizationSponsorship.SponsoredOrganizationId    = null;
            replaceOrganizationSponsorship.InstallationId          = null;
            replaceOrganizationSponsorship.SponsoredOrganizationId = null;

            var savedOrganizationSponsorships = new List <TableModel.OrganizationSponsorship>();

            foreach (var(sut, orgRepo) in suts.Zip(efOrgRepos))
            {
                var efSponsoringOrg = await orgRepo.CreateAsync(sponsoringOrg);

                sut.ClearChangeTracking();
                postOrganizationSponsorship.SponsoringOrganizationId    = efSponsoringOrg.Id;
                replaceOrganizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;

                var postEfOrganizationSponsorship = await sut.CreateAsync(postOrganizationSponsorship);

                sut.ClearChangeTracking();

                replaceOrganizationSponsorship.Id = postEfOrganizationSponsorship.Id;
                await sut.ReplaceAsync(replaceOrganizationSponsorship);

                sut.ClearChangeTracking();

                var replacedOrganizationSponsorship = await sut.GetByIdAsync(replaceOrganizationSponsorship.Id);

                savedOrganizationSponsorships.Add(replacedOrganizationSponsorship);
            }

            var sqlSponsoringOrg = await sqlOrganizationRepo.CreateAsync(sponsoringOrg);

            postOrganizationSponsorship.SponsoringOrganizationId = sqlSponsoringOrg.Id;

            var postSqlOrganization = await sqlOrganizationSponsorshipRepo.CreateAsync(postOrganizationSponsorship);

            replaceOrganizationSponsorship.Id = postSqlOrganization.Id;
            await sqlOrganizationSponsorshipRepo.ReplaceAsync(replaceOrganizationSponsorship);

            savedOrganizationSponsorships.Add(await sqlOrganizationSponsorshipRepo.GetByIdAsync(replaceOrganizationSponsorship.Id));

            var distinctItems = savedOrganizationSponsorships.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
        public async void DeleteAsync_Works_DataMatches(TableModel.OrganizationSponsorship organizationSponsorship,
                                                        TableModel.Organization sponsoringOrg,
                                                        List <EfRepo.OrganizationRepository> efOrgRepos,
                                                        SqlRepo.OrganizationRepository sqlOrganizationRepo,
                                                        SqlRepo.OrganizationSponsorshipRepository sqlOrganizationSponsorshipRepo,
                                                        List <EfRepo.OrganizationSponsorshipRepository> suts)
        {
            organizationSponsorship.InstallationId          = null;
            organizationSponsorship.SponsoredOrganizationId = null;

            foreach (var(sut, orgRepo) in suts.Zip(efOrgRepos))
            {
                var efSponsoringOrg = await orgRepo.CreateAsync(sponsoringOrg);

                sut.ClearChangeTracking();
                organizationSponsorship.SponsoringOrganizationId = efSponsoringOrg.Id;

                var postEfOrganizationSponsorship = await sut.CreateAsync(organizationSponsorship);

                sut.ClearChangeTracking();

                var savedEfOrganizationSponsorship = await sut.GetByIdAsync(postEfOrganizationSponsorship.Id);

                sut.ClearChangeTracking();
                Assert.True(savedEfOrganizationSponsorship != null);

                await sut.DeleteAsync(savedEfOrganizationSponsorship);

                sut.ClearChangeTracking();

                savedEfOrganizationSponsorship = await sut.GetByIdAsync(savedEfOrganizationSponsorship.Id);

                Assert.True(savedEfOrganizationSponsorship == null);
            }

            var sqlSponsoringOrg = await sqlOrganizationRepo.CreateAsync(sponsoringOrg);

            organizationSponsorship.SponsoringOrganizationId = sqlSponsoringOrg.Id;

            var postSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.CreateAsync(organizationSponsorship);

            var savedSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.GetByIdAsync(postSqlOrganizationSponsorship.Id);

            Assert.True(savedSqlOrganizationSponsorship != null);

            await sqlOrganizationSponsorshipRepo.DeleteAsync(postSqlOrganizationSponsorship);

            savedSqlOrganizationSponsorship = await sqlOrganizationSponsorshipRepo.GetByIdAsync(postSqlOrganizationSponsorship.Id);

            Assert.True(savedSqlOrganizationSponsorship == null);
        }
Beispiel #7
0
        public async void ReplaceAsync_Works_DataMatches(SsoConfig postSsoConfig, SsoConfig replaceSsoConfig,
                                                         Organization org, SsoConfigCompare equalityComparer, List <EfRepo.SsoConfigRepository> suts,
                                                         List <EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
                                                         SqlRepo.OrganizationRepository sqlOrganizationRepo)
        {
            var savedSsoConfigs = new List <SsoConfig>();

            foreach (var sut in suts)
            {
                var i = suts.IndexOf(sut);

                var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
                sut.ClearChangeTracking();

                postSsoConfig.OrganizationId = replaceSsoConfig.OrganizationId = savedEfOrg.Id;
                var postEfSsoConfig = await sut.CreateAsync(postSsoConfig);

                sut.ClearChangeTracking();

                replaceSsoConfig.Id = postEfSsoConfig.Id;
                savedSsoConfigs.Add(postEfSsoConfig);
                await sut.ReplaceAsync(replaceSsoConfig);

                sut.ClearChangeTracking();

                var replacedSsoConfig = await sut.GetByIdAsync(replaceSsoConfig.Id);

                Assert.True(replacedSsoConfig != null);
                savedSsoConfigs.Add(replacedSsoConfig);
            }

            var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);

            postSsoConfig.OrganizationId = sqlOrganization.Id;

            var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(postSsoConfig);

            replaceSsoConfig.Id = postSqlSsoConfig.Id;
            savedSsoConfigs.Add(postSqlSsoConfig);

            await sqlSsoConfigRepo.ReplaceAsync(replaceSsoConfig);

            var replacedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(replaceSsoConfig.Id);

            Assert.True(replacedSqlSsoConfig != null);
            savedSsoConfigs.Add(replacedSqlSsoConfig);

            var distinctItems = savedSsoConfigs.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(2).Any());
        }
        public async void DeleteAsync_Works_DataMatches(TableModel.OrganizationUser orgUser, TableModel.User user, TableModel.Organization org,
                                                        OrganizationUserCompare equalityComparer, List <EfRepo.OrganizationUserRepository> suts,
                                                        List <EfRepo.UserRepository> efUserRepos, List <EfRepo.OrganizationRepository> efOrgRepos,
                                                        SqlRepo.OrganizationUserRepository sqlOrgUserRepo, SqlRepo.UserRepository sqlUserRepo,
                                                        SqlRepo.OrganizationRepository sqlOrgRepo)
        {
            foreach (var sut in suts)
            {
                var i          = suts.IndexOf(sut);
                var postEfUser = await efUserRepos[i].CreateAsync(user);
                var postEfOrg  = await efOrgRepos[i].CreateAsync(org);
                sut.ClearChangeTracking();

                orgUser.UserId         = postEfUser.Id;
                orgUser.OrganizationId = postEfOrg.Id;
                var postEfOrgUser = await sut.CreateAsync(orgUser);

                sut.ClearChangeTracking();

                var savedEfOrgUser = await sut.GetByIdAsync(postEfOrgUser.Id);

                Assert.True(savedEfOrgUser != null);
                sut.ClearChangeTracking();

                await sut.DeleteAsync(savedEfOrgUser);

                sut.ClearChangeTracking();

                savedEfOrgUser = await sut.GetByIdAsync(savedEfOrgUser.Id);

                Assert.True(savedEfOrgUser == null);
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(user);

            var postSqlOrg = await sqlOrgRepo.CreateAsync(org);

            orgUser.UserId         = postSqlUser.Id;
            orgUser.OrganizationId = postSqlOrg.Id;
            var postSqlOrgUser = await sqlOrgUserRepo.CreateAsync(orgUser);

            var savedSqlOrgUser = await sqlOrgUserRepo.GetByIdAsync(postSqlOrgUser.Id);

            Assert.True(savedSqlOrgUser != null);

            await sqlOrgUserRepo.DeleteAsync(postSqlOrgUser);

            savedSqlOrgUser = await sqlOrgUserRepo.GetByIdAsync(postSqlOrgUser.Id);

            Assert.True(savedSqlOrgUser == null);
        }
Beispiel #9
0
        public async void GetManyAbilitiesAsync_Works(TableModel.Organization organization,
                                                      SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
                                                      List <EfRepo.OrganizationRepository> suts)
        {
            var list = new List <OrganizationAbility>();

            foreach (var sut in suts)
            {
                list.Concat(await sut.GetManyAbilitiesAsync());
            }

            list.Concat(await sqlOrganizationRepo.GetManyAbilitiesAsync());
            Assert.True(list.All(x => x.GetType() == typeof(OrganizationAbility)));
        }
Beispiel #10
0
        public async void GetBySsoUserAsync_Works_DataMatches(User user, Organization org,
                                                              SsoUser ssoUser, UserCompare equalityComparer, List <EfRepo.UserRepository> suts,
                                                              List <EfRepo.SsoUserRepository> ssoUserRepos, List <EfRepo.OrganizationRepository> orgRepos,
                                                              SqlRepo.UserRepository sqlUserRepo, SqlRepo.SsoUserRepository sqlSsoUserRepo,
                                                              SqlRepo.OrganizationRepository sqlOrgRepo)
        {
            var returnedList = new List <User>();

            foreach (var sut in suts)
            {
                var i = suts.IndexOf(sut);

                var postEfUser = await sut.CreateAsync(user);

                sut.ClearChangeTracking();

                var efOrg = await orgRepos[i].CreateAsync(org);
                sut.ClearChangeTracking();

                ssoUser.UserId         = postEfUser.Id;
                ssoUser.OrganizationId = efOrg.Id;
                var postEfSsoUser = await ssoUserRepos[i].CreateAsync(ssoUser);
                sut.ClearChangeTracking();

                var returnedUser = await sut.GetBySsoUserAsync(postEfSsoUser.ExternalId.ToUpperInvariant(), efOrg.Id);

                returnedList.Add(returnedUser);
            }

            var sqlUser = await sqlUserRepo.CreateAsync(user);

            var sqlOrganization = await sqlOrgRepo.CreateAsync(org);

            ssoUser.UserId         = sqlUser.Id;
            ssoUser.OrganizationId = sqlOrganization.Id;
            var postSqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);

            var returnedSqlUser = await sqlUserRepo
                                  .GetBySsoUserAsync(postSqlSsoUser.ExternalId, sqlOrganization.Id);

            returnedList.Add(returnedSqlUser);

            var distinctItems = returnedList.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #11
0
        public async void DeleteAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
                                                        SsoConfigCompare equalityComparer, List <EfRepo.SsoConfigRepository> suts,
                                                        List <EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
                                                        SqlRepo.OrganizationRepository sqlOrganizationRepo)
        {
            foreach (var sut in suts)
            {
                var i = suts.IndexOf(sut);

                var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
                sut.ClearChangeTracking();

                ssoConfig.OrganizationId = savedEfOrg.Id;
                var postEfSsoConfig = await sut.CreateAsync(ssoConfig);

                sut.ClearChangeTracking();

                var savedEfSsoConfig = await sut.GetByIdAsync(postEfSsoConfig.Id);

                Assert.True(savedEfSsoConfig != null);
                sut.ClearChangeTracking();

                await sut.DeleteAsync(savedEfSsoConfig);

                var deletedEfSsoConfig = await sut.GetByIdAsync(savedEfSsoConfig.Id);

                Assert.True(deletedEfSsoConfig == null);
            }

            var sqlOrganization = await sqlOrganizationRepo.CreateAsync(org);

            ssoConfig.OrganizationId = sqlOrganization.Id;

            var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);

            var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(postSqlSsoConfig.Id);

            Assert.True(savedSqlSsoConfig != null);

            await sqlSsoConfigRepo.DeleteAsync(savedSqlSsoConfig);

            savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdAsync(postSqlSsoConfig.Id);

            Assert.True(savedSqlSsoConfig == null);
        }
Beispiel #12
0
        public async void CreateAsync_Works_DataMatches(
            TableModel.Policy policy,
            TableModel.Organization organization,
            PolicyCompare equalityComparer,
            List <EfRepo.PolicyRepository> suts,
            List <EfRepo.OrganizationRepository> efOrganizationRepos,
            SqlRepo.PolicyRepository sqlPolicyRepo,
            SqlRepo.OrganizationRepository sqlOrganizationRepo
            )
        {
            var savedPolicys = new List <TableModel.Policy>();

            foreach (var sut in suts)
            {
                var i = suts.IndexOf(sut);

                var efOrganization = await efOrganizationRepos[i].CreateAsync(organization);
                sut.ClearChangeTracking();

                policy.OrganizationId = efOrganization.Id;
                var postEfPolicy = await sut.CreateAsync(policy);

                sut.ClearChangeTracking();

                var savedPolicy = await sut.GetByIdAsync(postEfPolicy.Id);

                savedPolicys.Add(savedPolicy);
            }

            var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);

            policy.OrganizationId = sqlOrganization.Id;
            var sqlPolicy = await sqlPolicyRepo.CreateAsync(policy);

            var savedSqlPolicy = await sqlPolicyRepo.GetByIdAsync(sqlPolicy.Id);

            savedPolicys.Add(savedSqlPolicy);

            var distinctItems = savedPolicys.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #13
0
        public async void CreateAsync_Works_DataMatches(
            Collection collection,
            Organization organization,
            CollectionCompare equalityComparer,
            List <EfRepo.CollectionRepository> suts,
            List <EfRepo.OrganizationRepository> efOrganizationRepos,
            SqlRepo.CollectionRepository sqlCollectionRepo,
            SqlRepo.OrganizationRepository sqlOrganizationRepo
            )
        {
            var savedCollections = new List <Collection>();

            foreach (var sut in suts)
            {
                var i = suts.IndexOf(sut);
                var efOrganization = await efOrganizationRepos[i].CreateAsync(organization);
                sut.ClearChangeTracking();

                collection.OrganizationId = efOrganization.Id;
                var postEfCollection = await sut.CreateAsync(collection);

                sut.ClearChangeTracking();

                var savedCollection = await sut.GetByIdAsync(postEfCollection.Id);

                savedCollections.Add(savedCollection);
            }

            var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);

            collection.OrganizationId = sqlOrganization.Id;

            var sqlCollection = await sqlCollectionRepo.CreateAsync(collection);

            var savedSqlCollection = await sqlCollectionRepo.GetByIdAsync(sqlCollection.Id);

            savedCollections.Add(savedSqlCollection);

            var distinctItems = savedCollections.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #14
0
        public async void GetByIdentifierAsync_Works_DataMatches(SsoConfig ssoConfig, Organization org,
                                                                 SsoConfigCompare equalityComparer, List <EfRepo.SsoConfigRepository> suts,
                                                                 List <EfRepo.OrganizationRepository> efOrgRepos, SqlRepo.SsoConfigRepository sqlSsoConfigRepo,
                                                                 SqlRepo.OrganizationRepository sqlOrgRepo)
        {
            var returnedList = new List <SsoConfig>();

            foreach (var sut in suts)
            {
                var i = suts.IndexOf(sut);

                var savedEfOrg = await efOrgRepos[i].CreateAsync(org);
                sut.ClearChangeTracking();

                ssoConfig.OrganizationId = savedEfOrg.Id;
                await sut.CreateAsync(ssoConfig);

                sut.ClearChangeTracking();

                var savedEfSsoConfig = await sut.GetByIdentifierAsync(org.Identifier);

                Assert.True(savedEfSsoConfig != null);
                returnedList.Add(savedEfSsoConfig);
            }

            var savedSqlOrg = await sqlOrgRepo.CreateAsync(org);

            ssoConfig.OrganizationId = savedSqlOrg.Id;

            var postSqlSsoConfig = await sqlSsoConfigRepo.CreateAsync(ssoConfig);

            var savedSqlSsoConfig = await sqlSsoConfigRepo.GetByIdentifierAsync(org.Identifier);

            Assert.True(savedSqlSsoConfig != null);
            returnedList.Add(savedSqlSsoConfig);

            var distinctItems = returnedList.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #15
0
        public async void GetManyByEnabledAsync_Works_DataMatches(TableModel.Organization organization,
                                                                  SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityCompare,
                                                                  List <EfRepo.OrganizationRepository> suts)
        {
            var returnedOrgs = new List <TableModel.Organization>();

            foreach (var sut in suts)
            {
                var postEfOrg = await sut.CreateAsync(organization);

                sut.ClearChangeTracking();

                var efReturnedOrgs = await sut.GetManyByEnabledAsync();

                returnedOrgs.Concat(efReturnedOrgs);
            }

            var postSqlOrg = await sqlOrganizationRepo.CreateAsync(organization);

            returnedOrgs.Concat(await sqlOrganizationRepo.GetManyByEnabledAsync());

            Assert.True(returnedOrgs.All(o => o.Enabled));
        }
Beispiel #16
0
        public async void DeleteAsync_Works_DataMatches(TableModel.Organization organization,
                                                        SqlRepo.OrganizationRepository sqlOrganizationRepo, OrganizationCompare equalityComparer,
                                                        List <EfRepo.OrganizationRepository> suts)
        {
            foreach (var sut in suts)
            {
                var postEfOrganization = await sut.CreateAsync(organization);

                sut.ClearChangeTracking();

                var savedEfOrganization = await sut.GetByIdAsync(postEfOrganization.Id);

                sut.ClearChangeTracking();
                Assert.True(savedEfOrganization != null);

                await sut.DeleteAsync(savedEfOrganization);

                sut.ClearChangeTracking();

                savedEfOrganization = await sut.GetByIdAsync(savedEfOrganization.Id);

                Assert.True(savedEfOrganization == null);
            }

            var postSqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);

            var savedSqlOrganization = await sqlOrganizationRepo.GetByIdAsync(postSqlOrganization.Id);

            Assert.True(savedSqlOrganization != null);

            await sqlOrganizationRepo.DeleteAsync(postSqlOrganization);

            savedSqlOrganization = await sqlOrganizationRepo.GetByIdAsync(postSqlOrganization.Id);

            Assert.True(savedSqlOrganization == null);
        }
Beispiel #17
0
        [EfPolicyApplicableToUserInlineAutoData(OrganizationUserType.User, false, OrganizationUserStatusType.Invited, true, true, false)]        // User not minStatus
        public async void GetManyByTypeApplicableToUser_Works_DataMatches_Corre(
            // Inline data
            OrganizationUserType userType,
            bool canManagePolicies,
            OrganizationUserStatusType orgUserStatus,
            bool policyEnabled,
            bool policySameType,
            bool isProvider,

            // Auto data - models
            TableModel.Policy policy,
            TableModel.User user,
            TableModel.Organization organization,
            TableModel.OrganizationUser orgUser,
            TableModel.Provider.Provider provider,
            TableModel.Provider.ProviderOrganization providerOrganization,
            TableModel.Provider.ProviderUser providerUser,
            PolicyCompareIncludingOrganization equalityComparer,

            // Auto data - EF repos
            List <EfRepo.PolicyRepository> suts,
            List <EfRepo.UserRepository> efUserRepository,
            List <EfRepo.OrganizationRepository> efOrganizationRepository,
            List <EfRepo.OrganizationUserRepository> efOrganizationUserRepository,
            List <EfRepo.ProviderRepository> efProviderRepository,
            List <EfRepo.ProviderOrganizationRepository> efProviderOrganizationRepository,
            List <EfRepo.ProviderUserRepository> efProviderUserRepository,

            // Auto data - SQL repos
            SqlRepo.PolicyRepository sqlPolicyRepo,
            SqlRepo.UserRepository sqlUserRepo,
            SqlRepo.OrganizationRepository sqlOrganizationRepo,
            SqlRepo.ProviderRepository sqlProviderRepo,
            SqlRepo.OrganizationUserRepository sqlOrganizationUserRepo,
            SqlRepo.ProviderOrganizationRepository sqlProviderOrganizationRepo,
            SqlRepo.ProviderUserRepository sqlProviderUserRepo
            )
        {
            // Combine EF and SQL repos into one list per type
            var policyRepos = suts.ToList <IPolicyRepository>();

            policyRepos.Add(sqlPolicyRepo);
            var userRepos = efUserRepository.ToList <IUserRepository>();

            userRepos.Add(sqlUserRepo);
            var orgRepos = efOrganizationRepository.ToList <IOrganizationRepository>();

            orgRepos.Add(sqlOrganizationRepo);
            var orgUserRepos = efOrganizationUserRepository.ToList <IOrganizationUserRepository>();

            orgUserRepos.Add(sqlOrganizationUserRepo);
            var providerRepos = efProviderRepository.ToList <IProviderRepository>();

            providerRepos.Add(sqlProviderRepo);
            var providerOrgRepos = efProviderOrganizationRepository.ToList <IProviderOrganizationRepository>();

            providerOrgRepos.Add(sqlProviderOrganizationRepo);
            var providerUserRepos = efProviderUserRepository.ToList <IProviderUserRepository>();

            providerUserRepos.Add(sqlProviderUserRepo);

            // Arrange data
            var savedPolicyType   = PolicyType.SingleOrg;
            var queriedPolicyType = policySameType ? savedPolicyType : PolicyType.DisableSend;

            orgUser.Type   = userType;
            orgUser.Status = orgUserStatus;
            var permissionsData = new Permissions {
                ManagePolicies = canManagePolicies
            };

            orgUser.Permissions = JsonSerializer.Serialize(permissionsData, new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            });

            policy.Enabled = policyEnabled;
            policy.Type    = savedPolicyType;

            var results = new List <TableModel.Policy>();

            foreach (var policyRepo in policyRepos)
            {
                var i = policyRepos.IndexOf(policyRepo);

                // Seed database
                var savedUser = await userRepos[i].CreateAsync(user);
                var savedOrg  = await orgRepos[i].CreateAsync(organization);

                orgUser.UserId         = savedUser.Id;
                orgUser.OrganizationId = savedOrg.Id;
                await orgUserRepos[i].CreateAsync(orgUser);

                if (isProvider)
                {
                    var savedProvider = await providerRepos[i].CreateAsync(provider);

                    providerOrganization.OrganizationId = savedOrg.Id;
                    providerOrganization.ProviderId     = savedProvider.Id;
                    await providerOrgRepos[i].CreateAsync(providerOrganization);

                    providerUser.UserId     = savedUser.Id;
                    providerUser.ProviderId = savedProvider.Id;
                    await providerUserRepos[i].CreateAsync(providerUser);
                }

                policy.OrganizationId = savedOrg.Id;
                await policyRepo.CreateAsync(policy);

                if (suts.Contains(policyRepo))
                {
                    (policyRepo as BaseEntityFrameworkRepository).ClearChangeTracking();
                }

                // Act
                var result = await policyRepo.GetManyByTypeApplicableToUserIdAsync(savedUser.Id, queriedPolicyType, OrganizationUserStatusType.Accepted);

                results.Add(result.FirstOrDefault());
            }

            // Assert
            var distinctItems = results.Distinct(equalityComparer);

            Assert.True(results.All(r => r == null) ||
                        !distinctItems.Skip(1).Any());
        }
Beispiel #18
0
        public async void CreateAsync_Works_DataMatches(SsoUser ssoUser, User user, Organization org,
                                                        SsoUserCompare equalityComparer, List <EfRepo.SsoUserRepository> suts,
                                                        List <EfRepo.OrganizationRepository> efOrgRepos, List <EfRepo.UserRepository> efUserRepos,
                                                        SqlRepo.SsoUserRepository sqlSsoUserRepo, SqlRepo.OrganizationRepository sqlOrgRepo,
                                                        SqlRepo.UserRepository sqlUserRepo)
        {
            var createdSsoUsers = new List <SsoUser>();

            foreach (var sut in suts)
            {
                var i = suts.IndexOf(sut);

                var efUser = await efUserRepos[i].CreateAsync(user);
                var efOrg  = await efOrgRepos[i].CreateAsync(org);
                sut.ClearChangeTracking();

                ssoUser.UserId         = efUser.Id;
                ssoUser.OrganizationId = efOrg.Id;
                var postEfSsoUser = await sut.CreateAsync(ssoUser);

                sut.ClearChangeTracking();

                var savedSsoUser = await sut.GetByIdAsync(ssoUser.Id);

                createdSsoUsers.Add(savedSsoUser);
            }

            var sqlUser = await sqlUserRepo.CreateAsync(user);

            var sqlOrganization = await sqlOrgRepo.CreateAsync(org);

            ssoUser.UserId         = sqlUser.Id;
            ssoUser.OrganizationId = sqlOrganization.Id;
            var sqlSsoUser = await sqlSsoUserRepo.CreateAsync(ssoUser);

            createdSsoUsers.Add(await sqlSsoUserRepo.GetByIdAsync(sqlSsoUser.Id));

            var distinctSsoUsers = createdSsoUsers.Distinct(equalityComparer);

            Assert.True(!distinctSsoUsers.Skip(1).Any());
        }