public void GetAllByUserWithPagingAndFilteringWithoutDateRangeShouldWork() { string userId = "userId"; string wrongUserId = "wrongUserId"; DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddDays(5); var trainingsRepo = new Mock <IDbRepository <Training> >(); trainingsRepo.Setup( x => x.All()) .Returns(new List <Training>() { new Training() { UserId = userId, StartDate = startDate, EndDate = endDate }, new Training() { UserId = wrongUserId, StartDate = startDate, EndDate = endDate } }.AsQueryable()); var usersRepo = new Mock <IDbRepository <ApplicationUser> >(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.GetAllByUserWithPagingAndFiltering(userId, 0, 2, null, null); Assert.AreEqual(1, result.Count()); }
public void ChangeTrainingsSequence(int[] sequence) { string login = HttpContext.Session.GetString("User_Login"); TrainingsService service = new TrainingsService(services); service.ChangeTrainingsSequence(sequence, login); }
public void EditCourse(TrainingDTO training) { string login = HttpContext.Session.GetString("User_Login"); TrainingsService service = new TrainingsService(services); service.EditTraining(training, login); }
public void GetCheckedInTrainingsPagingShouldWork() { var trainingsRepo = new Mock <IDbRepository <Training> >(); trainingsRepo.Setup( x => x.All()) .Returns(new List <Training>() { new Training() { CheckedInOn = DateTime.Now, CheckedOutOn = null }, new Training() { CheckedInOn = DateTime.Now, CheckedOutOn = null }, new Training() { } }.AsQueryable()); var usersRepo = new Mock <IDbRepository <ApplicationUser> >(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.GetCheckedIn(0, 1); Assert.AreEqual(1, result.Count()); }
public void GetAllByUserWithPagingAndFilteringWithDateRangeShouldWork() { string userId = "userId"; string wrongUserId = "wrongUserId"; DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddDays(5); DateTime wrongEndDate = startDate.AddDays(10); var trainingsRepo = new Mock<IDbRepository<Training>>(); trainingsRepo.Setup( x => x.All()) .Returns(new List<Training>() { new Training() { UserId = userId, StartDate = startDate, EndDate = endDate }, new Training() { UserId = userId, StartDate = startDate, EndDate = wrongEndDate } }.AsQueryable()); var usersRepo = new Mock<IDbRepository<ApplicationUser>>(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.GetAllByUserWithPagingAndFiltering(userId, 0, 2, startDate, endDate); Assert.AreEqual(1, result.Count()); }
public void UpdateCheckInOutWithCheckOutCommandAndIllegalRequestShouldThrow() { int trainingId = 1; string userId = "user1"; string command = "checkout"; var trainingsRepo = new Mock <IDbRepository <Training> >(); trainingsRepo.Setup( x => x.All()) .Returns(new List <Training>() { new Training() { Id = trainingId, UserId = userId }, new Training() { Id = trainingId + 1, UserId = userId } }.AsQueryable()); var usersRepo = new Mock <IDbRepository <ApplicationUser> >(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(trainingId, command, userId); }
public void UpdateCheckInOutWithCheckInCommandAndLegalRequestShouldWork() { int trainingId = 1; string userId = "user1"; string command = "checkin"; var trainingsRepo = new Mock <IDbRepository <Training> >(); trainingsRepo.Setup( x => x.All()) .Returns(new List <Training>() { new Training() { Id = trainingId, UserId = userId }, new Training() { Id = trainingId + 1, UserId = userId } }.AsQueryable()); var usersRepo = new Mock <IDbRepository <ApplicationUser> >(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(trainingId, command, userId); Assert.AreNotEqual(null, result.CheckedInOn); }
public void UpdateCheckInOutWithWrongUserIdShouldReturnNull() { int trainingId = 1; string userId = "user1"; var trainingsRepo = new Mock <IDbRepository <Training> >(); trainingsRepo.Setup( x => x.All()) .Returns(new List <Training>() { new Training() { Id = trainingId, UserId = userId }, new Training() { Id = trainingId + 1, UserId = userId } }.AsQueryable()); var usersRepo = new Mock <IDbRepository <ApplicationUser> >(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(2, "fake", "fake"); Assert.AreEqual(null, result); }
public void DeleteTraining(int id) { string login = HttpContext.Session.GetString("User_Login"); TrainingsService service = new TrainingsService(services); service.DeleteTraining(id, login); }
public void AddTraining(TrainingFromListDTO training, int id) { string login = HttpContext.Session.GetString("User_Login"); TrainingsService service = new TrainingsService(services); service.AddTraining(training, id, login); }
public virtual void InitializeTests() { this.dbContext = MockDbContext.GetContext(); var userManager = MockUserManager.GetUserManager(dbContext); var exercisesService = new Mock <IExercisesService>(); this.service = new TrainingsService( dbContext, MockAutoMapper.GetAutoMapper(), userManager, exercisesService.Object); }
private async Task InitAsync() { this.DataContext = _vm = new TrainingsViewModel(); await _vm.InitBaseAsync(); ITrainingsService trainingsSrv = new TrainingsService(App.__APIKey); var trainings = (await trainingsSrv.GetTrainingsAsync()).ToList(); foreach (var training in trainings) { _vm.Trainings.Add(TrainingsterminViewModel.FromSingle(training, App.__spieler)); } _vm.DoneLoading(); }
private async void SaveButton_Click(object sender, RoutedEventArgs e) { SaveButton.IsEnabled = false; CancelButton.IsEnabled = false; var trainingsService = new TrainingsService(App.__APIKey); var success = await trainingsService.SaveTrainingAsync(_edit); if (success.Erfolgreich) { this.Frame.GoBack(); } else { Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(success.Fehlermeldung); await dialog.ShowAsync(); } SaveButton.IsEnabled = true; CancelButton.IsEnabled = true; }
public void UpdateCheckInOutWithResetCommandAndLegalRequestShouldThrow() { int trainingId = 1; string userId = "user1"; string command = "reset"; var trainingsRepo = new Mock <IDbRepository <Training> >(); var predictedEndDate = DateTime.Now.AddDays(2); trainingsRepo.Setup( x => x.All()) .Returns(new List <Training>() { new Training() { Id = trainingId, UserId = userId, CheckedInOn = DateTime.Now, CheckedOutOn = DateTime.Now.AddDays(1), PredictedEndDate = predictedEndDate }, new Training() { Id = trainingId + 1, UserId = userId, CheckedInOn = DateTime.Now, CheckedOutOn = DateTime.Now.AddDays(1), PredictedEndDate = predictedEndDate } }.AsQueryable()); var usersRepo = new Mock <IDbRepository <ApplicationUser> >(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(trainingId, command, userId); Assert.AreEqual(null, result.CheckedOutOn); Assert.AreEqual(null, result.CheckedInOn); Assert.AreEqual(predictedEndDate, result.PredictedEndDate); }
public async void Execute(object parameter) { if (!ServiceBase.IsOnline()) { Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("Du bist gerade leider nicht online. Bitte prüfe deine Verbindung."); await dialog.ShowAsync(); return; } TrainingsterminViewModel model = parameter as TrainingsterminViewModel; model.Loading = true; model.LoadingFinished = false; ITrainingsService service = new TrainingsService(App.__APIKey); var success = await service.ChangeStatusAsync(App.__spieler, model.Termin, NewSpielerStatus); if (success.Erfolgreich) { var newTraining = await service.GetTrainingAsync(model.Termin.Id); model.RefreshFrom(newTraining, App.__spieler); var index = Model.Trainings.IndexOf(model); Model.Trainings.RemoveAt(index); Model.Trainings.Insert(index, model); } else { Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(success.Fehlermeldung); await dialog.ShowAsync(); return; } model.DoneLoading(); }
public void UpdateCheckInOutWithCheckOutCommandAndLegalRequestShouldThrow() { int trainingId = 1; string userId = "user1"; string command = "checkout"; var trainingsRepo = new Mock <IDbRepository <Training> >(); trainingsRepo.Setup( x => x.All()) .Returns(new List <Training>() { new Training() { Id = trainingId, UserId = userId, CheckedInOn = DateTime.Now }, new Training() { Id = trainingId + 1, UserId = userId, CheckedInOn = DateTime.Now } }.AsQueryable()); var usersRepo = new Mock <IDbRepository <ApplicationUser> >(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(trainingId, command, userId); Assert.AreNotEqual(null, result.CheckedOutOn); Assert.AreNotEqual(null, result.EndDate); Assert.AreEqual(result.CheckedOutOn.Value.ToShortDateString(), result.EndDate.ToShortDateString()); }
public void UpdateCheckInOutWithResetCommandAndLegalRequestShouldThrow() { int trainingId = 1; string userId = "user1"; string command = "reset"; var trainingsRepo = new Mock<IDbRepository<Training>>(); var predictedEndDate = DateTime.Now.AddDays(2); trainingsRepo.Setup( x => x.All()) .Returns(new List<Training>() { new Training() { Id = trainingId, UserId = userId, CheckedInOn = DateTime.Now, CheckedOutOn = DateTime.Now.AddDays(1), PredictedEndDate = predictedEndDate }, new Training() { Id = trainingId + 1, UserId = userId, CheckedInOn = DateTime.Now, CheckedOutOn = DateTime.Now.AddDays(1), PredictedEndDate = predictedEndDate } }.AsQueryable()); var usersRepo = new Mock<IDbRepository<ApplicationUser>>(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(trainingId, command, userId); Assert.AreEqual(null, result.CheckedOutOn); Assert.AreEqual(null, result.CheckedInOn); Assert.AreEqual(predictedEndDate, result.PredictedEndDate); }
public void UpdateCheckInOutWithCheckOutCommandAndLegalRequestShouldThrow() { int trainingId = 1; string userId = "user1"; string command = "checkout"; var trainingsRepo = new Mock<IDbRepository<Training>>(); trainingsRepo.Setup( x => x.All()) .Returns(new List<Training>() { new Training() { Id = trainingId, UserId = userId, CheckedInOn = DateTime.Now }, new Training() { Id = trainingId + 1, UserId = userId, CheckedInOn = DateTime.Now } }.AsQueryable()); var usersRepo = new Mock<IDbRepository<ApplicationUser>>(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(trainingId, command, userId); Assert.AreNotEqual(null, result.CheckedOutOn); Assert.AreNotEqual(null, result.EndDate); Assert.AreEqual(result.CheckedOutOn.Value.ToShortDateString(), result.EndDate.ToShortDateString()); }
public void UpdateCheckInOutWithCheckOutCommandAndIllegalRequestShouldThrow() { int trainingId = 1; string userId = "user1"; string command = "checkout"; var trainingsRepo = new Mock<IDbRepository<Training>>(); trainingsRepo.Setup( x => x.All()) .Returns(new List<Training>() { new Training() { Id = trainingId, UserId = userId }, new Training() { Id = trainingId + 1, UserId = userId } }.AsQueryable()); var usersRepo = new Mock<IDbRepository<ApplicationUser>>(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(trainingId, command, userId); }
public void UpdateCheckInOutWithCheckInCommandAndLegalRequestShouldWork() { int trainingId = 1; string userId = "user1"; string command = "checkin"; var trainingsRepo = new Mock<IDbRepository<Training>>(); trainingsRepo.Setup( x => x.All()) .Returns(new List<Training>() { new Training() { Id = trainingId, UserId = userId }, new Training() { Id = trainingId + 1, UserId = userId } }.AsQueryable()); var usersRepo = new Mock<IDbRepository<ApplicationUser>>(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(trainingId, command, userId); Assert.AreNotEqual(null, result.CheckedInOn); }
public void UpdateCheckInOutWithWrongUserIdShouldReturnNull() { int trainingId = 1; string userId = "user1"; var trainingsRepo = new Mock<IDbRepository<Training>>(); trainingsRepo.Setup( x => x.All()) .Returns(new List<Training>() { new Training() { Id = trainingId, UserId = userId }, new Training() { Id = trainingId + 1, UserId = userId } }.AsQueryable()); var usersRepo = new Mock<IDbRepository<ApplicationUser>>(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.UpdateCheckInOut(2, "fake", "fake"); Assert.AreEqual(null, result); }
public TrainingDTO Info(int id) { TrainingsService service = new TrainingsService(services); return(service.Info(id)); }
public void GetCheckedInTrainingsPagingShouldWork() { var trainingsRepo = new Mock<IDbRepository<Training>>(); trainingsRepo.Setup( x => x.All()) .Returns(new List<Training>() { new Training() { CheckedInOn = DateTime.Now, CheckedOutOn = null }, new Training() { CheckedInOn = DateTime.Now, CheckedOutOn = null }, new Training() { } }.AsQueryable()); var usersRepo = new Mock<IDbRepository<ApplicationUser>>(); var trainings = new TrainingsService(trainingsRepo.Object, usersRepo.Object); var result = trainings.GetCheckedIn(0, 1); Assert.AreEqual(1, result.Count()); }
public TrainingFromListDTO[] TrainingsList(int id) { TrainingsService service = new TrainingsService(services); return(service.TrainingsList(id)); }