Beispiel #1
0
        public async void SearchAsync_Works_DataMatches(User user, int skip, int take,
                                                        UserCompare equalityCompare, List <EfRepo.UserRepository> suts,
                                                        SqlRepo.UserRepository sqlUserRepo)
        {
            var searchedEfUsers = new List <User>();

            foreach (var sut in suts)
            {
                var postEfUser = await sut.CreateAsync(user);

                sut.ClearChangeTracking();

                var searchedEfUsersCollection = await sut.SearchAsync(postEfUser.Email.ToUpperInvariant(), skip, take);

                searchedEfUsers.Concat(searchedEfUsersCollection.ToList());
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(user);

            var searchedSqlUsers = await sqlUserRepo.SearchAsync(postSqlUser.Email.ToUpperInvariant(), skip, take);

            var distinctItems = searchedEfUsers.Concat(searchedSqlUsers).Distinct(equalityCompare);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #2
0
        public async void ReplaceAsync_Works_DataMatches(User postUser, User replaceUser,
                                                         UserCompare equalityComparer, List <EfRepo.UserRepository> suts,
                                                         SqlRepo.UserRepository sqlUserRepo)
        {
            var savedUsers = new List <User>();

            foreach (var sut in suts)
            {
                var postEfUser = await sut.CreateAsync(postUser);

                replaceUser.Id = postEfUser.Id;
                await sut.ReplaceAsync(replaceUser);

                var replacedUser = await sut.GetByIdAsync(replaceUser.Id);

                savedUsers.Add(replacedUser);
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(postUser);

            replaceUser.Id = postSqlUser.Id;
            await sqlUserRepo.ReplaceAsync(replaceUser);

            savedUsers.Add(await sqlUserRepo.GetByIdAsync(replaceUser.Id));

            var distinctItems = savedUsers.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #3
0
        public async void UpdateRenewalReminderDateAsync_Works_DataMatches(User user,
                                                                           DateTime updatedReminderDate, List <EfRepo.UserRepository> suts,
                                                                           SqlRepo.UserRepository sqlUserRepo)
        {
            var savedDates = new List <DateTime?>();

            foreach (var sut in suts)
            {
                var postEfUser = user;
                postEfUser = await sut.CreateAsync(user);

                sut.ClearChangeTracking();

                await sut.UpdateRenewalReminderDateAsync(postEfUser.Id, updatedReminderDate);

                sut.ClearChangeTracking();

                var replacedUser = await sut.GetByIdAsync(postEfUser.Id);

                savedDates.Add(replacedUser.RenewalReminderDate);
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(user);

            await sqlUserRepo.UpdateRenewalReminderDateAsync(postSqlUser.Id, updatedReminderDate);

            var replacedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);

            savedDates.Add(replacedSqlUser.RenewalReminderDate);

            var distinctItems = savedDates.GroupBy(e => e.ToString());

            Assert.True(!distinctItems.Skip(1).Any() &&
                        savedDates.All(e => e.ToString() == updatedReminderDate.ToString()));
        }
Beispiel #4
0
        public async void CreateAsync_Works_DataMatches(
            User user, UserCompare equalityComparer,
            List <EfRepo.UserRepository> suts,
            SqlRepo.UserRepository sqlUserRepo
            )
        {
            var savedUsers = new List <User>();

            foreach (var sut in suts)
            {
                var postEfUser = await sut.CreateAsync(user);

                sut.ClearChangeTracking();

                var savedUser = await sut.GetByIdAsync(postEfUser.Id);

                savedUsers.Add(savedUser);
            }

            var sqlUser = await sqlUserRepo.CreateAsync(user);

            savedUsers.Add(await sqlUserRepo.GetByIdAsync(sqlUser.Id));

            var distinctItems = savedUsers.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #5
0
        public async void GetKdfInformationByEmailAsync_Works_DataMatches(User user,
                                                                          UserKdfInformationCompare equalityComparer, List <EfRepo.UserRepository> suts,
                                                                          SqlRepo.UserRepository sqlUserRepo)
        {
            var savedKdfInformation = new List <UserKdfInformation>();

            foreach (var sut in suts)
            {
                var postEfUser = await sut.CreateAsync(user);

                sut.ClearChangeTracking();
                var kdfInformation = await sut.GetKdfInformationByEmailAsync(postEfUser.Email.ToUpperInvariant());

                savedKdfInformation.Add(kdfInformation);
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(user);

            var sqlKdfInformation = await sqlUserRepo.GetKdfInformationByEmailAsync(postSqlUser.Email);

            savedKdfInformation.Add(sqlKdfInformation);

            var distinctItems = savedKdfInformation.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #6
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());
        }
Beispiel #8
0
        public async void CreateAsync_Works_DataMatches(
            EmergencyAccess emergencyAccess,
            List <User> users,
            EmergencyAccessCompare equalityComparer,
            List <EfRepo.EmergencyAccessRepository> suts,
            List <EfRepo.UserRepository> efUserRepos,
            SqlRepo.EmergencyAccessRepository sqlEmergencyAccessRepo,
            SqlRepo.UserRepository sqlUserRepo
            )
        {
            var savedEmergencyAccesss = new List <EmergencyAccess>();

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

                for (int j = 0; j < users.Count; j++)
                {
                    users[j] = await efUserRepos[i].CreateAsync(users[j]);
                }
                sut.ClearChangeTracking();

                emergencyAccess.GrantorId = users[0].Id;
                emergencyAccess.GranteeId = users[0].Id;
                var postEfEmergencyAccess = await sut.CreateAsync(emergencyAccess);

                sut.ClearChangeTracking();

                var savedEmergencyAccess = await sut.GetByIdAsync(postEfEmergencyAccess.Id);

                savedEmergencyAccesss.Add(savedEmergencyAccess);
            }

            for (int j = 0; j < users.Count; j++)
            {
                users[j] = await sqlUserRepo.CreateAsync(users[j]);
            }

            emergencyAccess.GrantorId = users[0].Id;
            emergencyAccess.GranteeId = users[0].Id;
            var sqlEmergencyAccess = await sqlEmergencyAccessRepo.CreateAsync(emergencyAccess);

            var savedSqlEmergencyAccess = await sqlEmergencyAccessRepo.GetByIdAsync(sqlEmergencyAccess.Id);

            savedEmergencyAccesss.Add(savedSqlEmergencyAccess);

            var distinctItems = savedEmergencyAccesss.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #9
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 #10
0
        public async void CreateAsync_Works_DataMatches(
            U2f u2f,
            User user,
            U2fCompare equalityComparer,
            List <EfRepo.U2fRepository> suts,
            List <EfRepo.UserRepository> efUserRepos,
            SqlRepo.U2fRepository sqlU2fRepo,
            SqlRepo.UserRepository sqlUserRepo
            )
        {
            var savedU2fs = new List <U2f>();

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

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

                u2f.UserId = efUser.Id;
                var postEfU2f = await sut.CreateAsync(u2f);

                sut.ClearChangeTracking();

                var savedU2f = await sut.GetByIdAsync(postEfU2f.Id);

                savedU2fs.Add(savedU2f);
            }

            var sqlUser = await sqlUserRepo.CreateAsync(user);

            u2f.UserId = sqlUser.Id;
            var sqlU2f = await sqlU2fRepo.CreateAsync(u2f);

            var savedSqlU2f = await sqlU2fRepo.GetByIdAsync(sqlU2f.Id);

            savedU2fs.Add(savedSqlU2f);

            var distinctItems = savedU2fs.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #11
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());
        }
Beispiel #12
0
        public async void CreateAsync_Works_DataMatches(Device device, User user,
                                                        DeviceCompare equalityComparer, List <EfRepo.DeviceRepository> suts,
                                                        List <EfRepo.UserRepository> efUserRepos, SqlRepo.DeviceRepository sqlDeviceRepo,
                                                        SqlRepo.UserRepository sqlUserRepo)
        {
            var savedDevices = new List <Device>();

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

                var efUser = await efUserRepos[i].CreateAsync(user);
                device.UserId = efUser.Id;
                sut.ClearChangeTracking();

                var postEfDevice = await sut.CreateAsync(device);

                sut.ClearChangeTracking();

                var savedDevice = await sut.GetByIdAsync(postEfDevice.Id);

                savedDevices.Add(savedDevice);
            }

            var sqlUser = await sqlUserRepo.CreateAsync(user);

            device.UserId = sqlUser.Id;

            var sqlDevice = await sqlDeviceRepo.CreateAsync(device);

            var savedSqlDevice = await sqlDeviceRepo.GetByIdAsync(sqlDevice.Id);

            savedDevices.Add(savedSqlDevice);

            var distinctItems = savedDevices.Distinct(equalityComparer);

            Assert.True(!distinctItems.Skip(1).Any());
        }
Beispiel #13
0
        public async void GetAccountRevisionDateAsync(User user, List <EfRepo.UserRepository> suts,
                                                      SqlRepo.UserRepository sqlUserRepo)
        {
            var returnedKeys = new List <string>();

            foreach (var sut in suts)
            {
                var postEfUser = await sut.CreateAsync(user);

                sut.ClearChangeTracking();

                var efKey = await sut.GetPublicKeyAsync(postEfUser.Id);

                returnedKeys.Add(efKey);
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(user);

            var sqlKey = await sqlUserRepo.GetPublicKeyAsync(postSqlUser.Id);

            returnedKeys.Add(sqlKey);

            Assert.True(!returnedKeys.Distinct().Skip(1).Any());
        }
Beispiel #14
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 #15
0
        public async void CreateAsync_BumpsUserAccountRevisionDate(Cipher cipher, User user,
                                                                   CipherCompare equalityComparer, List <EfRepo.CipherRepository> suts, List <EfRepo.UserRepository> efUserRepos,
                                                                   SqlRepo.CipherRepository sqlCipherRepo, SqlRepo.UserRepository sqlUserRepo)
        {
            var bumpedUsers = new List <User>();

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

                var efUser = await efUserRepos[i].CreateAsync(user);
                efUserRepos[i].ClearChangeTracking();
                cipher.UserId         = efUser.Id;
                cipher.OrganizationId = null;

                var postEfCipher = await sut.CreateAsync(cipher);

                sut.ClearChangeTracking();

                var bumpedUser = await efUserRepos[i].GetByIdAsync(efUser.Id);
                bumpedUsers.Add(bumpedUser);
            }

            Assert.True(bumpedUsers.All(u => u.AccountRevisionDate.ToShortDateString() == DateTime.UtcNow.ToShortDateString()));
        }
Beispiel #16
0
        public async void GetManyByPremiumAsync_Works_DataMatches(User user,
                                                                  List <EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
        {
            var returnedUsers = new List <User>();

            foreach (var sut in suts)
            {
                var postEfUser = await sut.CreateAsync(user);

                sut.ClearChangeTracking();

                var searchedEfUsers = await sut.GetManyByPremiumAsync(user.Premium);

                returnedUsers.Concat(searchedEfUsers.ToList());
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(user);

            var searchedSqlUsers = await sqlUserRepo.GetManyByPremiumAsync(user.Premium);

            returnedUsers.Concat(searchedSqlUsers.ToList());

            Assert.True(returnedUsers.All(x => x.Premium == user.Premium));
        }
Beispiel #17
0
        public async void DeleteAsync_Works_DataMatches(User user, UserCompare equalityComparer,
                                                        List <EfRepo.UserRepository> suts, SqlRepo.UserRepository sqlUserRepo)
        {
            foreach (var sut in suts)
            {
                var postEfUser = await sut.CreateAsync(user);

                sut.ClearChangeTracking();

                var savedEfUser = await sut.GetByIdAsync(postEfUser.Id);

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

                await sut.DeleteAsync(savedEfUser);

                sut.ClearChangeTracking();

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

                Assert.True(savedEfUser == null);
            }

            var postSqlUser = await sqlUserRepo.CreateAsync(user);

            var savedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);

            Assert.True(savedSqlUser != null);

            await sqlUserRepo.DeleteAsync(postSqlUser);

            savedSqlUser = await sqlUserRepo.GetByIdAsync(postSqlUser.Id);

            Assert.True(savedSqlUser == null);
        }
        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);
        }