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)); } }
public BabysitterRepositoryTests() { _testBabysitter = new BabysitterRequestData { FamilyId = SetFamily(), StartTime = RandomData.GetInt(17, 23), EndTime = RandomData.GetInt(0, 4) }; _testBabysitterDb = new TestBabysitterDbContext(); _babysitterRepository = new BabysitterRepository(_testBabysitterDb); }
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>())); }
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()); }
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) }); }
private Int32 CalculatePay(BabysitterRequestData data) { var shiftWorked = Shift.Create(data.FamilyId, data.StartTime, data.EndTime); return(shiftWorked.CalculatePayForNightWorked()); }