예제 #1
0
        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());
        }
예제 #2
0
        public void ChangeTrainingsSequence(int[] sequence)
        {
            string           login   = HttpContext.Session.GetString("User_Login");
            TrainingsService service = new TrainingsService(services);

            service.ChangeTrainingsSequence(sequence, login);
        }
예제 #3
0
        public void EditCourse(TrainingDTO training)
        {
            string           login   = HttpContext.Session.GetString("User_Login");
            TrainingsService service = new TrainingsService(services);

            service.EditTraining(training, login);
        }
예제 #4
0
        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());
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        public void DeleteTraining(int id)
        {
            string           login   = HttpContext.Session.GetString("User_Login");
            TrainingsService service = new TrainingsService(services);

            service.DeleteTraining(id, login);
        }
예제 #10
0
        public void AddTraining(TrainingFromListDTO training, int id)
        {
            string           login   = HttpContext.Session.GetString("User_Login");
            TrainingsService service = new TrainingsService(services);

            service.AddTraining(training, id, login);
        }
예제 #11
0
        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);
        }
예제 #12
0
        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();
        }
예제 #13
0
        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;
        }
예제 #14
0
        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);
        }
예제 #15
0
        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();
        }
예제 #16
0
        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);
        }
예제 #22
0
        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());
        }
예제 #24
0
        public TrainingFromListDTO[] TrainingsList(int id)
        {
            TrainingsService service = new TrainingsService(services);

            return(service.TrainingsList(id));
        }