public void TestGetGoals() { var options = new DbContextOptionsBuilder <MyPracticeJournalContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var db = new MyPracticeJournalContext(options)) { db.Goals.Add(new Goal { Name = "One" }); db.Goals.Add(new Goal { Name = "Two" }); db.Goals.Add(new Goal { Name = "Three" }); db.SaveChanges(); } // Use a clean instance of the context to run the test using (var context = new MyPracticeJournalContext(options)) { var service = new GoalService(_mapper, context); var result = service.GetGoal(1); Assert.IsNotNull(result); } }
public void ShouldUpdateGoalForUserBasedOnGoalIdAndUserId() { //Arrange int expectedId = 1; int expectedUserId = 1; Goal targetGoal = new Goal(expectedId, "Testing Goal", "Testing Goal", 50, GoalStatus.Open, false); Goal expectedGoal = new Goal(expectedId, "Testing Goal", "Testing Goal", 100, GoalStatus.Open, false); //Pretend the goal exists mockGoalRepository.Setup(gr => gr.GetGoalForUser(It.Is <int>(val => val == expectedId), It.Is <int>(val => val == expectedUserId))).Returns(targetGoal); //Pretend the update goals smoothly mockGoalRepository.Setup(gr => gr.UpdateGoal(It.Is <int>(val => val == expectedId), It.Is <Goal>(val => val.Equals(expectedGoal)))).Returns(expectedGoal); IGoalService goalService = new GoalService(mockGoalRepository.Object); //Act Goal savedGoal = goalService.UpdateGoal(expectedUserId, expectedId, expectedGoal); //Assert savedGoal.Should().NotBeNull(); savedGoal.Id.Should().Be(expectedId); savedGoal.Name.Should().Be(expectedGoal.Name); savedGoal.Description.Should().Be(expectedGoal.Description); savedGoal.Target.Should().Be(expectedGoal.Target); savedGoal.Status.Should().Be(expectedGoal.Status); savedGoal.IsDefault.Should().Be(expectedGoal.IsDefault); }
public void ShouldInsertGoalIntoDatabaseUsingValuesProvided() { //Arrange int expectedId = 151; GoalStatus defaultCreateStatus = GoalStatus.Open; Goal knownGoal = new Goal(0, "Testing Goal A", null, 100, GoalStatus.Open, false); //Setup the repository mockGoalRepository.Setup (gr => gr.CreateGoalForUser(It.IsAny <int>(), It.Is <Goal>(goal => goal.Equals(knownGoal)))) .Returns <int, Goal>((userId, goal) => { Goal testGoal = new Goal(expectedId, goal.Name, goal.Description, goal.Target, defaultCreateStatus, goal.IsDefault); return(testGoal); }); IGoalService goalService = new GoalService(mockGoalRepository.Object); //Act Goal savedGoal = goalService.CreateGoal(1, knownGoal); //Assert savedGoal.Should().NotBeNull(); savedGoal.Id.Should().Be(expectedId); savedGoal.Name.Should().Be(knownGoal.Name); savedGoal.Description.Should().Be(knownGoal.Description); savedGoal.Target.Should().Be(knownGoal.Target); savedGoal.Status.Should().Be(defaultCreateStatus); savedGoal.IsDefault.Should().Be(knownGoal.IsDefault); }
public void ShouldGetGoalsForUserBasedOnID() { //Arrange int knownUserId = 1; IEnumerable <Goal> knownGoals = new List <Goal>() { new Goal(3, "Testing Goal A", null, 103, GoalStatus.Open, false), new Goal(1, "Testing Goal B", null, 101, GoalStatus.Open, false), new Goal(10, "Testing Goal D", null, 110, GoalStatus.Cancelled, false), new Goal(5, "Testing Goal C", null, 105, GoalStatus.Complete, true), }; IEnumerable <Goal> orderedExpectedGoals = knownGoals.OrderBy(g => g.Id); //Setup the repository mockGoalRepository.Setup(gr => gr.GetGoalsForUser(It.Is <int>(v => v == knownUserId))).Returns(knownGoals); IGoalService goalService = new GoalService(mockGoalRepository.Object); //Act IEnumerable <Goal> returnedGoals = goalService.GetGoalsForUser(knownUserId); //Assert returnedGoals.Should().NotBeNull(); returnedGoals.Should().BeInAscendingOrder(g => g.Id); IEnumerable <int> orderedIds = orderedExpectedGoals.Select(g => g.Id); returnedGoals.Select(g => g.Id).Should().ContainInOrder(orderedIds); }
public ActionResult Create(BuildCreate model) { var userId = Guid.Parse(User.Identity.GetUserId()); CarService serviceCar = new CarService(userId); ViewBag.Cars = serviceCar.GetCars(); DecalService serviceDecal = new DecalService(userId); ViewBag.Decals = serviceDecal.GetDecals(); WheelsService serviceWheels = new WheelsService(userId); ViewBag.Wheelss = serviceWheels.GetWheels(); GoalService serviceGoal = new GoalService(userId); ViewBag.Goals = serviceGoal.GetGoals(); if (!ModelState.IsValid) { return(View(model)); } var service = CreateBuildService(); if (service.CreateBuild(model)) { TempData["SaveResult"] = "Your build was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Build could not be created."); return(View(model)); }
private GoalService CreateGoalService() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new GoalService(userId); return(service); }
public ActionResult Edit(int id) { var service = CreateBuildService(); var detail = service.GetBuildById(id); var userId = Guid.Parse(User.Identity.GetUserId()); CarService serviceCar2 = new CarService(userId); ViewBag.Cars = serviceCar2.GetCars(); DecalService serviceDecal2 = new DecalService(userId); ViewBag.Decals = serviceDecal2.GetDecals(); WheelsService serviceWheels2 = new WheelsService(userId); ViewBag.Wheelss = serviceWheels2.GetWheels(); GoalService serviceGoal2 = new GoalService(userId); ViewBag.Goals = serviceGoal2.GetGoals(); var model = new BuildEdit { BuildID = detail.BuildID, BuildName = detail.BuildName, }; return(View(model)); }
//public IHttpActionResult GetAll() //{ // GoalService goalService = CreateGoalService(); // var goals = goalService.GetGoal(); // return Ok(goals); //} public IHttpActionResult Get(int id) { GoalService goalService = CreateGoalService(); var goal = goalService.GetGoalByID(id); return(Ok(goal)); }
public void TestInit() { activities = new List <Activity> { new Activity { Id = 1, Name = "Walking", Duration = 800, UserId = "2a7f80bb-5e84-4468-88ad-804f848d8f20", StartTime = new DateTime(2014, 2, 15), Type = ActivityType.Walking, Distance = 1200, Steps = 430 }, new Activity { Id = 2, Name = "Walking", Duration = 500, UserId = "2a7f80bb-5e84-4468-88ad-804f848d8f20", StartTime = new DateTime(2015, 3, 15), Type = ActivityType.Walking, Distance = 900, Steps = 370 }, new Activity { Id = 3, Name = "Jogging", Duration = 1000, UserId = "2a7f80bb-5b36-4468-88ad-804f848d8f20", StartTime = new DateTime(2015, 3, 18), Type = ActivityType.Jogging, Distance = 1500, Steps = 480 }, new Activity { Id = 4, Name = "Biking", Duration = 1500, UserId = "2a7f80bb-5b36-4468-88ad-804f848d8f20", StartTime = new DateTime(2015, 4, 2), Type = ActivityType.Biking, Distance = 2000, Steps = 600 }, new Activity { Id = 5, Name = "Running", Duration = 400, UserId = "2a7f80bb-3r56-4468-88ad-804f848d8f20", StartTime = new DateTime(2015, 4, 8), Type = ActivityType.Running, Distance = 600, Steps = 300 }, }; var mockContext = new Mock <ApplicationDbContext>(); var activityRepo = new Mock <IActivityRepository>(); activityRepo.Setup(a => a.ReadAll()).Returns(activities); activityRepo.Setup(a => a.GetById(It.IsAny <long>())) .Returns <long>(i => Task.FromResult(activities.Where(x => x.Id == i).Single())); activityRepo.Setup(a => a.GetByUser(It.IsAny <string>())) .Returns <string>(i => activities.Where(x => x.UserId == i).ToList()); activityRepo.Setup(a => a.GetActivitiesByDateRange(It.IsAny <DateTime>(), It.IsAny <DateTime>())) .Returns <DateTime, DateTime>((i, j) => activities.Where(x => DateTime.Compare(x.StartTime, i) >= 0 && DateTime.Compare(x.StartTime, j) <= 0).ToList()); activityRepo.Setup(a => a.GetUserActivitiesByDateRange(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())) .Returns <string, DateTime, DateTime>((s, i, j) => activities.Where(x => DateTime.Compare(x.StartTime, i) >= 0 && DateTime.Compare(x.StartTime, j) <= 0 && x.UserId == s).ToList()); activityRepo.Setup(a => a.GetActivitiesByDay(It.IsAny <DateTime>())) .Returns <DateTime>(i => activities.Where(x => DateTime.Compare(x.StartTime, i) == 0).ToList()); activityRepo.Setup(a => a.GetUserActivitiesByDay(It.IsAny <String>(), It.IsAny <DateTime>())) .Returns <string, DateTime>((s, i) => activities.Where(x => DateTime.Compare(x.StartTime, i) == 0 && x.UserId == s).ToList()); activityRepo.Setup(a => a.GetActivitiesByMonth(It.IsAny <DateTime>())) .Returns <DateTime>(i => activities.Where(x => x.StartTime.Month == i.Month).ToList()); activityRepo.Setup(a => a.GetActivitiesByYear(It.IsAny <int>())) .Returns <int>(i => activities.Where(x => x.StartTime.Year == i).ToList()); var unitOfWork = new Mock <IUnitOfWork>(); var goalRepo = new Mock <IGoalRepository>(); var feedEventRepo = new Mock <IFeedEventRepository>(); var membershipRepo = new Mock <IMembershipRepository>(); var moodRepo = new Mock <IMoodRepository>(); var groupRepo = new Mock <IGroupRepository>(); var badgeRepo = new Mock <IBadgeRepository>(); var userRepo = new Mock <IUserRepository>(); var userBadgeService = new Mock <IUserBadgeService>(); IFeedEventService feedService = new FeedEventService(feedEventRepo.Object, membershipRepo.Object, moodRepo.Object, groupRepo.Object, badgeRepo.Object, unitOfWork.Object); IGoalService goalService = new GoalService(goalRepo.Object, activityRepo.Object, feedService, unitOfWork.Object); IFeedEventService feedEventService = new FeedEventService(feedEventRepo.Object, membershipRepo.Object, moodRepo.Object, groupRepo.Object, badgeRepo.Object, unitOfWork.Object); IMembershipService membershipService = new MembershipService(membershipRepo.Object, feedEventService, userBadgeService.Object, unitOfWork.Object); IUserService userService = new UserService(userRepo.Object, membershipService, unitOfWork.Object); activityService = new ActivityService(activityRepo.Object, goalService, feedEventService, userService, userBadgeService.Object, unitOfWork.Object); }
public StatsController(UserService userService, GoalService goalService, TogglHelper TogglHelper, ResponseHelper responseHelper) { _userService = userService; _goalService = goalService; _TogglHelper = TogglHelper; _responseHelper = responseHelper; }
// GET: Goal public ActionResult Index() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new GoalService(userId); var model = service.GetGoals(); return(View(model)); }
public async Task <IActionResult> Delete([FromRoute] Guid goalId) { var goalDeleted = await GoalService.DeleteAsync(goalId); return(goalDeleted ? NoContent() : StatusCode((int)HttpStatusCode.NotModified)); }
public async Task <IActionResult> Get() { var goals = await GoalService.GetAllAsync(); var goalsModels = GoalMapper.Map(goals); return(Ok(goalsModels)); }
public TeamController(TeamService teamService, UserService userService, TaskService taskService, GoalService goalService) { _teamService = teamService; _userService = userService; _taskService = taskService; _goalService = goalService; }
public DailyGoalController(UserService userService, GoalService goalService, TogglHelper TogglHelper, IValidator <Goal> createGoalValidator, ResponseHelper responseHelper) { _userService = userService; _goalService = goalService; _TogglHelper = TogglHelper; _createGoalValidator = createGoalValidator; _responseHelper = responseHelper; }
public GoalServiceTests() { this.enumParseService = new Mock <IEnumParseService>(); this.calendarService = new Mock <ICalendarService>(); this.colorService = new Mock <IColorService>(); this.habitService = new Mock <IHabitService>(); this.goalRepository = new Mock <IDeletableEntityRepository <Goal> >(); this.goalService = new GoalService(this.goalRepository.Object, this.enumParseService.Object, this.calendarService.Object, this.colorService.Object, this.habitService.Object); }
public ActionResult PutMoney(double Amount, int putOnId, string catType) { //TODO catType убрать GoalService goalService = new GoalService(putOnId); goalService.PutMoney(Amount); return(RedirectToAction("MyBudget", "Transactions")); }
public async Task <IActionResult> GetById([FromRoute] Guid goalId) { var goal = await GoalService.GetAsync(goalId); if (goal == null) { return(NotFound()); } var goalModel = GoalMapper.Map(goal); return(Ok(goalModel)); }
public async Task DeleteAsync_WhenGoalIdGuidEmpty_ShouldReturnFalse( GoalService sut) { // Arrange var goalId = Guid.Empty; // Act var result = await sut.DeleteAsync(goalId); // Asserts result.Should().BeFalse(); await sut.GoalRepository.DidNotReceive().DeleteAsync(Arg.Any <Guid>()); }
public async Task DeleteAsync_WhenDeleteFails_ShouldReturnCorrectly( Guid goalId, GoalService sut) { // Arrange sut.GoalRepository.DeleteAsync(Arg.Is(goalId)).Returns(false); // Act var result = await sut.DeleteAsync(goalId); // Asserts result.Should().BeFalse(); await sut.GoalRepository.Received(1).DeleteAsync(Arg.Is(goalId)); }
public Services(string path) { FileManager = new FileManager(path); BudgetService = new BudgetService(FileManager); CartService = new CartService(FileManager); GoalService = new GoalService(FileManager); HistoryService = new HistoryService(FileManager); PaymentService = new PaymentService(FileManager); SchedulerService = new SchedulerService(FileManager); ShoppingService = new ShoppingService(); StatisticsService = new StatisticsService(FileManager); VerificationService = new VerificationService(); CurrentInfoHolder = new CurrentInfoHolder(); }
public void ShouldThrowANullReferenceExceptionWhenGoalWithIDDoesNotExist() { //Arrange int expectedGoalID = 1; mockGoalRepository.Setup(gr => gr.GetGoal(It.Is <int>(val => val == expectedGoalID))).Returns(null as Goal); IGoalService service = new GoalService(mockGoalRepository.Object); //Act Action failAction = () => service.GetGoal(expectedGoalID); //Assert failAction.Should().Throw <ArgumentOutOfRangeException>(); }
public async Task DeleteAsync_ShouldCallMethodCorrectly( Guid goalId, GoalService sut) { // Arrange sut.GoalRepository.DeleteAsync(Arg.Is(goalId)).Returns(true); // Act var result = await sut.DeleteAsync(goalId); // Asserts result.Should().BeTrue(); await sut.GoalRepository.Received(1).DeleteAsync(Arg.Is(goalId)); }
public async Task GetAsync_WhenGoalIdEmpty_ShouldReturnNull( GoalService sut) { // Arrange var goalId = Guid.Empty; // Act var result = await sut.GetAsync(goalId); // Asserts result.Should().BeNull(); await sut.GoalQuery.DidNotReceive().GetAsync( Arg.Any <Guid>()); }
public async Task GetAsync_WhenGoalNull_ShouldReturnNull( Guid goalId, GoalService sut) { // Arrange sut.GoalQuery.GetAsync(Arg.Is(goalId)).ReturnsNull(); // Act var result = await sut.GetAsync(goalId); // Asserts result.Should().BeNull(); await sut.GoalQuery.Received(1).GetAsync(Arg.Is(goalId)); }
public async Task <IActionResult> Put( [FromBody] GoalModel goalModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var goal = GoalMapper.Map(goalModel); var goalUpdated = await GoalService.UpdateAsync(goal); return(goalUpdated ? NoContent() : StatusCode((int)HttpStatusCode.NotModified)); }
public async Task UpdateAsync_WhenFails_ShouldCallMethodCorrectly( Goal goal, GoalService sut) { // Arrange goal.Id = Guid.Empty; sut.GoalRepository.UpdateAsync(Arg.Is(goal)).Returns(false); // Act var result = await sut.UpdateAsync(goal); // Asserts result.Should().BeFalse(); await sut.GoalRepository.Received(1).UpdateAsync(Arg.Is(goal)); }
public ActionResult Create(GoalCreate model) { var userId = User.Identity.GetUserId(); model.CurrentUserId = userId; if (!ModelState.IsValid) { return(View(model)); } else { GoalService service = CreateGoalService(); service.CreateGoal(model); return(RedirectToAction("Index")); } }
public async Task CreateAsync_WhenSuccess_ShouldCallMethodCorrectly( Goal goal, GoalService sut) { // Arrange goal.Id = Guid.Empty; sut.GoalRepository.CreateAsync(Arg.Is(goal)).Returns(true); // Act var result = await sut.CreateAsync(goal); // Asserts result.Should().BeEquivalentTo(goal); await sut.GoalRepository.Received(1) .CreateAsync(Arg.Is <Goal>(x => x.Id != Guid.Empty)); }
public async Task GetAllAsync_ShouldCallMethodCorrectly( List <Goal> goals, GoalService sut) { // Arrange sut.GoalQuery.GetAllAsync().Returns(goals); // Act var result = await sut.GetAllAsync(); // Asserts result.Should().NotBeNull(); result.Should().BeEquivalentTo(goals); result.Should().BeOfType <List <Goal> >(); await sut.GoalQuery.Received(1).GetAllAsync(); }