Ejemplo n.º 1
0
        public void SlotStorageOperations()
        {
            // Arrange
            TimeModel timeService = TimeModel.getService();
            DateTime  start       = DateTime.Today;
            DateTime  end         = DateTime.Now;
            string    desc        = "A daily dummy job";
            string    project     = "Test";
            Slot      createdSlot = new Slot(start, end, desc, project);

            // Act
            timeService.InsertSlot(createdSlot);
            long id        = timeService.GetSlotIdByData(start, end, desc, project);
            Slot foundSlot = timeService.GetSlotByID(id);

            // Assert
            Assert.AreEqual(createdSlot, foundSlot);

            // Act
            createdSlot.Description = "An updated activity description";
            timeService.UpdateSlot(createdSlot);
            foundSlot = timeService.GetSlotByID(id);

            // Assert
            Assert.AreEqual(foundSlot.Description, createdSlot.Description);

            // Act
            timeService.DeleteSlot(id);
            foundSlot = timeService.GetSlotByID(id);
            long noId = timeService.GetSlotIdByData(createdSlot.Start, createdSlot.End, createdSlot.Description, createdSlot.Project);

            // Assert
            Assert.IsNull(foundSlot);
            Assert.AreEqual(noId, TimeModel.NON_VALUE);
        }
Ejemplo n.º 2
0
        public IEnumerable <Slot> GetSlots()
        {
            TimeModel timeService = TimeModel.getService();
            var       slots       = timeService.GetSlots();

            return(slots);
        }
Ejemplo n.º 3
0
        private IEnumerable <Slot> GetSlots(string project, DateTime start, DateTime end)
        {
            TimeModel timeService = TimeModel.getService();

            if (!timeService.GetProjects().Contains(project))
            {
                return(timeService.GetSlots(start, end));
            }
            return(timeService.GetSlots(project, start, end));
        }
Ejemplo n.º 4
0
        public IEnumerable <Slot> GetSlots(string project)
        {
            TimeModel timeService = TimeModel.getService();

            if (!timeService.GetProjects().Contains(project))
            {
                return(timeService.GetSlots());
            }
            return(timeService.GetSlots(project));
        }
Ejemplo n.º 5
0
        public Slot Get(long id)
        {
            var slot = TimeModel.getService().GetSlotByID(id);

            if (slot == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(slot);
        }
Ejemplo n.º 6
0
        public HttpResponseMessage Delete(long id)
        {
            bool      result      = false;
            TimeModel timeService = TimeModel.getService();

            if (timeService.GetSlotByID(id) != null)
            {
                result = timeService.DeleteSlot(id);
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(new HttpResponseMessage(result ? HttpStatusCode.OK : HttpStatusCode.BadRequest));
        }
Ejemplo n.º 7
0
        // Warning: Assumes that is run after the previous test.
        // TODO: Remove when lifecycle can be completed.
        public void SlotStorageData()
        {
            // Arrange
            TimeModel timeRepository = TimeModel.getService();
            var       lastEntry      = new Slot(1, new DateTime(2018, 5, 2, 9, 00, 00), new DateTime(2018, 5, 2, 18, 00, 00),
                                                "Just a timeslot", "Test");

            // Act
            var slots = timeRepository.GetSlots();

            // Assert
            //Assert.AreEqual(expectedType, slots.ToString());
            IEnumerator <Slot> iter = slots.GetEnumerator();

            iter.MoveNext();
            Assert.AreEqual(lastEntry, iter.Current);
        }
Ejemplo n.º 8
0
        public HttpResponseMessage Post(FormDataCollection formData)
        {
            DateTime start, end;
            long     id;
            bool     success = true;

            success &= DateTime.TryParse(formData["Start"], out start);
            success &= DateTime.TryParse(formData["End"], out end);
            if (!success)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            if (start > end)
            {
                DateTime tmp = end;
                end   = start;
                start = tmp;
            }
            string description = formData["Description"];
            string project     = formData["Project"].Trim().Length == 0 ? UNSPECIFIED_PROJECT : formData["Project"];

            TimeModel timeService = TimeModel.getService();
            Slot      storedSlot  = null;

            if (Int64.TryParse(formData["ID"], out id))
            {
                storedSlot = timeService.GetSlotByID(id);
            }
            if (storedSlot != null)
            {
                success = timeService.UpdateSlot(new Slot(id, start, end, description, project));
                return(new HttpResponseMessage(success ? HttpStatusCode.OK : HttpStatusCode.InternalServerError));
            }
            else
            {
                success = timeService.InsertSlot(new Slot(start, end, description, project));
                return(new HttpResponseMessage(success ? HttpStatusCode.Created : HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 9
0
 public IEnumerable <string> GetProjects()
 {
     return(TimeModel.getService().GetProjects());
 }