当前位置: 首页>>代码示例>>C#>>正文


C# MockRepository.SetCurrentUser_Andre_CorrectPassword方法代码示例

本文整理汇总了C#中MockRepository.SetCurrentUser_Andre_CorrectPassword方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.SetCurrentUser_Andre_CorrectPassword方法的具体用法?C# MockRepository.SetCurrentUser_Andre_CorrectPassword怎么用?C# MockRepository.SetCurrentUser_Andre_CorrectPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MockRepository的用法示例。


在下文中一共展示了MockRepository.SetCurrentUser_Andre_CorrectPassword方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EditPost_UserIsOwner_WithInvalidData

        public void EditPost_UserIsOwner_WithInvalidData()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();
            try
            {
                mr.SetCurrentUser_Andre_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");

                homeController = mr.CreateController<PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            var viewModel = new PracticeHomeControllerViewModel
            {
                PracticeName = "", // Cannot set practice name to empty
                PracticeTimeZone = 3
            };

            Mvc3TestHelper.SetModelStateErrors(homeController, viewModel);

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
                            ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
                            ?? homeController.Edit(viewModel);

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            Assert.AreEqual(null, ((ViewResult)actionResult).View);
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:34,代码来源:PracticeHomeControllerTests.cs

示例2: Edit_4_EditExamThatDoesNotExist

        public void Edit_4_EditExamThatDoesNotExist()
        {
            ExamsController controller;
            ExaminationRequestViewModel viewModel;
            var isDbChangesSaved = false;
            var localNow = new DateTime(2012, 08, 16);
            try
            {
                var drandre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
                var patient = Firestarter.CreateFakePatients(drandre, this.db).First();

                var mr = new MockRepository(true);
                controller = mr.CreateController<ExamsController>(
                        setupNewDb: db => db.SavingChanges += (s, e) => { isDbChangesSaved = true; });
                Debug.Assert(drandre != null, "drandre must not be null");
                var utcNow = PracticeController.ConvertToUtcDateTime(drandre.Users.First().Practice, localNow);
                controller.UtcNowGetter = () => utcNow;

                // saving the object that will be edited
                var medicalProc0 = this.db.SYS_MedicalProcedure.Single(x => x.Code == "4.03.04.36-1");
                var examRequest = new ExaminationRequest
                                      {
                                          CreatedOn = utcNow,
                                          PatientId = patient.Id,
                                          Text = "Old text",
                                          MedicalProcedureCode = medicalProc0.Code,
                                          MedicalProcedureName = medicalProc0.Name,
                                          PracticeId = drandre.PracticeId,
                                      };
                this.db.ExaminationRequests.AddObject(examRequest);
                this.db.SaveChanges();

                // Define André as the logged user.
                mr.SetCurrentUser_Andre_CorrectPassword();

                // Creating view-model and setting up controller ModelState based on the view-model.
                var medicalProc1 = this.db.SYS_MedicalProcedure.Single(x => x.Code == "4.01.03.23-4");
                viewModel = new ExaminationRequestViewModel
                {
                    Id = 19837,
                    PatientId = patient.Id,
                    Notes = "New text",
                    MedicalProcedureCode = medicalProc1.Code,
                    MedicalProcedureName = medicalProc1.Name,
                };

                Mvc3TestHelper.SetModelStateErrors(controller, viewModel);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Editing an examination request that does not belong to the current user's practice.
            // This is not allowed and must throw an exception.
            // note: this is not a validation error, this is a malicious attack...
            ActionResult actionResult = controller.Edit(new[] { viewModel });

            // Verifying the ActionResult, and the DB.
            // - The result must be a ViewResult, with the name "Edit".
            // - The controller ModelState must have one validation message.
            Assert.IsNotNull(actionResult, "The result of the controller method is null.");
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            var viewResult = (ViewResult)actionResult;
            Assert.AreEqual("NotFound", viewResult.ViewName);

            // Verifying the database: cannot save the changes.
            Assert.IsFalse(isDbChangesSaved, "Database changes were saved, but they should not.");
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:70,代码来源:ExamsControllerTests.cs

示例3: Delete_3_ExamFromAnotherPractice

        public void Delete_3_ExamFromAnotherPractice()
        {
            ExamsController controller;
            ExaminationRequest examRequest;
            var isDbChangesSaved = false;
            var localNow = new DateTime(2012, 08, 16);
            try
            {
                var drandre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
                var dramarta = Firestarter.Create_CrmMg_Psiquiatria_DraMarta_Marta(this.db);
                var patientDraMarta = Firestarter.CreateFakePatients(dramarta, this.db).First();

                var mr = new MockRepository(true);
                controller = mr.CreateController<ExamsController>(
                        setupNewDb: db => db.SavingChanges += (s, e) => { isDbChangesSaved = true; });
                Debug.Assert(drandre != null, "drandre must not be null");
                var utcNow = PracticeController.ConvertToUtcDateTime(drandre.Users.First().Practice, localNow);
                controller.UtcNowGetter = () => utcNow;

                // saving the object that will be edited
                var medicalProc0 = this.db.SYS_MedicalProcedure.Single(x => x.Code == "4.03.04.36-1");
                examRequest = new ExaminationRequest
                {
                    CreatedOn = utcNow,
                    PatientId = patientDraMarta.Id,
                    Text = "Old text",
                    MedicalProcedureCode = medicalProc0.Code,
                    MedicalProcedureName = medicalProc0.Name,
                    PracticeId = dramarta.PracticeId,
                };
                this.db.ExaminationRequests.AddObject(examRequest);
                this.db.SaveChanges();

                // Define André as the logged user, he cannot edit Marta's patients.
                mr.SetCurrentUser_Andre_CorrectPassword();
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Editing an examination request that does not belong to the current user's practice.
            // This is not allowed and must throw an exception.
            // note: this is not a validation error, this is a malicious attack...
            var jsonResult = controller.Delete(examRequest.Id);

            // Verifying the ActionResult.
            Assert.IsNotNull(jsonResult, "The result of the controller method is null.");
            var jsonDelete = (JsonDeleteMessage)jsonResult.Data;
            Assert.IsFalse(jsonDelete.success, "Deletion should not succed.");
            Assert.IsNotNull(jsonDelete.text, "Deletion should fail with a message.");

            // Verifying the controller model-state.
            Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");

            // Verifying the database: cannot save the changes.
            Assert.IsFalse(isDbChangesSaved, "Database changes were saved, but they should not.");
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:59,代码来源:ExamsControllerTests.cs

示例4: Delete_2_ExamThatDoesNotExist

        public void Delete_2_ExamThatDoesNotExist()
        {
            ExamsController controller;
            bool isDbChangesSaved = false;
            try
            {
                using (var db2 = DbTestBase.CreateNewCerebelloEntities())
                {
                    Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(db2);

                    var mr = new MockRepository(true);
                    controller = mr.CreateController<ExamsController>(
                        setupNewDb: db => db.SavingChanges += (s, e) => { isDbChangesSaved = true; });

                    // Define André as the logged user, he cannot edit Marta's patients.
                    mr.SetCurrentUser_Andre_CorrectPassword();
                }
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Editing an examination request that does not belong to the current user's practice.
            // This is not allowed and must throw an exception.
            // note: this is not a validation error, this is a malicious attack...
            var jsonResult = controller.Delete(6327);

            // Verifying the ActionResult.
            Assert.IsNotNull(jsonResult, "The result of the controller method is null.");
            var jsonDelete = (JsonDeleteMessage)jsonResult.Data;
            Assert.IsFalse(jsonDelete.success, "Deletion should not succed.");
            Assert.IsNotNull(jsonDelete.text, "Deletion should fail with a message.");

            // Verifying the controller model-state.
            Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");

            // Verifying the database: cannot save the changes.
            Assert.IsFalse(isDbChangesSaved, "Database changes were saved, but they should not.");
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:41,代码来源:ExamsControllerTests.cs

示例5: Delete_1_HappyPath

        public void Delete_1_HappyPath()
        {
            ExamsController controller;
            Patient patient;
            ExaminationRequest examRequest;
            var isDbChangesSaved = false;
            var localNow = new DateTime(2012, 08, 16);
            try
            {
                using (var db2 = DbTestBase.CreateNewCerebelloEntities())
                {
                    var drandre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(db2);
                    patient = Firestarter.CreateFakePatients(drandre, db2).First();

                    var mr = new MockRepository(true);
                    controller = mr.CreateController<ExamsController>(
                        setupNewDb: db => db.SavingChanges += (s, e) => { isDbChangesSaved = true; });
                    Debug.Assert(drandre != null, "drandre must not be null");
                    var utcNow = PracticeController.ConvertToUtcDateTime(drandre.Users.First().Practice, localNow);
                    controller.UtcNowGetter = () => utcNow;

                    // saving the object that will be edited
                    var medicalProc1 = this.db.SYS_MedicalProcedure.Single(x => x.Code == "4.01.03.55-2");

                    examRequest = new ExaminationRequest
                                      {
                                          PracticeId = patient.PracticeId,
                                          CreatedOn = utcNow,
                                          PatientId = patient.Id,
                                          Text = "Old text",
                                          MedicalProcedureCode = medicalProc1.Code,
                                          MedicalProcedureName = medicalProc1.Name
                                      };

                    db2.ExaminationRequests.AddObject(examRequest);
                    db2.SaveChanges();

                    // Define André as the logged user, he cannot edit Marta's patients.
                    mr.SetCurrentUser_Andre_CorrectPassword();
                }
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Editing an examination request that does not belong to the current user's practice.
            // This is not allowed and must throw an exception.
            // note: this is not a validation error, this is a malicious attack...
            ActionResult actionResult = controller.Delete(examRequest.Id);

            // Verifying the ActionResult.
            Assert.IsNotNull(actionResult, "The result of the controller method is null.");

            // Verifying the controller model-state.
            Assert.IsTrue(controller.ModelState.IsValid, "ModelState is not valid.");

            // Verifying the database: cannot save the changes.
            Assert.IsTrue(isDbChangesSaved, "Database changes were not saved, but they should.");

            // Verifying the database.
            using (var db2 = DbTestBase.CreateNewCerebelloEntities())
            {
                var obj = db2.ExaminationRequests.FirstOrDefault(x => x.PatientId == patient.Id);
                Assert.IsNull(obj, "Database record was not deleted.");
            }
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:68,代码来源:ExamsControllerTests.cs

示例6: FindNextFreeTime_SkipDoctorVacation_HappyPath

        public void FindNextFreeTime_SkipDoctorVacation_HappyPath()
        {
            ScheduleController controller;
            var utcNow = new DateTime(2012, 09, 12, 18, 00, 00, DateTimeKind.Utc);
            bool isDbChanged = false;
            try
            {
                var andre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
                Firestarter.SetupDoctor(andre, this.db);

                var daysOff = DateTimeHelper.Range(new DateTime(2012, 09, 01), 30, d => d.AddDays(1.0))
                    .Select(
                        d => new CFG_DayOff
                            {
                                Date = d,
                                DoctorId = andre.Id,
                                Description = "Férias",
                                PracticeId = andre.PracticeId,
                            })
                    .ToArray();

                foreach (var eachDayOff in daysOff)
                    this.db.CFG_DayOff.AddObject(eachDayOff);

                this.db.SaveChanges();

                var mr = new MockRepository();
                mr.SetCurrentUser_Andre_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "FindNextFreeTime");

                controller = mr.CreateController<ScheduleController>(
                    callOnActionExecuting: true,
                    setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
                controller.UtcNowGetter = () => utcNow;
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            JsonResult jsonResult;
            {
                jsonResult = controller.FindNextFreeTime("", "");
            }

            Assert.IsFalse(isDbChanged, "Database should not be changed.");

            dynamic data = jsonResult.Data;
            Assert.AreEqual("01/10/2012", data.date);
            Assert.AreEqual("09:00", data.start);
            Assert.AreEqual("09:30", data.end);
            Assert.AreEqual("segunda-feira, daqui a 19 dias", data.dateSpelled);
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:54,代码来源:ScheduleControllerTests.cs

示例7: FindNextFreeTime_AllSlotsFree_HappyPath

        public void FindNextFreeTime_AllSlotsFree_HappyPath()
        {
            ScheduleController controller;
            var utcNow = new DateTime(2012, 09, 12, 18, 00, 00, DateTimeKind.Utc);
            bool isDbChanged = false;
            try
            {
                var andre = Firestarter.Create_CrmMg_Psiquiatria_DrHouse_Andre(this.db);
                Firestarter.SetupDoctor(andre, this.db);

                var mr = new MockRepository();
                mr.SetCurrentUser_Andre_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(ScheduleController), "FindNextFreeTime");

                controller = mr.CreateController<ScheduleController>(
                    callOnActionExecuting: true,
                    setupNewDb: db2 => db2.SavingChanges += (s, e) => { isDbChanged = true; });
                controller.UtcNowGetter = () => utcNow;
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            JsonResult jsonResult;
            {
                jsonResult = controller.FindNextFreeTime("", "");
            }

            Assert.IsFalse(isDbChanged, "Database should not be changed.");

            dynamic data = jsonResult.Data;
            Assert.AreEqual("12/09/2012", data.date);
            Assert.AreEqual("15:00", data.start);
            Assert.AreEqual("15:30", data.end);
            Assert.AreEqual("quarta-feira, hoje", data.dateSpelled);
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:38,代码来源:ScheduleControllerTests.cs

示例8: Index_UserIsOwner

        public void Index_UserIsOwner()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();
            try
            {
                mr.SetCurrentUser_Andre_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Index");

                homeController = mr.CreateController<PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Index")
                            ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Index")
                            ?? homeController.Index();

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            Assert.AreEqual(null, ((ViewResult)actionResult).View);
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:26,代码来源:PracticeHomeControllerTests.cs

示例9: EditPost_UserIsOwner_WithValidData

        public void EditPost_UserIsOwner_WithValidData()
        {
            PracticeHomeController homeController;
            var mr = new MockRepository();
            try
            {
                mr.SetCurrentUser_Andre_CorrectPassword();
                mr.SetRouteData_ConsultorioDrHouse_GregoryHouse(typeof(PracticeHomeController), "Edit");

                homeController = mr.CreateController<PracticeHomeController>(callOnActionExecuting: false);
            }
            catch (Exception ex)
            {
                InconclusiveInit(ex);
                return;
            }

            var viewModel = new PracticeHomeControllerViewModel
                                {
                                    PracticeName = "K!",
                                    PracticeTimeZone = 3,
                                    PhoneMain = "(32)91272552",
                                    Address = new AddressViewModel
                                        {
                                            StateProvince = "MG",
                                            CEP = "36030-000",
                                            City = "Juiz de Fora",
                                            Complement = "Sta Luzia",
                                            Street = "Rua Sem Saída",
                                        }
                                };

            Mvc3TestHelper.SetModelStateErrors(homeController, viewModel);

            // Execute test: owner must have access to this view.
            var actionResult = Mvc3TestHelper.RunOnAuthorization(homeController, "Edit", "POST")
                            ?? Mvc3TestHelper.RunOnActionExecuting(homeController, "Edit", "POST")
                            ?? homeController.Edit(viewModel);

            // Asserts
            Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
            var redirectResult = (RedirectToRouteResult)actionResult;
            Assert.AreEqual(2, redirectResult.RouteValues.Count);
            Assert.AreEqual("practicehome", string.Format("{0}", redirectResult.RouteValues["controller"]), ignoreCase: true);
            Assert.AreEqual("Index", string.Format("{0}", redirectResult.RouteValues["action"]), ignoreCase: true);
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:46,代码来源:PracticeHomeControllerTests.cs


注:本文中的MockRepository.SetCurrentUser_Andre_CorrectPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。