예제 #1
0
        public void CheckContextualValidationRules()
        {
            Func <CourseDelete.Request, ValidationMessageCollection> CallSut = request =>
            {
                var response = DomainServices.Dispatch(request);
                return(response.ValidationDetails);
            };

            Assert2.CheckContextualValidation("CourseId", "CourseId must have a minimum value of 1", () => CallSut(CreateValidRequest(p => p.CommandModel.CourseId = 0)));
        }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            var request = new CourseDelete.Request(SystemPrincipal.Name, new CourseDelete.CommandModel {
                CourseId = id
            });

            DomainServices.Dispatch(request);

            return(RedirectToAction("Index"));
        }
예제 #3
0
        public void CheckContextualValidationRules()
        {
            Func <CourseCreate.Request, ValidationMessageCollection> CallSut = request =>
            {
                var response = DomainServices.Dispatch(request);
                return(response.ValidationDetails);
            };

            Assert2.CheckContextualValidation("Title", "The field Title must be a string with a minimum length of 3 and a maximum length of 50.", () => CallSut(CreateValidRequest(p => p.CommandModel.Title = "X")));
            Assert2.CheckContextualValidation("Credits", "The field Credits must be between 1 and 5.", () => CallSut(CreateValidRequest(p => p.CommandModel.Credits = 0)));
        }
예제 #4
0
        public void CheckContextualValidationRules()
        {
            Func <CourseUpdate.Request, ValidationMessageCollection> CallSut = request =>
            {
                var reponse = DomainServices.Dispatch(request);
                return(reponse.ValidationDetails);
            };

            Assert2.CheckContextualValidation("CourseId", "CourseId cannot be less than 1", () => CallSut(CreateValidRequest(p => p.CommandModel.CourseID             = 0)));
            Assert2.CheckContextualValidation("DepartmentId", "DepartmentId cannot be less than 1", () => CallSut(CreateValidRequest(p => p.CommandModel.DepartmentID = 0)));
        }
예제 #5
0
        public void CheckInvariantValidationRules()
        {
            Action <CourseUpdate.Request> CallSut = request =>
            {
                DomainServices.Dispatch(request);
            };

            // Example (not really an invariant rule)
            Assert2.CheckInvariantValidation("Title cannot be set to Title", () => CallSut(CreateValidRequest(p => p.CommandModel.Title = "Title")));
            Assert2.CheckInvariantValidation("Title cannot be null", () => CallSut(CreateValidRequest(p => p.CommandModel.Title         = null)));
        }
        public ActionResult Edit(StudentModify.CommandModel commandModel)
        {
            var request  = new StudentModify.Request(SystemPrincipal.Name, commandModel);
            var response = DomainServices.Dispatch(request);

            if (!response.HasValidationIssues)
            {
                return(RedirectToAction("Index"));
            }

            ModelState.AddRange(response.ValidationDetails);
            return(View(commandModel));
        }
예제 #7
0
        public ActionResult UpdateCourseCredits(int?multiplier)
        {
            if (multiplier != null)
            {
                var request = new CourseUpdateCredits.Request(SystemPrincipal.Name, new CourseUpdateCredits.CommandModel {
                    Multiplier = multiplier.Value
                });
                var response = DomainServices.Dispatch <CourseUpdateCredits.Response>(request);

                ViewBag.RowsAffected = response.RowsEffected;
            }

            return(View());
        }
예제 #8
0
        public async Task <ActionResult> Create(CourseCreate.CommandModel commandModel)
        {
            var request  = new CourseCreate.Request(SystemPrincipal.Name, commandModel);
            var response = DomainServices.Dispatch(request);

            if (!response.HasValidationIssues)
            {
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentID = await CreateDepartmentSelectList(commandModel.DepartmentID);

            return(View(commandModel));
        }
        public ActionResult Delete(int id)
        {
            var request = new StudentDelete.Request(SystemPrincipal.Name, new StudentDelete.CommandModel {
                StudentId = id
            });
            var response = DomainServices.Dispatch(request);

            if (!response.HasValidationIssues)
            {
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Delete", new { id = id, saveChangesError = true }));
        }
        public async Task <ActionResult> Edit(ModifyInstructorAndCoursesViewModel viewModel)
        {
            var request  = new InstructorModifyAndCourses.Request(SystemPrincipal.Name, viewModel.CommandModel);
            var response = DomainServices.Dispatch(request);

            if (response.HasValidationIssues)
            {
                ModelState.AddRange(response.ValidationDetails);
                await PopulateAssignedCourseData(viewModel.SelectedCourses);

                return(View(viewModel));
            }

            return(RedirectToAction("Index"));
        }
예제 #11
0
        public void GivenIHaveTheFollowingCourses(Table table)
        {
            foreach (var row in table.Rows)
            {
                var commandModel = DataHelper.CreateCommandModelFromTable <CourseCreate.CommandModel>(table, row);
                var response     = DomainServices.Dispatch <CourseCreate.Response>(new CourseCreate.Request("test", commandModel));

                if (response.HasValidationIssues)
                {
                    throw new ApplicationException(string.Join(" | ", response.ValidationDetails.Select(p => p.ErrorMessage)));
                }

                DataHelper.AddEntityToRemove(EntityType.Course, response.CourseId);
            }
        }
예제 #12
0
        public void GivenIHaveTheFollowingDepartments(Table table)
        {
            using (var repository = new ContosoUniversityEntityFrameworkRepository())
            {
                foreach (var row in table.Rows)
                {
                    var commandModel = DataHelper.CreateCommandModelFromTable <DepartmentCreate.CommandModel>(table, row);
                    var response     = DomainServices.Dispatch <DepartmentCreate.Response>(new DepartmentCreate.Request("test", commandModel));
                    if (response.HasValidationIssues)
                    {
                        throw new ApplicationException(string.Join(" | ", response.ValidationDetails.Select(p => p.ErrorMessage)));
                    }

                    DataHelper.AddEntityToRemove(EntityType.Department, response.DepartmentId);
                }
            }
        }
예제 #13
0
        public static void AfterScenario()
        {
            foreach (var entity in _AddedEntities)
            {
                switch (entity.Type)
                {
                case (EntityType.Department):
                    var commandModel = new DepartmentDelete.CommandModel {
                        DepartmentID = (int)entity.Id
                    };
                    DomainServices.Dispatch(new DepartmentDelete.Request("test", commandModel));
                    break;

                case (EntityType.Student):
                    var commandModel1 = new StudentDelete.CommandModel {
                        StudentId = (int)entity.Id
                    };
                    DomainServices.Dispatch(new StudentDelete.Request("test", commandModel1));
                    break;

                case (EntityType.Instructor):
                    var commandModel2 = new InstructorDelete.CommandModel {
                        InstructorId = (int)entity.Id
                    };
                    DomainServices.Dispatch(new InstructorDelete.Request("test", commandModel2));
                    break;

                case (EntityType.Course):
                    var commandModel3 = new CourseDelete.CommandModel {
                        CourseId = (int)entity.Id
                    };
                    DomainServices.Dispatch(new CourseDelete.Request("test", commandModel3));
                    break;

                default:
                    throw new ApplicationException($"Missing entity removal for type {entity.Type}");
                }
            }
        }