public async Task GetProgramByIdAsyncShouldThrowExceptionIfProgramIsNull()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await programsService.GetProgramByIdAsync(ProgramId));

            Assert.IsType <ArgumentNullException>(exception);
        }
        public async Task CreateProgramAsyncShouldThrowExceptionIfCategoryIsIncorrect()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var programModel = new ProgramAdminCreateViewModel
            {
                Title       = ProgramTitle,
                Description = ProgramDescription,
                Rating      = ProgramRating,
                CategoryId  = null,
            };

            var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await programsService.CreateProgramAsync(programModel));

            Assert.IsType <ArgumentNullException>(exception);
        }
Exemple #3
0
        public override void InitData()
        {
            base.InitData();

            Task <ICollection <ProgramDTO> > programsTask;

            if (TakeCurrentUserPrograms)
            {
                programsTask = new ProgramsService().GetUserPrograms();
            }
            else
            {
                programsTask = new ProgramsService().GetAllPrograms();
            }

            programsTask.ContinueWith(async task =>
            {
                if (task.Result == null)
                {
                    await App.Current.MainPage.DisplayAlert("Operation Failed", "Unable to load drills", "OK");
                }

                Items = task.Result;
                OnPropertyChanged("Items");
            });
        }
        public async Task GetAllProgramsAsyncShouldReturnProgramsSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var category = new ProgramCategory
            {
                Name        = CategoryName,
                Description = CategoryDescription,
            };

            await dbContext.ProgramCategories.AddAsync(category);

            await dbContext.SaveChangesAsync();

            for (int i = 0; i < 3; i++)
            {
                var program = new Program
                {
                    Title       = ProgramTitle,
                    Description = ProgramDescription,
                    CategoryId  = category.Id,
                };

                await dbContext.Programs.AddAsync(program);

                await dbContext.SaveChangesAsync();
            }

            var expected = await programsService.GetAllProgramsAsync();

            var counter = 0;

            foreach (var program in expected)
            {
                counter++;
            }

            Assert.Equal(3, counter);
        }
Exemple #5
0
        public async Task GetImagesByProductIdAsyncShouldReturnImagesSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var postsService = new PostsService(dbContext, mapper, usersService, categoriesService);

            var productsService = new ProductsService(dbContext, mapper, usersService, categoriesService);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var exercisesService = new ExercisesService(dbContext, mapper, usersService, categoriesService);

            var imagesService = new ImagesService(dbContext, mapper, postsService, exercisesService, productsService, programsService);

            for (int i = 0; i < 4; i++)
            {
                var image = new Image
                {
                    Url       = ImageUrl,
                    ProductId = ProductId,
                };

                await dbContext.Images.AddAsync(image);

                await dbContext.SaveChangesAsync();
            }

            var expected = await imagesService.GetImagesByProductIdAsync(ProductId);

            var counter = 0;

            foreach (var img in expected)
            {
                counter++;
            }

            Assert.Equal(4, counter);
        }
 public override void InitData()
 {
     base.InitData();
     Programs = new ProgramsService().GetLocalPrograms();
     if (Programs == null)
     {
         App.Current.MainPage.DisplayAlert("Operation Failed", "Users Programs were unable to load", "OK");
     }
     OnPropertyChanged("Programs");
     addPropertyToBeChangedAfterSelection("CanViewProgram");
 }
Exemple #7
0
        public async Task EditImageAsyncShouldEditImageSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var postsService = new PostsService(dbContext, mapper, usersService, categoriesService);

            var productsService = new ProductsService(dbContext, mapper, usersService, categoriesService);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var exercisesService = new ExercisesService(dbContext, mapper, usersService, categoriesService);

            var imagesService = new ImagesService(dbContext, mapper, postsService, exercisesService, productsService, programsService);

            var image = new Image
            {
                Id  = ImageId,
                Url = ImageUrl,
            };

            await dbContext.Images.AddAsync(image);

            await dbContext.SaveChangesAsync();

            var imageModel = new ImageAdminEditViewModel
            {
                Id  = ImageId,
                Url = ImageEditUrl,
            };

            await imagesService.EditImageAsync(imageModel);

            var actual = dbContext.Images.FirstOrDefaultAsync(i => i.Id == image.Id);

            Assert.Equal(imageModel.Url, actual.Result.Url);
        }
        public ActionResult Index()
        {
            using (var program = new ProgramsService())
            {
                ViewBag.Programs = program.GetPrograms();
            }
            using (var jobTitle = new JobtitlesService())
            {
                ViewBag.JobTitles = jobTitle.GetJobtitles();
            }

            return(View());
        }
Exemple #9
0
        public async Task EditImageAsyncShouldThrowExceptionIfProgramIdIsIncorrect()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var postsService = new PostsService(dbContext, mapper, usersService, categoriesService);

            var productsService = new ProductsService(dbContext, mapper, usersService, categoriesService);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var exercisesService = new ExercisesService(dbContext, mapper, usersService, categoriesService);

            var imagesService = new ImagesService(dbContext, mapper, postsService, exercisesService, productsService, programsService);

            var image = new Image
            {
                Id  = ImageId,
                Url = ImageUrl,
            };

            await dbContext.Images.AddAsync(image);

            await dbContext.SaveChangesAsync();

            var imageModel = new ImageAdminEditViewModel
            {
                Url       = ImageUrl,
                ProgramId = ProgramId,
            };

            var exception = await Assert.ThrowsAsync <ArgumentNullException>(async() => await imagesService.EditImageAsync(imageModel));

            Assert.IsType <ArgumentNullException>(exception);
        }
Exemple #10
0
        /// <summary>
        /// Sets up HTTP methods mappings.
        /// </summary>
        /// <param name="service">Service handling requests</param>
        public ProgramsModule(ProgramsService service) : base("/")
        {
            Delete["/api/program/{programId}"] = parameters =>
            {
                var programId     = Parameters.ValueOf <string>(parameters, Context.Request, "programId", ParameterType.Path);
                var xGwImsOrgId   = Parameters.ValueOf <string>(parameters, Context.Request, "xGwImsOrgId", ParameterType.Header);
                var authorization = Parameters.ValueOf <string>(parameters, Context.Request, "authorization", ParameterType.Header);
                var xApiKey       = Parameters.ValueOf <string>(parameters, Context.Request, "xApiKey", ParameterType.Header);
                Preconditions.IsNotNull(programId, "Required parameter: 'programId' is missing at 'DeleteProgram'");

                Preconditions.IsNotNull(xGwImsOrgId, "Required parameter: 'xGwImsOrgId' is missing at 'DeleteProgram'");

                Preconditions.IsNotNull(authorization, "Required parameter: 'authorization' is missing at 'DeleteProgram'");

                Preconditions.IsNotNull(xApiKey, "Required parameter: 'xApiKey' is missing at 'DeleteProgram'");

                return(service.DeleteProgram(Context, programId, xGwImsOrgId, authorization, xApiKey));
            };

            Get["/api/program/{programId}"] = parameters =>
            {
                var programId     = Parameters.ValueOf <string>(parameters, Context.Request, "programId", ParameterType.Path);
                var xGwImsOrgId   = Parameters.ValueOf <string>(parameters, Context.Request, "xGwImsOrgId", ParameterType.Header);
                var authorization = Parameters.ValueOf <string>(parameters, Context.Request, "authorization", ParameterType.Header);
                var xApiKey       = Parameters.ValueOf <string>(parameters, Context.Request, "xApiKey", ParameterType.Header);
                Preconditions.IsNotNull(programId, "Required parameter: 'programId' is missing at 'GetProgram'");

                Preconditions.IsNotNull(xGwImsOrgId, "Required parameter: 'xGwImsOrgId' is missing at 'GetProgram'");

                Preconditions.IsNotNull(authorization, "Required parameter: 'authorization' is missing at 'GetProgram'");

                Preconditions.IsNotNull(xApiKey, "Required parameter: 'xApiKey' is missing at 'GetProgram'");

                return(service.GetProgram(Context, programId, xGwImsOrgId, authorization, xApiKey));
            };

            Get["/api/programs"] = parameters =>
            {
                var xGwImsOrgId   = Parameters.ValueOf <string>(parameters, Context.Request, "xGwImsOrgId", ParameterType.Header);
                var authorization = Parameters.ValueOf <string>(parameters, Context.Request, "authorization", ParameterType.Header);
                var xApiKey       = Parameters.ValueOf <string>(parameters, Context.Request, "xApiKey", ParameterType.Header);
                Preconditions.IsNotNull(xGwImsOrgId, "Required parameter: 'xGwImsOrgId' is missing at 'GetPrograms'");

                Preconditions.IsNotNull(authorization, "Required parameter: 'authorization' is missing at 'GetPrograms'");

                Preconditions.IsNotNull(xApiKey, "Required parameter: 'xApiKey' is missing at 'GetPrograms'");

                return(service.GetPrograms(Context, xGwImsOrgId, authorization, xApiKey));
            };
        }
        public async Task GetProgramByIdShouldReturnTrueIfProgramExists()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var category = new ProgramCategory
            {
                Name        = CategoryName,
                Description = CategoryDescription,
            };

            await dbContext.ProgramCategories.AddAsync(category);

            await dbContext.SaveChangesAsync();

            var program = new Program
            {
                Id          = ProgramId,
                Title       = ProgramTitle,
                Description = ProgramDescription,
                CategoryId  = category.Id,
            };

            await dbContext.Programs.AddAsync(program);

            await dbContext.SaveChangesAsync();

            var result = programsService.GetProgramById(ProgramId);

            Assert.True(result);
        }
        public async Task AddRatingAsyncShouldThrowExceptionIfUserIsNull()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var category = new ProgramCategory
            {
                Name        = CategoryName,
                Description = CategoryDescription,
            };

            await dbContext.ProgramCategories.AddAsync(category);

            await dbContext.SaveChangesAsync();

            var program = new Program
            {
                Id          = ProgramId,
                Title       = ProgramTitle,
                Description = ProgramDescription,
                CategoryId  = category.Id,
            };

            await dbContext.Programs.AddAsync(program);

            await dbContext.SaveChangesAsync();

            var exception = await Assert.ThrowsAsync <NullReferenceException>(async() => await programsService.AddRatingAsync(ProgramId));

            Assert.IsType <NullReferenceException>(exception);
        }
        public async Task CreateProgramAsyncShouldCreateProgramSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var category = new ProgramCategory
            {
                Name        = CategoryName,
                Description = CategoryDescription,
            };

            await dbContext.ProgramCategories.AddAsync(category);

            await dbContext.SaveChangesAsync();

            var programModel = new ProgramAdminCreateViewModel
            {
                Title       = ProgramTitle,
                Description = ProgramDescription,
                Rating      = ProgramRating,
                CategoryId  = category.Id,
            };

            await programsService.CreateProgramAsync(programModel);

            var actual = await dbContext.Programs.FirstOrDefaultAsync();

            Assert.Equal(programModel.Title, actual.Title);
        }
        public ActionResult GetRegisted(int programId)
        {
            var school = (T_DM_Truong)Session[Constant.SCHOOL_SESSION];

            if (school == null)
            {
                return(RedirectToRoute("login"));
            }
            using (var program = new ProgramsService())
            {
                ViewBag.Programs = program.GetProgramsAll();
            }
            using (var creative = new RegistrationReativeExpService())
            {
                ViewBag.Creatives = creative.GetRegistrationCreativeExpsBySchoolIdAndProgramId(school.SchoolID, programId);
            }
            ViewBag.ProgramId = programId;
            return(View());
        }
        public ActionResult CreativeExp(int programId, DateTime dateFrom, DateTime dateTo)
        {
            var manager = (Account)Session[Constant.MANAGER_SESSION];

            if (manager == null)
            {
                return(RedirectToRoute("quanlylogin"));
            }

            var managerPersmission = (List <UserPermission>)Session[Constant.MANAGER_PERMISSION_SESSION];

            //var permission = 1;
            if (managerPersmission.Where(s => s.PermissionId == 1).FirstOrDefault() == null)
            {
                return(RedirectToRoute("quanlylogin"));
            }
            using (var program = new ProgramsService())
            {
                var programs = program.GetProgramsByAccountId(manager.Id);
                ViewBag.Programs = programs;
                using (var creative = new RegistrationReativeExpService())
                {
                    if (programs.Where(s => s.Id == programId).SingleOrDefault() == null)
                    {
                        ViewBag.Creatives = creative.GetRegistrationCreativeExpsByProgramIdAndDateRange(programs[0].Id, dateFrom, dateTo);
                        programId         = programs[0].Id;
                    }
                    else
                    {
                        ViewBag.Creatives = creative.GetRegistrationCreativeExpsByProgramIdAndDateRange(programId, dateFrom, dateTo);
                    }
                }
                ViewBag.ProgramId = programId;
            }
            ViewBag.DateFrom = dateFrom.ToString("dd-MM-yyyy");
            ViewBag.DateTo   = dateTo.ToString("dd-MM-yyyy");
            return(View());
        }
        public async Task GetProgramDetailsByIdAsyncShouldReturnProgramSuccessfully()
        {
            var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var dbContext = new MyCalisthenicAppDbContext(options);

            IHttpContextAccessor httpContextAccessor = new HttpContextAccessor();

            var usersService = new UsersService(httpContextAccessor, dbContext, null);

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MyCalisthenicAppProfile());
            });

            var mapper = mockMapper.CreateMapper();

            var categoriesService = new CategoriesService(dbContext, mapper);

            var programsService = new ProgramsService(dbContext, mapper, usersService, categoriesService);

            var category = new ProgramCategory
            {
                Name        = CategoryName,
                Description = CategoryDescription,
            };

            await dbContext.ProgramCategories.AddAsync(category);

            await dbContext.SaveChangesAsync();

            for (int i = 0; i < 3; i++)
            {
                var program = new Program
                {
                    Title       = ProgramTitle,
                    Description = ProgramDescription,
                    CategoryId  = category.Id,
                };

                program.Images.Add(new Image
                {
                    Url = ImageUrl,
                });

                program.Comments.Add(new Comment
                {
                    Text = CommentText,
                });

                await dbContext.Programs.AddAsync(program);

                await dbContext.SaveChangesAsync();
            }

            var programToReturn = new Program
            {
                Id          = ProgramId,
                Title       = ProgramTitle,
                Description = ProgramDescription,
                CategoryId  = category.Id,
            };

            await dbContext.Programs.AddAsync(programToReturn);

            await dbContext.SaveChangesAsync();

            var expected = await programsService.GetProgramDetailsByIdAsync(ProgramId);

            Assert.Equal(expected.Id, programToReturn.Id);
        }