public ChallengesController(ChallengesService cs, ParticipantsService ps, RuleDetailsService rs, DailyPointsService dps)
 {
     _cs  = cs;
     _ps  = ps;
     _rs  = rs;
     _dps = dps;
 }
Example #2
0
        public void ThrowsArgumentException_When_NoChallengeFound()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake = new Mock <IEfData>();
            var mapperFake = new Mock <IMappingProvider>();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            Challenge challenge   = null;
            var       challengeId = Guid.NewGuid();

            challengesRepositoryFake.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(challenge);

            // Act & Assert
            Assert.Throws <ArgumentException>(() => service.Update(challengeId.ToString(), It.IsAny <string>(), It.IsAny <Language>(), It.IsAny <double>(), It.IsAny <int>()));
        }
        public void Call_RepositoryAll_ToGetTheChallenges()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake = new Mock <IEfData>();
            var mapperFake = new Mock <IMappingProvider>();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            var challengesFake = new List <Challenge>().AsQueryable <Challenge>();

            challengesRepositoryFake.Setup(x => x.All).Returns(challengesFake).Verifiable();

            // Act
            service.GetByCateogryId <object>(It.IsAny <Guid>());

            // Assert
            challengesRepositoryFake.Verify(x => x.All, Times.AtLeastOnce);
        }
Example #4
0
        public void Call_ChallengesRepository_ToUpdateObjectState()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake = new Mock <IEfData>();
            var mapperFake = new Mock <IMappingProvider>();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            string challengeId   = Guid.NewGuid().ToString();
            var    challengeFake = new Mock <Challenge>();

            challengesRepositoryFake.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(challengeFake.Object);
            challengesRepositoryFake.Setup(x => x.Update(challengeFake.Object)).Verifiable();

            string title      = "title";
            var    lang       = Language.C;
            double timeInMs   = 1.1;
            int    memoryInKb = 1;

            // Act
            service.Update(challengeId, title, lang, timeInMs, memoryInKb);

            // Assert
            challengesRepositoryFake.Verify(x => x.Update(challengeFake.Object), Times.AtLeastOnce);
        }
Example #5
0
        public void Call_ChallengesRepositoryGetById_WithCorrectValue()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake = new Mock <IEfData>();
            var mapperFake = new Mock <IMappingProvider>();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            var  challengeId   = Guid.NewGuid();
            var  challengeFake = new Mock <Challenge>();
            Guid passedId      = default(Guid);

            challengesRepositoryFake.Setup(x => x.GetById(challengeId)).Returns(challengeFake.Object)
            .Callback <Guid>(x => passedId = x);

            // Act
            service.Update(challengeId.ToString(), It.IsAny <string>(), It.IsAny <Language>(), It.IsAny <double>(), It.IsAny <int>());

            // Assert
            Assert.IsTrue(passedId.ToString() == challengeId.ToString());
        }
Example #6
0
        public void Call_MappingProvider_ToCreateMappingOf_RequiredData()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake = new Mock <IEfData>();
            var mapperFake = new Mock <IMappingProvider>();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            mapperFake.Setup(x => x.ProjectTo <Challenge, object>(It.IsAny <IQueryable <Challenge> >())).Verifiable();

            // Act
            //service.GetAll<object>();

            // Assert
            mapperFake.Verify(x => x.ProjectTo <Challenge, object>(It.IsAny <IQueryable <Challenge> >()), Times.Once);
        }
Example #7
0
        public void Call_CategoriesRepository_WithCorrectId()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake   = new Mock <IEfData>();
            var mapperFake   = new Mock <IMappingProvider>();
            var categoryFake = new Mock <Category>();
            var categoryId   = Guid.NewGuid();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            categoriesRepositoryFake.Setup(x => x.GetById(categoryId)).Returns(categoryFake.Object).Verifiable();

            // Act
            service.Create("title", "description", categoryId.ToString(), Language.C, 12, 1, new List <Test>());

            // Assert
            categoriesRepositoryFake.Verify(x => x.GetById(categoryId));
        }
Example #8
0
        public void ThrowsArgumentException_WhenCategoryIsNotFound()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake = new Mock <IEfData>();
            var mapperFake = new Mock <IMappingProvider>();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            Category returnedCateogry = null;

            categoriesRepositoryFake.Setup(x => x.GetById(It.IsAny <object>())).Returns(returnedCateogry);

            // Act & Assert
            Assert.Throws <ArgumentException>(() =>
                                              service.Create("title", "description", Guid.NewGuid().ToString(), Language.C, 12, 1, new List <Test>()));
        }
Example #9
0
        public void Call_TestsRepositoryAdd_AsManyTimesAsTestsArePassed()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake   = new Mock <IEfData>();
            var mapperFake   = new Mock <IMappingProvider>();
            var categoryFake = new Mock <Category>();
            var tests        = new List <Test>
            {
                new Mock <Test>().Object,
                new Mock <Test>().Object,
                new Mock <Test>().Object
            };

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            categoriesRepositoryFake.Setup(x => x.GetById(It.IsAny <object>())).Returns(categoryFake.Object).Verifiable();
            testsRepositoryFake.Setup(x => x.Add(It.IsAny <Test>())).Verifiable();

            // Act
            service.Create("title", "description", Guid.NewGuid().ToString(), Language.C, 12, 1, tests);

            // Assert
            testsRepositoryFake.Verify(x => x.Add(It.IsAny <Test>()), Times.Exactly(tests.Count));
        }
        public ViewResult Details(int id)
        {
            var categoriesAll = _challengesService.GetChallengeCategories();

            var viewModel = new ChallengeDetailsViewModel();
            var challengeModel = new ChallengesService().GetChallengeDetails(id);
            viewModel.Challenge = challengeModel;

            var exists = _challengesService.CheckIfInMyChallenges(LayoutViewModel.ProviderUserKey, id);
            if (exists)
            {
                viewModel.PointsClaimed = _challengesService.ClaimedPoint(LayoutViewModel.ProviderUserKey, id);
            }

            var numOfImages = 0;
            if (challengeModel.ImageId1 != null)
            {
                numOfImages++;
            }
            if (challengeModel.ImageId2 != null)
            {
                numOfImages++;
            }
            if (challengeModel.ImageId3 != null)
            {
                numOfImages++;
            }
            if (challengeModel.ImageId4 != null)
            {
                numOfImages++;
            }

            viewModel.ShowSlider = numOfImages > 1;

            var challengeCategories = categoriesAll as IList<ChallengeCategory> ?? categoriesAll.ToList();

            viewModel.SelectedCategory = challengeCategories.FirstOrDefault(c => c.Id == challengeModel.ChallengeCategoryId);

            viewModel.Categories = challengeCategories;
            if (viewModel.SelectedCategory == null) return View("CategoryAction", viewModel);
            if (viewModel.SelectedCategory.ShortName.ToLower()
                .Equals(ChallengeCategoryEnum.Action.ToString().ToLower()))
            {
                return View("CategoryAction", viewModel);
            }
            if (viewModel.SelectedCategory.ShortName.ToLower()
                .Equals(ChallengeCategoryEnum.Pledge.ToString().ToLower()))
            {
                viewModel.Participating = exists && !viewModel.PointsClaimed;
                return View("CategoryPledge", viewModel);
            }
            if (viewModel.SelectedCategory.ShortName.ToLower()
                .Equals(ChallengeCategoryEnum.Learn.ToString().ToLower()))
            {
                return View("CategoryLearn", viewModel);
            }
            return View("CategoryAction", viewModel);
        }
Example #11
0
 public ChallengesContentViewModel(INavigationService navigationService, IPageDialogService dialogService)
 {
     _navigation    = navigationService;
     _dialogService = dialogService;
     //StarCommand = new Command(async () => { await OnStar(); });
     SelectEventCommand = new Command(async(i) => { await OnSelectEvent((ChallengesModel)i); });
     WelcomeMessage     = $"Welcome { App.UserProfileInfo.FirstName }";
     _challengesService = new ChallengesService();
     LoadChallenges();
 }
        public void Call_CategoriesRepository_WithCorrectId()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake   = new Mock <IEfData>();
            var mapperFake   = new Mock <IMappingProvider>();
            var categoryFake = new Mock <Category>();
            var categoryId   = Guid.NewGuid();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            categoriesRepositoryFake.Setup(x => x.GetById(categoryId)).Returns(categoryFake.Object).Verifiable();

            FileDecription passedFileDescription = null;

            fileDescriptionRepositoryFake.Setup(x => x.Add(It.IsAny <FileDecription>()))
            .Callback <FileDecription>(x => passedFileDescription = x);

            string fileName = "file1";
            string fileExt  = "exe";
            string filePath = "/";

            // Act
            var challenge = service.CreateWithFileDescription(
                "title",
                "description",
                categoryId.ToString(),
                Language.C,
                12,
                1,
                new List <Test>(),
                fileName,
                fileExt,
                filePath);

            // Assert
            Assert.AreEqual(passedFileDescription.FileName, fileName + challenge.Id);
            Assert.AreEqual(passedFileDescription.FileExtension, fileExt);
            Assert.AreEqual(passedFileDescription.FileSystemPath, filePath);
            Assert.AreEqual(passedFileDescription.ChallengeId, challenge.Id);
        }
Example #13
0
        public void Create_ChallengeWithCorrectData()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake   = new Mock <IEfData>();
            var mapperFake   = new Mock <IMappingProvider>();
            var categoryFake = new Mock <Category>();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            categoriesRepositoryFake.Setup(x => x.GetById(It.IsAny <object>())).Returns(categoryFake.Object).Verifiable();

            Challenge passedChallenge = null;

            challengesRepositoryFake.Setup(x => x.Add(It.IsAny <Challenge>()))
            .Callback <Challenge>(x => passedChallenge = x);

            string title       = "Strings";
            string description = "Draw!";
            var    categoryId  = Guid.NewGuid();
            var    lang        = Language.CPlusPlus;
            int    timeInMs    = 1;
            int    memoryInKb  = 1;
            var    tests       = new List <Test>();

            // Act
            service.Create(title, description, categoryId.ToString(), lang, timeInMs, memoryInKb, tests);

            // Assert
            Assert.AreEqual(title, passedChallenge.Title);
            Assert.AreEqual(description, passedChallenge.Description);
            Assert.AreEqual(lang, passedChallenge.Language);
            Assert.AreEqual(categoryId, passedChallenge.CategoryId);
            Assert.AreEqual(timeInMs, passedChallenge.TimeInMs);
            Assert.AreEqual(memoryInKb, passedChallenge.MemoryInKb);
        }
Example #14
0
        public void Update_Challenge_WithNewValues()
        {
            // Arrange
            var challengesRepositoryFake      = this.GetMockedRepository <Challenge>();
            var testsRepositoryFake           = this.GetMockedRepository <Test>();
            var fileDescriptionRepositoryFake = this.GetMockedRepository <FileDecription>();
            var categoriesRepositoryFake      = this.GetMockedRepository <Category>();
            var efDataFake = new Mock <IEfData>();
            var mapperFake = new Mock <IMappingProvider>();

            var service = new ChallengesService(
                challengesRepository: challengesRepositoryFake.Object,
                testsRepository: testsRepositoryFake.Object,
                fileDescriptionRepository: fileDescriptionRepositoryFake.Object,
                categoriesRepository: categoriesRepositoryFake.Object,
                efData: efDataFake.Object,
                mapper: mapperFake.Object);

            string challengeId   = Guid.NewGuid().ToString();
            var    challengeFake = new Mock <Challenge>();

            challengesRepositoryFake.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(challengeFake.Object);

            string title      = "title";
            var    lang       = Language.C;
            double timeInMs   = 1.1;
            int    memoryInKb = 1;

            // Act
            service.Update(challengeId, title, lang, timeInMs, memoryInKb);

            // Assert
            Assert.AreEqual(title, challengeFake.Object.Title);
            Assert.AreEqual(lang, challengeFake.Object.Language);
            Assert.AreEqual(timeInMs, challengeFake.Object.TimeInMs);
            Assert.AreEqual(memoryInKb, challengeFake.Object.MemoryInKb);
        }
 public ChallengesController()
 {
     _challengesService = new ChallengesService();
 }
 public ParticipantsController(ParticipantsService ps, ChallengesService cs)
 {
     _ps = ps;
     _cs = cs;
 }