Ejemplo n.º 1
0
        public async Task Create_Slots_Successes()
        {
            Setup();
            var slots = GenerateListOfSlots();

            var firstSlot = new SlotsReturnContract()
            {
                CoachId   = 5,
                DateStart = "02.20.2001",
                TimeStart = "11:00"
            };
            var SecondSlot = new SlotsReturnContract()
            {
                CoachId   = 5,
                DateStart = "02.20.2001",
                TimeStart = "10:00"
            };

            List <SlotsReturnContract> slotsAdd = new List <SlotsReturnContract>()
            {
                firstSlot, SecondSlot
            };

            _applicationContextMock.Setup(x => x.Slots).ReturnsDbSet(slots);

            _testedService = new SlotService(Logger, _applicationContextMock.Object);

            var result = await _testedService.AddListOfSlots(slotsAdd, CancellationToken.None);

            Assert.True(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateSlot(
            [FromBody] SlotsReturnContract createSlots,
            CancellationToken cancellationToken)
        {
            var update = await _slotService.UpdateSlot(createSlots, cancellationToken);

            if (update)
            {
                return(Ok());
            }

            return(NotFound("No slot"));
        }
 /// <summary>
 /// Return contract
 /// </summary>
 /// <param name="contract"></param>
 /// <returns></returns>
 public static Slot SlotMapFromContractToModel(SlotsReturnContract contract)
 {
     if (contract == null)
     {
         return(null);
     }
     return(new Slot
     {
         Id = contract.Id,
         CoachId = contract.CoachId,
         Date = DateTime.ParseExact(contract.DateStart, Settings.DateFormat, null, DateTimeStyles.None),
         Duration = TimeSpan.Parse(contract.Duration, null),
         StartTime = TimeSpan.Parse(contract.TimeStart, null)
     });
 }
Ejemplo n.º 4
0
        public async Task Slots_Update_Successes(int id)
        {
            Setup();
            var slots = GenerateListOfSlots();

            var firstSlot = new SlotsReturnContract()
            {
                Id        = id,
                CoachId   = 5,
                DateStart = "02.20.2001",
                Duration  = "10:00",
                TimeStart = "11:00"
            };

            _applicationContextMock.Setup(x => x.Slots).ReturnsDbSet(slots);

            _testedService = new SlotService(Logger, _applicationContextMock.Object);

            var result = await _testedService.UpdateSlot(firstSlot, CancellationToken.None);

            Assert.True(result);
        }
        /// <summary>
        /// update coach
        /// </summary>
        /// <param name="slotContract"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <bool> UpdateSlot(SlotsReturnContract slotContract, CancellationToken cancellationToken)
        {
            var slot = SlotsMapping.SlotMapFromContractToModel(slotContract);

            var updateSlot = await _dbContext.Slots.FirstOrDefaultAsync(x => x.Id == slotContract.Id, cancellationToken);

            if (updateSlot == null)
            {
                _logger.LogInformation($"No slot with {slot.Id} Id");
                return(false);
            }
            try
            {
                _dbContext.Update(slot);
                await _dbContext.SaveChangesAsync(cancellationToken);
            }
            catch
            {
                _logger.LogInformation($"Slot with id {slot.Id} is not updated");
                return(false);
            }
            return(true);
        }