예제 #1
0
        public ActivityTime StartActivity(int id)
        {
            var activity = ActivityRepository.GetByID(id);
            if (activity == null)
                throw new Exception("Activity not found");

            if (activity.IsStarted())
                throw new Exception("Activity is already started");

            var newActivityTime = new ActivityTime()// _activityTimeRepository.dbSet.Create();
            {
                StartDate = DateTimeOffset.Now,
                EndDate = null,
                ActivityId = activity.Id
            };
            activity.ActivityTimes.Add(newActivityTime);
            Save();

            return newActivityTime;
        }
예제 #2
0
 public ActivityTime StopActivity(int id)
 {
     var activity = _activityRepository.GetByID(id);
     if (activity == null) {
         throw new Exception("Activity not found");
     }
     var newActivityTime = new ActivityTime()// _activityTimeRepository.dbSet.Create();
     {
         StartDate = DateTimeOffset.MinValue,
         EndDate = DateTimeOffset.Now,
         ActivityId = activity.Id
     };
     activity.ActivityTimes.Add(newActivityTime);
     Save();
     return newActivityTime;
 }
예제 #3
0
        public void StartToEndFlow()
        {
            var unitOfWork = new ActivityUnitOfWork();
            var repo = unitOfWork.ActivityRepository;

            var at = new ActivityTime();
            var act = new Activity()
            {
                Name = "test",
                DueDate = DateTimeOffset.Now.AddHours(2),
                CompletedAt = DateTime.Now,
                //act.ActivityTimes.StartDate = DateTimeOffset.Now.AddHours(10),
            };

            at.EndDate = DateTimeOffset.Now;

            repo.Insert(act);
            unitOfWork.Save();

            var startedActivityTime = unitOfWork.StartActivity(act.Id);
            Assert.IsNotNull(startedActivityTime);
            Assert.IsTrue(DateTimeOffset.Now > startedActivityTime.StartDate);

            //var endedActivityTime = repo.EndActivity(act.Id);
            //repo.SaveChanges();
            //   Assert.IsNotNull(endedActivityTime);
            //Assert.IsNull(endedActivityTime);

            //      Assert.IsNotNull(endedActivityTime.EndDate);

            //           Assert.IsTrue(DateTimeOffset.Now > startedActivityTime.EndDate);
            //            Assert.AreEqual(startedActivityTime.StartDate, endedActivityTime.StartDate);
        }