Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Add(AddVisitBindingModel model)
        {
            try
            {
                VisitTerm visitTerm = await _unitOfWork.VisitTermRepository.AddVisitTermOrReturnIfExists(model.StartDate);

                Visit visit = Visit.Create(model.ServiceId, visitTerm.Id, User.Identity.GetUserId(), model.StartDate);
                visit = _mapper.Map(model, visit);

                await _unitOfWork.VisitRepository.Add(visit);

                await _unitOfWork.CompleteAsync();

                var addedVisit = await _unitOfWork.VisitRepository.FindWithCustomerAndServiceAsync(visit.Id);

                var result = _mapper.Map <VisitInfoBindingModel>(addedVisit);

                return(Ok(result));
            }
            catch (VisitCurrentlyReservedException e)
            {
                ModelState.AddModelError("model.StartDate", "Podana data została już zarezerwowana!");
                return(BadRequest(ModelState));
            }
            catch (Exception e)
            {
                _logger.Error(e);
                return(InternalServerError());
            }
        }
 private IEnumerable <VisitTerm> GetVisitTerms()
 {
     return(new List <VisitTerm>
     {
         VisitTerm.Create(DateTimeUtil.GetNextWeekday(Constants.Constants.OPENING_HOUR_OF_SALON.AddDays(1), DayOfWeek.Monday)),
         VisitTerm.Create(DateTimeUtil.GetNextWeekday(Constants.Constants.OPENING_HOUR_OF_SALON.AddDays(1), DayOfWeek.Tuesday)),
         VisitTerm.Create(DateTimeUtil.GetNextWeekday(Constants.Constants.OPENING_HOUR_OF_SALON.AddDays(1), DayOfWeek.Wednesday)),
     });
 }
        public async Task IsInDatabase_ShouldReturnTrueIfVisitTermExists()
        {
            // Arrange
            VisitTerm visitTerm = await _context.VisitTerms.FirstAsync();

            // Act
            bool isInDatabase = await _unitOfWork.VisitTermRepository.IsInDatabase(visitTerm.StartDate);

            // Assert
            Assert.IsTrue(isInDatabase);
        }
        public async Task AddVisitTermOrReturnIfExists_ShouldReturnExistingEntityFromDate()
        {
            // Arrange
            VisitTerm visitTerm = await _context.VisitTerms.FirstAsync();

            // Act
            VisitTerm result = await _unitOfWork.VisitTermRepository.AddVisitTermOrReturnIfExists(visitTerm.StartDate);

            // Assert
            Assert.AreEqual(result.Id, visitTerm.Id);
        }
        public async Task GetFreeHours_ShouldReturnAppropriateCountOfFreeHours()
        {
            // Arrange
            VisitTerm visitTerm = await _context.VisitTerms.FirstAsync();

            // Act
            var result = await _unitOfWork.VisitTermRepository.GetFreeHours(visitTerm.EndDate);

            // Assert
            Assert.AreEqual(18 - visitTerm.Visits.Count, result.Count);
        }
        public async Task GetByDateWithVisits_ShouldReturnVisitTermWithVisit()
        {
            // Arrange
            VisitTerm visitTerm = await _context.VisitTerms.FirstAsync();

            // Act
            VisitTerm result = await _unitOfWork.VisitTermRepository.GetByDateWithVisits(visitTerm.EndDate);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Visits);
        }
Ejemplo n.º 7
0
        public async Task Visits_ShouldReturnOkWithVisits()
        {
            // Arrange
            VisitTerm visitTerm = GetVisitTerm();

            unitOfWorkMock.Setup(x => x.VisitTermRepository.GetByDateWithVisits(It.IsAny <DateTime>())).ReturnsAsync(visitTerm);
            mapperMock.Setup(x => x.Map <VisitTermInfoBindingModel>(It.IsAny <VisitTerm>())).Returns(new VisitTermInfoBindingModel());

            // Act
            IHttpActionResult result = await controller.Visits(DateTime.Now);

            var content = result as OkNegotiatedContentResult <VisitTermInfoBindingModel>;

            // Assert
            Assert.IsInstanceOfType(content, typeof(OkNegotiatedContentResult <VisitTermInfoBindingModel>));
            Assert.IsNotNull(content.Content);
        }
 private VisitTerm GetVsisitTermForTest()
 {
     return(VisitTerm.Create(Constants.Constants.OPENING_HOUR_OF_SALON.AddDays(2)));
 }
Ejemplo n.º 9
0
 public VisitTerm GetVisitTerm()
 {
     return(VisitTerm.Create(
                DateTimeUtil.GetNextWeekday(Constants.Constants.OPENING_HOUR_OF_SALON, DayOfWeek.Monday),
                1));
 }