コード例 #1
0
        public ActionResult <ViewModel <Babysitter> > Get(String familyId, int startTime, int endTime)
        {
            try
            {
                var requestData = new BabysitterRequestData()
                {
                    FamilyId  = familyId,
                    StartTime = startTime,
                    EndTime   = endTime
                };



                var babysitter = _babysitter.GetBabysitterWorkingShift(requestData);

                if (babysitter is null)
                {
                    return(NoContent());
                }

                var vm = BabysitterViewModel.From(Request, babysitter);

                return(Ok(vm));
            }
            catch (Exception ex)
            {
                var vm = new ViewModel <Babysitter>(String.Empty);
                vm.AddError(ex.Message);
                return(Ok(vm));
            }
        }
コード例 #2
0
        public BabysitterRepositoryTests()
        {
            _testBabysitter = new BabysitterRequestData
            {
                FamilyId  = SetFamily(),
                StartTime = RandomData.GetInt(17, 23),
                EndTime   = RandomData.GetInt(0, 4)
            };

            _testBabysitterDb = new TestBabysitterDbContext();

            _babysitterRepository = new BabysitterRepository(_testBabysitterDb);
        }
コード例 #3
0
        private void SetNoContentFixture()
        {
            _requestData = new BabysitterRequestData()
            {
                FamilyId  = SetFamily(),
                StartTime = RandomData.GetInt(17, 23),
                EndTime   = RandomData.GetInt(0, 4)
            };

            _mockBabysitter = new Mock <IBabysitterAccessor>();

            _mockBabysitter.Setup(x => x.GetBabysitterWorkingShift(It.IsAny <BabysitterRequestData>()));
        }
コード例 #4
0
        public Babysitter GetBabysitterWorkingShift(BabysitterRequestData babysitterRequest)
        {
            if (_dBContext.Babysitters.Count() > 0)
            {
                RemoveExistingBabysitter();
            }

            var babysitter = new Babysitter(babysitterRequest)
            {
                PayForShift = WorkShift(babysitterRequest.FamilyId, babysitterRequest.StartTime, babysitterRequest.EndTime)
            };

            _dBContext.Babysitters.Add(babysitter);
            _dBContext.SaveChanges();

            return(_dBContext.Babysitters.Where(b => babysitter.Id == b.Id).Single());
        }
コード例 #5
0
        private void SetTestFixture()
        {
            _requestData = new BabysitterRequestData()
            {
                FamilyId  = SetFamily(),
                StartTime = RandomData.GetInt(17, 23),
                EndTime   = RandomData.GetInt(0, 4)
            };

            _mockBabysitter = new Mock <IBabysitterAccessor>();

            _mockBabysitter.Setup(x => x.GetBabysitterWorkingShift(It.IsAny <BabysitterRequestData>()))
            .Returns(new Babysitter(_requestData)
            {
                PayForShift = RandomData.GetInt(80, 280)
            });
        }
コード例 #6
0
        private Int32 CalculatePay(BabysitterRequestData data)
        {
            var shiftWorked = Shift.Create(data.FamilyId, data.StartTime, data.EndTime);

            return(shiftWorked.CalculatePayForNightWorked());
        }