示例#1
0
        public static Hour CreateHourThatIsArchivedAndLogon(string userName, string userPassword)
        {
            var name     = DataHelper.RandomString(20);
            var password = DataHelper.RandomString(20);

            BusinessHelper.CreateUserWithFullControl(name, password);

            BusinessPrincipal.Login(name, password);

            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

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

            hour = HourService.HourSave(hour);

            BusinessPrincipal.Logout();

            BusinessPrincipal.Login(userName, userPassword);

            return(hour);
        }
示例#2
0
        public void Hour_New()
        {
            var hour = HourService.HourNew();

            Assert.IsTrue(hour.IsNew, "IsNew should be true");
            Assert.IsTrue(hour.IsDirty, "IsDirty should be true");
            Assert.IsFalse(hour.IsValid, "IsValid should be false");
            Assert.IsTrue(hour.IsSelfDirty, "IsSelfDirty should be true");
            Assert.IsFalse(hour.IsSelfValid, "IsSelfValid should be false");
            Assert.IsFalse(hour.IsArchived, "IsArchived should be false");
            Assert.IsTrue(hour.UserId == BusinessPrincipal.GetCurrentIdentity().UserId,
                          string.Format("UserId should be '{0}'", BusinessPrincipal.GetCurrentIdentity().UserId));
            Assert.IsTrue(hour.Date == DateTime.Now.Date,
                          string.Format("Date should be '{0:d}'", DateTime.Now.Date));

            // we init some values, so we want to make sure the rules are captured so
            // we reset the values to default
            hour.UserId = 0;
            hour.Date   = DateTime.MaxValue.Date;

            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Int32, "ProjectId"),
                          "ProjectId should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Int32, "UserId"),
                          "UserId should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.DateTime, "Date"),
                          "Date should be required");
            Assert.IsTrue(ValidationHelper.ContainsRule(hour, DbType.Decimal, "Duration"),
                          "Duration should be required");
        }
示例#3
0
        public ActionResult Create(int?projectId, int?taskId)
        {
            var model = new HourFormModel();

            try
            {
                var hour = HourService.HourNew();

                if (projectId.HasValue &&
                    projectId.Value != 0)
                {
                    hour.ProjectId = projectId.Value;
                }

                if (taskId.HasValue &&
                    taskId.Value != 0)
                {
                    hour.TaskId = taskId.Value;
                }

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

            return(this.View(model));
        }
示例#4
0
        public void Hour_Fetch_List()
        {
            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);

            HourService.HourSave(hour);

            hour = HourService.HourNew();

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

            HourService.HourSave(hour);

            var hours = HourService.HourFetchInfoList();

            Assert.IsTrue(hours.Count > 1, "Hours should be greater than one");
        }
示例#5
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);
            }
        }
示例#6
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");
        }
示例#7
0
        public static Hour CreateHour()
        {
            var hour = HourService.HourNew();

            var task = BusinessHelper.CreateTask();

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

            hour = HourService.HourSave(hour);

            return(hour);
        }
示例#8
0
        public void Hour_New()
        {
            Exception exception = null;

            try
            {
                HourService.HourNew();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception == null, "Exception should be null");
        }
        public void Hour_New()
        {
            Exception exception = null;

            try
            {
                HourService.HourNew();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsTrue(exception != null, "Exception should not be null");
            Assert.IsTrue(exception.GetBaseException() is SecurityException);
        }
示例#10
0
        public void Hour_Add()
        {
            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);

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

            hour = HourService.HourSave(hour);
        }
示例#11
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");
        }
示例#12
0
        public ActionResult Create(int?projectId, int?taskId, HourFormModel model)
        {
            var hour = HourService.HourNew();

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

            hour = HourService.HourSave(hour);

            if (hour.IsValid)
            {
                return(new JsonResult {
                    Data = this.Url.Action("Edit", new { id = hour.HourId, message = Resources.SaveSuccessfulMessage })
                });
            }

            this.Map(hour, model, false);

            return(this.View(model));
        }