public void Execute_ValidationFails_ThrowsException()
        {
            ProjectModel model = DataHelper.CreateProjectModel();

            _projectValidator.Validate(model).Returns(new ValidationResult("error"));

            // execute
            TestDelegate del = () => _createProjectCommand.Execute(model);

            // assert
            Assert.Throws <ValidationException>(del);

            // we shouldn't have even tried to do the insert
            _dbContext.DidNotReceive().ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>());
        }
Exemplo n.º 2
0
        public void Delete_AuthTest()
        {
            // setup
            var currentUser = new UserIdentity()
            {
                Id = Guid.NewGuid(), UserName = "******"
            };
            var browser = new Browser((bootstrapper) =>
                                      bootstrapper.Module(new ProjectModule(_dbContext, _projectValidator, _createProjectCommand, _deleteProjectCommand, _projectRepo, _logFileRepo, _requestRepo, _projectRequestAggregateRepo))
                                      .RequestStartup((container, pipelines, context) => {
                context.CurrentUser = currentUser;
            })
                                      );

            _projectValidator.Validate(Arg.Any <ProjectModel>()).Returns(new ValidationResult());
            _createProjectCommand.Execute(Arg.Any <ProjectModel>()).Returns(DataHelper.CreateProjectModel());

            TestHelper.ValidateAuth(currentUser, browser, Actions.Project.Delete(1), HttpMethod.Post, Claims.ProjectEdit);
        }
Exemplo n.º 3
0
        public dynamic ProjectSave()
        {
            ProjectFormViewModel model   = this.Bind <ProjectFormViewModel>();
            ProjectModel         project = Mapper.Map <ProjectFormViewModel, ProjectModel>(model);

            ValidationResult validationResult = _projectValidator.Validate(project);

            if (validationResult.Success)
            {
                _dbContext.BeginTransaction();
                project = _createProjectCommand.Execute(project);
                _dbContext.Commit();
            }

            SaveResultModel result = new SaveResultModel(project.Id.ToString(), validationResult.Success, validationResult.Messages.ToArray());

            return(this.Response.AsJson(result));
        }