public async void ShouldAddTrip() { //Given var now = DateTime.Now; var companyName = "New One"; var calendar = await CalendarRepository.Add(now); var company = await CompanyRepository.Add(new Company { Name = companyName }, true); var vehicle = await VehicleRepository.Add(new Vehicle { Name = "Vehicle" }, true); var vehicleType = await VehicleTypeRepository.Add(new VehicleType { Name = "VehicleType" }, true); var neighborhood = await NeighborhoodRepository.Add(new Neighborhood { Name = "Neighborhood" }, true); var patternArea = await PatternAreaRepository.Add(new PatternArea { Name = "Pattern Area" }, true); var paymentType = await PaymentTypeRepository.Add(new PaymentType { Name = "Payment" }, true); var controller = new TripController( new Mock <ILogger <TripController> >().Object, TripRepository, CalendarRepository, CompanyRepository, VehicleRepository ); var tripDTO = new TripDTO { StartTime = now, EndTime = now.AddHours(2), CompanyName = companyName, VehicleName = vehicle.Name, VehicleTypeKey = Convert.ToByte(vehicleType.Key), NeighborhoodStartKey = neighborhood.Key, NeighborhoodEndKey = neighborhood.Key, PatternAreaStartKey = patternArea.Key, PatternAreaEndKey = patternArea.Key, PaymentTypeKey = Convert.ToByte(paymentType.Key), PaymentAccessKey = Convert.ToByte(paymentType.Key) }; //When var result = await controller.PostAsync(tripDTO); var dbTrip = await TripRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <TripDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(tripDTO.EndTime.TimeOfDay, dbTrip.EndTime); }
///<inheritdoc/> public override void Handle(BrokeredMessage message) { var calendarRepository = new CalendarRepository(new MyCompanyContext()); var dto = message.GetBody <CalendarDTO>(); var calendar = Mapper.Map <Calendar>(dto); calendarRepository.Add(calendar); }
public async void ShouldAddComplaint() { //Given var now = DateTime.Now; var calendar = await CalendarRepository.Add(Calendars[0].Date); await CompanyRepository.Add(Companies[0], true); await TripRepository.Add(Trips[0]); await VehicleRepository.Add(Vehicles[0], true); var status = await StatusRepository.Add(new Status { Name = "Open" }, true); var location = new Point(new Coordinate(-122.3456, 45.67890)); var complaintDTO = new ComplaintDTO { SubmittedDate = Calendars[0].Date + now.TimeOfDay, Location = location.ToGeoJson <GeoJSON.Net.Geometry.Point>(), CompanyName = Companies[0].Name, VehicleName = Vehicles[0].Name, VehicleTypeKey = 1, ComplaintTypeKey = 8, ComplaintDetails = "Vehicle component issue", Complaints = new string[] { } }; //When var result = await Controller.PostAsync(complaintDTO); var dbCollision = await ComplaintRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <ComplaintDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(complaintDTO.SubmittedDate, model.SubmittedDate); Assert.True(dbCollision.FirstSeen == dbCollision.LastSeen); }
public async void ShouldAddCollision() { //Given var now = DateTime.Now; var calendar = await CalendarRepository.Add(Calendars[0].Date); await CompanyRepository.Add(Companies[0], true); await TripRepository.Add(Trips[0]); await VehicleRepository.Add(Vehicles[0], true); var status = await StatusRepository.Add(new Status { Name = "Open" }, true); var location = new Point(new Coordinate(-122.3456, 45.67890)); var collisionDTO = new CollisionDTO { Date = Calendars[0].Date + now.TimeOfDay, Location = location.ToGeoJson <GeoJSON.Net.Geometry.Point>(), CompanyName = Companies[0].Name, VehicleName = Vehicles[0].Name, TripAlternateKey = Trips[0].AlternateKey, VehicleTypeKey = 4, OtherVehicleTypeKey = 1, ClaimStatusKey = Convert.ToByte(status.Key) }; //When var result = await Controller.PostAsync(collisionDTO); var dbCollision = await CollisionRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <CollisionDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(collisionDTO.Date, model.Date); Assert.True(dbCollision.FirstSeen == dbCollision.LastSeen); }
public async void ShouldUpdateDeployment() { //Given var now = DateTime.Now; var companyName = "New One"; var calendar = await CalendarRepository.Add(now); await CompanyRepository.Add(new Company { Name = companyName }, true); var dbDeployment = new Deployment { Key = 1, StartDateKey = calendar.Key, StartTime = now.TimeOfDay, EndDateKey = calendar.Key, EndTime = now.TimeOfDay.Add(TimeSpan.FromHours(1)) }; await DeploymentRepository.Add(dbDeployment); // since we are modifying directly and not scoping, we'll need this Context.Entry(dbDeployment).State = EntityState.Detached; var controller = new DeploymentController( new Mock <ILogger <DeploymentController> >().Object, DeploymentRepository, CalendarRepository, CompanyRepository, VehicleRepository ); var deploymentDTO = new DeploymentDTO { Key = 1, StartTime = now, EndTime = now.AddHours(2), CompanyName = companyName }; //When var result = await controller.Update(deploymentDTO.Key, deploymentDTO); dbDeployment = await DeploymentRepository.Find(1); //Then var viewResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsType <DeploymentDTO>(viewResult.Value); Assert.NotNull(model); Assert.Equal(deploymentDTO.EndTime.Value.TimeOfDay, dbDeployment.EndTime); }
public void CalendarRepository_DeleteCalendar_Deleted_NotFail_Test() { var context = new MyCompanyContext(); var calendarId = context.Calendars.Select(e => e.CalendarId).Max() + 1; var calendar = new Calendar() { CalendarId = calendarId, Vacation = 12, }; ICalendarRepository target = new CalendarRepository(context); target.Add(calendar); target.Delete(calendarId); }
public void CalendarRepository_AddCalendar_Added_NotFail_Test() { var context = new MyCompanyContext(); int expected = context.Calendars.Count() + 1; var target = new CalendarRepository(context); var calendarId = context.Calendars.Select(e => e.CalendarId).Max() + 1; var calendar = new Calendar() { CalendarId = calendarId, Vacation = 12, }; target.Add(calendar); int actual = context.Calendars.Count(); Assert.AreEqual(expected, actual); }
public static void SetUpEvent(List <WordModel> words) { if (SmartLearningApplication.Instance.DatabaseName.Equals("SmartLearning.db3")) { courseName = "English"; } else if (SmartLearningApplication.Instance.DatabaseName.Equals("SmartLearningGerman.db3")) { courseName = "German"; } else { return; } //---- Add event to calender RequestAccess(EKEntityType.Event, () => { //Delete current event NSError e; var calendarRepository = new CalendarRepository(); var calendars = calendarRepository.GetAll(); if (calendars != null && calendars.Count != 0) { var calendar = calendars[0]; var currentEvent = App.Current.EventStore.EventFromIdentifier(calendar.EventIdentifier); if (currentEvent != null) { App.Current.EventStore.RemoveEvent(currentEvent, EKSpan.ThisEvent, true, out e); } } var newEvent = EKEvent.FromStore(App.Current.EventStore); //--- Setup time var fireDate = words[0].NextDay.Date; var startTime = (fireDate.Equals(DateTime.Now.Date))?DateTime.Now:fireDate.AddHours(7); var endTime = fireDate.AddHours(23); // set the alarm newEvent.AddAlarm(EKAlarm.FromDate(startTime)); // make the event newEvent.StartDate = startTime; newEvent.EndDate = endTime; newEvent.Title = courseName + ": Review your words with CleverBook"; var wordList = ""; foreach (var word in words) { wordList += word.Word + "; "; } newEvent.Notes = "You have " + words.Count + ((words.Count == 1) ? " word" : " words") + " to review: " + wordList; newEvent.Calendar = App.Current.EventStore.DefaultCalendarForNewEvents; App.Current.EventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e); calendarRepository.Add(new CalendarModel() { EventIdentifier = newEvent.EventIdentifier }); }); }