コード例 #1
0
        public void GetAspUserInfoTest()
        {
            Mock <DbSet <SQLDatabase.EF.aspnet_Users> > moq_aspnetUsers = new Mock <DbSet <SQLDatabase.EF.aspnet_Users> >();

            moq_aspnetUsers.SetupData(new List <SQLDatabase.EF.aspnet_Users>());

            Array.ForEach(db.aspnet_Users
                          .ToArray(), a =>
            {
                if (a.UserId == TestUsers.UserA || a.UserId == TestUsers.UserB || a.UserId == TestUsers.UserC)
                {
                    var nAsp = new SQLDatabase.EF.aspnet_Users();

                    nAsp.ApplicationId    = a.ApplicationId;
                    nAsp.UserName         = a.UserName;
                    nAsp.LoweredUserName  = a.LoweredUserName;
                    nAsp.MobileAlias      = a.MobileAlias;
                    nAsp.IsAnonymous      = a.IsAnonymous;
                    nAsp.LastActivityDate = a.LastActivityDate;
                    nAsp.EULA_Ver         = a.EULA_Ver;
                    nAsp.EULA_Date        = a.EULA_Date;
                    nAsp.UserId           = a.UserId;

                    moq_aspnetUsers.Object.Add(nAsp);
                }
            });

            nuContext.Setup(c => c.aspnet_Users).Returns(moq_aspnetUsers.Object);
            AspnetDbHelpers ah = new AspnetDbHelpers(nuContext.Object);

            // verify user is unique in aspnet_Users table
            var cnt = nuContext.Object.aspnet_Users.Where(a => a.UserId == TestUsers.UserA).ToList();

            Assert.AreEqual(1, cnt.Count);

            var expUser = db.aspnet_Users.Where(t => t.UserId == TestUsers.UserC).FirstOrDefault();
            var retUser = ah.GetAspUserInfo(TestUsers.UserC);

            //verify is null for non-matching user
            Assert.IsNull(ah.GetAspUserInfo(TestUsers.UserFake));

            // verify properties match
            Assert.AreEqual(expUser.ApplicationId, retUser.ApplicationId);
            Assert.AreEqual(expUser.UserName, retUser.UserName);
            Assert.AreEqual(expUser.LoweredUserName, retUser.LoweredUserName);
            Assert.AreEqual(expUser.MobileAlias, retUser.MobileAlias);
            Assert.AreEqual(expUser.IsAnonymous, retUser.IsAnonymous);
            Assert.AreEqual(expUser.LastActivityDate, retUser.LastActivityDate);
            Assert.AreEqual(expUser.EULA_Ver, retUser.EULA_Ver);
            Assert.AreEqual(expUser.EULA_Date, retUser.EULA_Date);
            Assert.AreEqual(expUser.UserId, retUser.UserId);
        }
コード例 #2
0
        public void CreateClinicianMapping()
        {
            try
            {
                var dataSet = aHelper.GetAllAdminsUsers().Where(w => w.CPSiteId == MigrationVariables.CurrentSiteId).ToList();
                RecordCount = dataSet.Count;

                foreach (var adUser in dataSet)
                {
                    var userInfo = aHelper.GetAspUserInfo(adUser.UserId);
                    if (mHelper.HasUserMigrated((userInfo == null) ? String.Empty : userInfo.UserName, adUser.UserId))
                    {
                        MappingStatistics.LogFailedMapping("None", "None", "Clinicians", typeof(Clinician), String.Empty, "Clinician previously migrated.");
                        FailedCount++;
                    }
                    else
                    {
                        var clin = new Clinician
                        {
                            UserId             = nHelper.ValidGuid(adUser.UserId),
                            Firstname          = "No Name",
                            Lastname           = "No Name",
                            StateLicenseNumber = "No License Number",
                            Email                = "",
                            InstitutionId        = nHelper.GetInstitutionId(MigrationVariables.CurrentSiteId),
                            InstitutionAddressId = 0//nHelper.GetInstitutionAddressId(MigrationVariables.CurrentSiteId),
                        };

                        clin.LastUpdatedByUser = clin.UserId;

                        if (CanAddToContext(clin.UserId))
                        {
                            CompletedMappings.Add(clin);
                        }
                        else
                        {
                            MappingStatistics.LogFailedMapping("None", "None", "Clinicians", typeof(Clinician), JsonConvert.SerializeObject(clin), "Clinician already exist in database.");
                            FailedCount++;
                        }
                    }
                }

                MappingStatistics.LogMappingStat("None", 0, "Clinicians", CompletedMappings.Count, FailedCount);
            }
            catch (Exception e)
            {
                throw new Exception("Error creating Clinician mapping.", e);
            }
        }
コード例 #3
0
        public void CreateUserAuthenticationMapping()
        {
            try
            {
                var dataSet = aHelper.GetAllUsers().Where(w => w.CPSiteId.Value == MigrationVariables.CurrentSiteId).ToList();
                RecordCount = dataSet.Count;

                foreach (var adUser in dataSet)
                {
                    aspnet_Membership  member;
                    aspnet_Users       aspUser;
                    UserAuthentication uAuth = null;
                    Guid appId           = nHelper.GetApplicationId("Diabetes Partner");
                    bool isAdmin         = (string.Equals(adUser.CliniProID, "admin", StringComparison.CurrentCultureIgnoreCase)) ? true : false;
                    bool isAdminSiteUser = false;

                    if (isAdmin)
                    {
                        switch (aHelper.GetCorporationName(adUser.CPSiteId))
                        {
                        case "Insulet":
                            appId = nHelper.GetApplicationId("OmniPod Partner");
                            break;

                        case "CliniProWeb":
                            appId = nHelper.GetApplicationId("CliniPro-Web");
                            break;

                        case "NuMedics":
                        default:
                            appId           = nHelper.GetApplicationId("Administration");
                            isAdminSiteUser = true;
                            break;
                        }
                    }

                    member  = aHelper.GetMembershipInfo(adUser.UserId);
                    aspUser = aHelper.GetAspUserInfo(adUser.UserId);

                    if (mHelper.HasUserMigrated(aspUser.UserName, member.UserId))
                    {
                        MappingStatistics.LogFailedMapping("None", "None", "Users", typeof(User), String.Empty, "User previously migrated.");
                        FailedCount++;
                    }
                    else
                    {
                        var userId = nHelper.ValidGuid(adUser.UserId);

                        uAuth = new UserAuthentication
                        {
                            ApplicationId              = appId,
                            UserId                     = userId,
                            Username                   = aspUser.UserName,
                            Password                   = member.Password,
                            PasswordQuestion           = member.PasswordQuestion,
                            PasswordAnswer             = member.PasswordAnswer,
                            PasswordAnswerFailureCount = member.FailedPasswordAnswerAttemptCount,
                            PasswordFailureCount       = member.FailedPasswordAttemptCount,
                            LastActivityDate           = aspUser.LastActivityDate,
                            LastLockOutDate            = member.LastLockoutDate,
                            IsApproved                 = member.IsApproved,
                            IsLockedOut                = member.IsLockedOut,
                            IsTempPassword             = member.IsTemp,
                            IsloggedIn                 = false,
                            LastUpdatedByUser          = userId
                        };

                        var user = new User
                        {
                            UserId            = userId,
                            AssignedUserTypes = new List <AssignedUserType> {
                                new AssignedUserType {
                                    UserId = userId, UserType = (isAdmin) ? (int)UserType.Clinician : (int)UserType.Patient
                                }
                            },
                            //UserType = (isAdmin) ? (int)UserType.Clinician : (int)UserType.Patient,
                            CreationDate = member.CreateDate
                        };

                        if (isAdminSiteUser)
                        {
                            user.AssignedUserTypes.Add(new AssignedUserType {
                                UserId = userId, UserType = (int)UserType.Admin
                            });
                        }

                        user.UserAuthentications.Add(uAuth);

                        // add user info to in-memery collection for use throughout application
                        MemoryMappings.AddPatientInfo(adUser.CPSiteId.Value, adUser.CliniProID, user.UserId);

                        if (CanAddToContext(user.UserId))
                        {
                            CompletedMappings.Add(user);
                        }
                        else
                        {
                            MappingStatistics.LogFailedMapping("None", "None", "Users", typeof(User), JsonConvert.SerializeObject(user), "User already exist in database.");
                            FailedCount++;
                        }
                    }
                }

                MappingStatistics.LogMappingStat("None", 0, "Users", CompletedMappings.Count, FailedCount);
            }
            catch (Exception e)
            {
                throw new Exception("Error creating User mapping.", e);
            }
        }