Esempio n. 1
0
        public void GetCorporationNameTest()
        {
            Mock <DbSet <SQLDatabase.EF.CorporationsView> > moq_CorpViews = new Mock <DbSet <SQLDatabase.EF.CorporationsView> >();

            var view = cView.Where(w => w.SiteId == TestUsers.TestInsuletSite).FirstOrDefault();

            view.Corp_Name = String.Empty;

            moq_CorpViews.SetupData(cView);

            nuContext.Setup(c => c.CorporationsViews).Returns(moq_CorpViews.Object);
            AspnetDbHelpers ah = new AspnetDbHelpers(nuContext.Object);

            // verify corporate name is returned
            Assert.AreEqual("CliniProWeb", ah.GetCorporationName(TestUsers.TestCliniProSite));

            // verify corporation name not exist returns empty string
            Assert.IsTrue(String.IsNullOrEmpty(ah.GetCorporationName(TestUsers.TestInsuletSite)));

            // verify if site id not exist returns empty string
            Assert.IsTrue(String.IsNullOrEmpty(ah.GetCorporationName(TestUsers.FakeSite)));
        }
Esempio n. 2
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);
            }
        }