public void SelectUptoThreeActivities_Below_Three_Return_False_Test() { IUserService _userService = new UserService(_context); IActivityService _activityService = new ActivityService(_context); IUserActivityService _userActivityService = new UserActivityService(_context); ApplicationUser user = new ApplicationUser { UserName = "******" }; bool userSaveResult = _userService.AddUser(user); RecretionalActivity kayaking = new RecretionalActivity { ActivityName = "Kayaking" }; _activityService.AddAnActivity(kayaking); RecretionalActivity camping = new RecretionalActivity { ActivityName = "Camping" }; _activityService.AddAnActivity(camping); if (userSaveResult) { _userActivityService.ChooseAnActivity(user, kayaking); _userActivityService.ChooseAnActivity(user, camping); } bool selectUpToThreeActivities = _userActivityService.CanChooseUptoThreeActivities(user); Assert.IsFalse(selectUpToThreeActivities); }
public void SetRankAnActivityTest() { IUserService _userService = new UserService(_context); IActivityService _activityService = new ActivityService(_context); IUserActivityService _userActivityService = new UserActivityService(_context); ApplicationUser user = new ApplicationUser { UserName = "******" }; bool userSaveResult = _userService.AddUser(user); RecretionalActivity kayaking = new RecretionalActivity { ActivityName = "Kayaking" }; _activityService.AddAnActivity(kayaking); RecretionalActivity camping = new RecretionalActivity { ActivityName = "Camping" }; _activityService.AddAnActivity(camping); if (userSaveResult) { _userActivityService.ChooseAnActivity(user, kayaking); _userActivityService.ChooseAnActivity(user, camping); } bool setKayakingAsFiveStarRatingResult = _userActivityService.SetRankAnActivity(user, kayaking, Rating.fiveStar); bool setCampingAsFourStarRatingResult = _userActivityService.SetRankAnActivity(user, camping, Rating.fourStar); Assert.IsTrue(setKayakingAsFiveStarRatingResult); Assert.IsTrue(setCampingAsFourStarRatingResult); }
public bool SetRankAnActivity(ApplicationUser user, RecretionalActivity activity, Rating rating) { var userActivity = _context.UserActivityRankings .Include(p => p.User) .Include(p => p.Activity) .FirstOrDefault(x => x.User.Id == user.Id && x.Activity.ActivityId == activity.ActivityId); userActivity.Rating = rating; return(SaveChanges()); }
public void AddActivityTest() { IActivityService _activityService = new ActivityService(_context); RecretionalActivity activity = new RecretionalActivity { ActivityName = "Kayaking" }; bool result = _activityService.AddAnActivity(activity); Assert.IsTrue(result); }
public bool UpdateActivity(RecretionalActivity activity) { var existingActivity = GetActivityById(activity.ActivityId); if (existingActivity != null) { existingActivity.ActivityName = activity.ActivityName; } return(SaveChanges()); //_context.Entry(activity).State = EntityState.Modified; //return SaveChanges(); }
public IActionResult CreateActivity(RecretionalActivity recretionalActivity) { try { _activityService.AddAnActivity(recretionalActivity); return(RedirectToAction("Index")); } catch (Exception e) { return(View()); } }
public bool ChooseAnActivity(ApplicationUser user, RecretionalActivity activity) { if (!CanChooseUptoThreeActivities(user)) { UserActivityRanking userActivityRanking = new UserActivityRanking { User = user, Activity = activity }; _context.UserActivityRankings.Add(userActivityRanking); return(SaveChanges()); } return(false); }
public IActionResult EditActivity(RecretionalActivity recretionalActivity) { try { bool result = _activityService.UpdateActivity(recretionalActivity); if (result) { return(RedirectToAction("Index")); } else { return(View(recretionalActivity)); } } catch (Exception e) { return(View(recretionalActivity)); } }
public void ChooseAnActivityTest() { IUserService _userService = new UserService(_context); IActivityService _activityService = new ActivityService(_context); IUserActivityService _userActivityService = new UserActivityService(_context); ApplicationUser user = new ApplicationUser { UserName = "******" }; bool userSaveResult = _userService.AddUser(user); RecretionalActivity activity = new RecretionalActivity { ActivityName = "Kayaking" }; bool activitySaveResult = _activityService.AddAnActivity(activity); bool selectAnActivityResult = false; if (userSaveResult && activitySaveResult) { selectAnActivityResult = _userActivityService.ChooseAnActivity(user, activity); } Assert.IsTrue(selectAnActivityResult); }
public bool AddAnActivity(RecretionalActivity activity) { _context.Activities.Add(activity); return(SaveChanges()); }
public IActionResult Create() { RecretionalActivity recretionalActivity = new RecretionalActivity(); return(View(recretionalActivity)); }
private static void SaveInitData(ApplicationDbContext context) { if (context.Activities.Count() > 0) { return; } IUserActivityService _userActivityService = new UserActivityService(context); IActivityService _activityService = new ActivityService(context); IRegionService _regionService = new RegionService(context); IUserService _userService = new UserService(context); RecretionalActivity kayaking = new RecretionalActivity { ActivityName = "Kayaking" }; _activityService.AddAnActivity(kayaking); RecretionalActivity camping = new RecretionalActivity { ActivityName = "Camping" }; _activityService.AddAnActivity(camping); RecretionalActivity fishing = new RecretionalActivity { ActivityName = "Fishing" }; _activityService.AddAnActivity(fishing); RecretionalActivity hiking = new RecretionalActivity { ActivityName = "Hiking" }; _activityService.AddAnActivity(hiking); RecretionalActivity sail = new RecretionalActivity { ActivityName = "Sailing" }; _activityService.AddAnActivity(sail); RecretionalActivity biking = new RecretionalActivity { ActivityName = "Biking" }; _activityService.AddAnActivity(biking); ////////////////////// Region japan = new Region { RegionName = "Japan" }; Region usa = new Region { RegionName = "USA" }; Region canada = new Region { RegionName = "Canada" }; Region turk = new Region { RegionName = "Turkey" }; Region india = new Region { RegionName = "India" }; Region pak = new Region { RegionName = "Pakistan" }; Region nepal = new Region { RegionName = "Nepal" }; _regionService.AddRegion(japan); _regionService.AddRegion(usa); _regionService.AddRegion(canada); _regionService.AddRegion(turk); _regionService.AddRegion(india); ApplicationUser safa = new ApplicationUser { UserName = "******", Region = japan, DateOfBirth = new DateTime(2000, 01, 01) }; ApplicationUser alif = new ApplicationUser { UserName = "******", Region = japan, DateOfBirth = new DateTime(2001, 01, 01) }; ApplicationUser hamza = new ApplicationUser { UserName = "******", Region = japan, DateOfBirth = new DateTime(2002, 01, 01) }; ApplicationUser kabir = new ApplicationUser { UserName = "******", Region = japan, DateOfBirth = new DateTime(1990, 01, 01) }; ApplicationUser saif = new ApplicationUser { UserName = "******", Region = canada, DateOfBirth = new DateTime(1998, 01, 01) }; ApplicationUser salman = new ApplicationUser { UserName = "******", Region = canada, DateOfBirth = new DateTime(1995, 01, 01) }; ApplicationUser rubel = new ApplicationUser { UserName = "******", Region = canada, DateOfBirth = new DateTime(1992, 01, 01) }; ApplicationUser talha = new ApplicationUser { UserName = "******", Region = usa, DateOfBirth = new DateTime(1980, 01, 01) }; ApplicationUser rahim = new ApplicationUser { UserName = "******", Region = usa, DateOfBirth = new DateTime(1985, 01, 01) }; ApplicationUser karim = new ApplicationUser { UserName = "******", Region = pak, DateOfBirth = new DateTime(1970, 01, 01) }; ApplicationUser polash = new ApplicationUser { UserName = "******", Region = nepal, DateOfBirth = new DateTime(1988, 01, 01) }; ApplicationUser kamal = new ApplicationUser { UserName = "******", Region = nepal, DateOfBirth = new DateTime(1978, 01, 01) }; _userService.AddUser(safa); _userService.AddUser(alif); _userService.AddUser(hamza); _userService.AddUser(kabir); _userService.AddUser(saif); _userService.AddUser(salman); _userService.AddUser(rubel); _userService.AddUser(talha); _userService.AddUser(rahim); _userService.AddUser(karim); _userService.AddUser(polash); _userService.AddUser(kamal); _userActivityService.ChooseAnActivity(safa, kayaking); _userActivityService.ChooseAnActivity(safa, camping); _userActivityService.ChooseAnActivity(safa, fishing); _userActivityService.ChooseAnActivity(alif, kayaking); _userActivityService.ChooseAnActivity(alif, fishing); _userActivityService.ChooseAnActivity(alif, biking); _userActivityService.ChooseAnActivity(kamal, biking); _userActivityService.ChooseAnActivity(kamal, hiking); _userActivityService.ChooseAnActivity(kamal, sail); _userActivityService.ChooseAnActivity(kabir, biking); _userActivityService.ChooseAnActivity(kabir, camping); _userActivityService.ChooseAnActivity(kabir, sail); _userActivityService.ChooseAnActivity(polash, hiking); _userActivityService.ChooseAnActivity(polash, kayaking); _userActivityService.ChooseAnActivity(karim, biking); _userActivityService.ChooseAnActivity(karim, fishing); _userActivityService.SetRankAnActivity(safa, kayaking, Rating.fiveStar); _userActivityService.SetRankAnActivity(safa, camping, Rating.fourStar); _userActivityService.SetRankAnActivity(safa, fishing, Rating.threeStar); _userActivityService.SetRankAnActivity(alif, kayaking, Rating.threeStar); _userActivityService.SetRankAnActivity(alif, fishing, Rating.twoStar); _userActivityService.SetRankAnActivity(alif, biking, Rating.oneStar); _userActivityService.SetRankAnActivity(kamal, biking, Rating.threeStar); _userActivityService.SetRankAnActivity(kamal, sail, Rating.twoStar); _userActivityService.SetRankAnActivity(kamal, hiking, Rating.oneStar); _userActivityService.SetRankAnActivity(kabir, biking, Rating.threeStar); _userActivityService.SetRankAnActivity(kabir, camping, Rating.twoStar); _userActivityService.SetRankAnActivity(kabir, sail, Rating.oneStar); _userActivityService.SetRankAnActivity(polash, hiking, Rating.fourStar); _userActivityService.SetRankAnActivity(polash, kayaking, Rating.twoStar); _userActivityService.SetRankAnActivity(karim, biking, Rating.twoStar); _userActivityService.SetRankAnActivity(karim, fishing, Rating.fiveStar); }
public void GetTopFiveRankActivityTest() { IUserService _userService = new UserService(_context); IActivityService _activityService = new ActivityService(_context); IUserActivityService _userActivityService = new UserActivityService(_context); RecretionalActivity kayaking = new RecretionalActivity { ActivityName = "Kayaking" }; _activityService.AddAnActivity(kayaking); RecretionalActivity camping = new RecretionalActivity { ActivityName = "Camping" }; _activityService.AddAnActivity(camping); RecretionalActivity fishing = new RecretionalActivity { ActivityName = "Fishing" }; _activityService.AddAnActivity(fishing); RecretionalActivity hiking = new RecretionalActivity { ActivityName = "Hiking" }; _activityService.AddAnActivity(hiking); RecretionalActivity sail = new RecretionalActivity { ActivityName = "Sailing" }; _activityService.AddAnActivity(sail); RecretionalActivity biking = new RecretionalActivity { ActivityName = "Biking" }; _activityService.AddAnActivity(biking); ////////////////////// ApplicationUser saiful = new ApplicationUser { UserName = "******" }; _userService.AddUser(saiful); ApplicationUser alif = new ApplicationUser { UserName = "******" }; _userService.AddUser(alif); ApplicationUser kamal = new ApplicationUser { UserName = "******" }; _userService.AddUser(kamal); ApplicationUser jamal = new ApplicationUser { UserName = "******" }; _userService.AddUser(jamal); _userActivityService.ChooseAnActivity(saiful, kayaking); _userActivityService.ChooseAnActivity(saiful, camping); _userActivityService.ChooseAnActivity(saiful, fishing); _userActivityService.ChooseAnActivity(alif, kayaking); _userActivityService.ChooseAnActivity(alif, fishing); _userActivityService.ChooseAnActivity(alif, biking); _userActivityService.ChooseAnActivity(kamal, biking); _userActivityService.ChooseAnActivity(kamal, hiking); _userActivityService.ChooseAnActivity(kamal, sail); _userActivityService.ChooseAnActivity(jamal, biking); _userActivityService.ChooseAnActivity(jamal, camping); _userActivityService.ChooseAnActivity(jamal, sail); _userActivityService.SetRankAnActivity(saiful, kayaking, Rating.fiveStar); _userActivityService.SetRankAnActivity(saiful, camping, Rating.fourStar); _userActivityService.SetRankAnActivity(saiful, fishing, Rating.threeStar); _userActivityService.SetRankAnActivity(alif, kayaking, Rating.threeStar); _userActivityService.SetRankAnActivity(alif, fishing, Rating.twoStar); _userActivityService.SetRankAnActivity(alif, biking, Rating.oneStar); _userActivityService.SetRankAnActivity(kamal, biking, Rating.threeStar); _userActivityService.SetRankAnActivity(kamal, sail, Rating.twoStar); _userActivityService.SetRankAnActivity(kamal, hiking, Rating.oneStar); _userActivityService.SetRankAnActivity(jamal, biking, Rating.threeStar); _userActivityService.SetRankAnActivity(jamal, camping, Rating.twoStar); _userActivityService.SetRankAnActivity(jamal, sail, Rating.oneStar); // kayaking = 5 + 3 = 8, campinig = 4+2=6, fishing=3+2=5, biking=1+3+3=7 // hiking = 2, sailing=2+1=3,golging= 1 var topActivity = _userActivityService.GetTopFiveRankActivity(); Assert.IsNotNull(topActivity); Assert.AreEqual(kayaking.ActivityName, topActivity.FirstOrDefault().Activity.ActivityName); Assert.AreEqual(biking.ActivityName, topActivity.Skip(1).FirstOrDefault().Activity.ActivityName); Assert.AreEqual(camping.ActivityName, topActivity.Skip(2).FirstOrDefault().Activity.ActivityName); Assert.AreEqual(fishing.ActivityName, topActivity.Skip(3).FirstOrDefault().Activity.ActivityName); Assert.AreEqual(sail.ActivityName, topActivity.LastOrDefault().Activity.ActivityName); }
public void GetTopOneRankActivityTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("testdb1").Options; _context = new ApplicationDbContext(options); IUserService _userService = new UserService(_context); IActivityService _activityService = new ActivityService(_context); IUserActivityService _userActivityService = new UserActivityService(_context); ApplicationUser faisal = new ApplicationUser { UserName = "******" }; _userService.AddUser(faisal); ApplicationUser jamil = new ApplicationUser { UserName = "******" }; _userService.AddUser(jamil); RecretionalActivity carRaicing = new RecretionalActivity { ActivityName = "Car Raicing" }; _activityService.AddAnActivity(carRaicing); RecretionalActivity snowSkiing = new RecretionalActivity { ActivityName = "Snow Skiing" }; _activityService.AddAnActivity(snowSkiing); RecretionalActivity golfing = new RecretionalActivity { ActivityName = "Golfing" }; _activityService.AddAnActivity(golfing); ////////////////////// _userActivityService.ChooseAnActivity(faisal, carRaicing); _userActivityService.ChooseAnActivity(faisal, snowSkiing); _userActivityService.ChooseAnActivity(faisal, golfing); _userActivityService.ChooseAnActivity(jamil, carRaicing); _userActivityService.ChooseAnActivity(jamil, golfing); _userActivityService.ChooseAnActivity(jamil, snowSkiing); _userActivityService.SetRankAnActivity(faisal, carRaicing, Rating.fiveStar); _userActivityService.SetRankAnActivity(faisal, snowSkiing, Rating.fourStar); _userActivityService.SetRankAnActivity(faisal, golfing, Rating.threeStar); _userActivityService.SetRankAnActivity(jamil, carRaicing, Rating.threeStar); _userActivityService.SetRankAnActivity(jamil, snowSkiing, Rating.twoStar); _userActivityService.SetRankAnActivity(jamil, golfing, Rating.oneStar); var topActivity = _userActivityService.GetTopOneRankActivity(); Assert.IsNotNull(topActivity); Assert.AreEqual(carRaicing.ActivityName, topActivity.ActivityName); }