Exemplo n.º 1
0
        public ActionResult Create(TaskFormModel model)
        {
            var task = TaskService.TaskNew();

            this.MapToObject(model, task);

            task = TaskService.TaskSave(task);

            if (task.IsValid)
            {
                if (model.HourId != 0)
                {
                    var hour = HourService.HourFetch(model.HourId);

                    hour.TaskId = task.TaskId;

                    HourService.HourSave(hour);
                }

                return(new JsonResult {
                    Data = this.Url.Action("Edit", new { id = task.TaskId, message = Resources.SaveSuccessfulMessage })
                });
            }

            this.MapToModel(task, model, false);

            return(this.View(model));
        }
Exemplo n.º 2
0
        public void Hour_Delete()
        {
            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = DataHelper.RandomString(100);

            hour = HourService.HourSave(hour);

            hour = HourService.HourFetch(hour.HourId);

            HourService.HourDelete(hour.HourId);

            try
            {
                HourService.HourFetch(hour.HourId);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetBaseException() is InvalidOperationException);
            }
        }
Exemplo n.º 3
0
        public ActionResult Create(int?hourId)
        {
            var model = new TaskFormModel();

            try
            {
                Task task;

                if (hourId != null)
                {
                    task = TaskService.TaskNew(HourService.HourFetch((int)hourId));
                }
                else
                {
                    task = TaskService.TaskNew();
                }

                this.MapToModel(task, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(this.View(model));
        }
Exemplo n.º 4
0
        public void Hour_Edit()
        {
            var hour  = HourService.HourNew();
            var notes = DataHelper.RandomString(100);

            var task = BusinessHelper.CreateTask();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = notes;

            Assert.IsTrue(hour.IsValid, "IsValid should be true");

            hour = HourService.HourSave(hour);

            hour = HourService.HourFetch(hour.HourId);

            hour.Notes = DataHelper.RandomString(100);

            hour = HourService.HourSave(hour);

            hour = HourService.HourFetch(hour.HourId);

            Assert.IsTrue(hour.Notes != notes, "Notes should have different value");
        }
Exemplo n.º 5
0
        public ActionResult Delete(int id)
        {
            var model = new HourFormModel();

            try
            {
                var hour = HourService.HourFetch(id);

                this.Map(hour, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(this.View(model));
        }
Exemplo n.º 6
0
        public void Hour_Fetch()
        {
            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

            hour.ProjectId = task.ProjectId;
            hour.TaskId    = task.TaskId;
            hour.Date      = DateTime.Now.Date;
            hour.Duration  = 8;
            hour.Notes     = DataHelper.RandomString(100);

            hour = HourService.HourSave(hour);

            hour = HourService.HourFetch(hour.HourId);

            Assert.IsFalse(hour == null, "Hour should not be null");
        }
        public void Hour_Fetch()
        {
            var hour = BusinessHelper.CreateHourAndLogon(
                HourTestsWithRoleReview.UserName,
                HourTestsWithRoleReview.UserPassword);

            Exception exception = null;

            try
            {
                HourService.HourFetch(hour.HourId);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception == null, "Exception should be null");
        }
Exemplo n.º 8
0
        public ActionResult Edit(int id, HourFormModel model)
        {
            var hour = HourService.HourFetch(id);

            Csla.Data.DataMapper.Map(model, hour, true);

            hour = HourService.HourSave(hour);

            if (hour.TaskId != 0)
            {
                model.Task = TaskService.TaskFetch(hour.TaskId);
            }

            if (hour.IsValid)
            {
                model.Message = Resources.SaveSuccessfulMessage;
            }

            this.Map(hour, model, true);

            return(this.View(model));
        }
Exemplo n.º 9
0
        public ActionResult Edit(int id, string message)
        {
            var model = new HourFormModel();

            try
            {
                var hour = HourService.HourFetch(id);

                model.Message = message;

                if (hour.TaskId != 0)
                {
                    model.Task = TaskService.TaskFetch(hour.TaskId);
                }

                this.Map(hour, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(this.View(model));
        }
Exemplo n.º 10
0
        public void Hour_Edit()
        {
            var hour = BusinessHelper.CreateHourAndLogon(
                HourTestsWithRoleReview.UserName,
                HourTestsWithRoleReview.UserPassword);

            Exception exception = null;

            try
            {
                hour = HourService.HourFetch(hour.HourId);

                hour.Notes = DataHelper.RandomString(20);

                hour = HourService.HourSave(hour);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception != null, "Exception should not be null");
            Assert.IsTrue(exception.GetBaseException() is SecurityException);
        }
Exemplo n.º 11
0
        public void Hour_Edit()
        {
            var hour = BusinessHelper.CreateHourForUserAndLogon(
                HourTestsWithRoleContribute.UserName,
                HourTestsWithRoleContribute.UserPassword,
                HourTestsWithRoleContribute.User.UserId);

            Exception exception = null;

            try
            {
                hour = HourService.HourFetch(hour.HourId);

                hour.Notes = DataHelper.RandomString(20);

                HourService.HourSave(hour);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception == null, "Exception should be null");
        }
Exemplo n.º 12
0
        public void Hour_Cannot_Write_To_User_Id_Property()
        {
            var hour = BusinessHelper.CreateHourAndLogon(
                HourTestsWithRoleContribute.UserName,
                HourTestsWithRoleContribute.UserPassword);

            Exception exception = null;

            try
            {
                hour = HourService.HourFetch(hour.HourId);

                hour.UserId = DataHelper.RandomNumber(1000);

                HourService.HourSave(hour);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception != null, "Exception should not be null");
            Assert.IsTrue(exception.GetBaseException() is SecurityException, "Exception should be of type SecurityException");
        }
Exemplo n.º 13
0
        public void Hour_Cannot_Edit_Where_Is_Archived_Property_Is_True()
        {
            var hour = BusinessHelper.CreateHourThatIsArchivedAndLogon(
                HourTestsWithRoleContribute.UserName,
                HourTestsWithRoleContribute.UserPassword);

            Exception exception = null;

            try
            {
                hour = HourService.HourFetch(hour.HourId);

                hour.Notes = DataHelper.RandomString(100);

                HourService.HourSave(hour);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception != null, "Exception should not be null");
            Assert.IsTrue(exception.GetBaseException() is SecurityException, "Exception should be of type SecurityException");
        }