Beispiel #1
0
        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);
        }
Beispiel #2
0
        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 void TestCreateGoal()
        {
            var options = new DbContextOptionsBuilder <MyPracticeJournalContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var db = new  MyPracticeJournalContext(options))
            {
                var goalService = new GoalService(_mapper, db);
                var goalDto     = new GoalDto
                {
                    Name        = "One",
                    Description = "Desc One"
                };
                goalService.CreateGoal(goalDto);
            }

            using (var db = new  MyPracticeJournalContext(options))
            {
                Assert.AreEqual(1, db.Goals.Count());
                Assert.AreEqual("One", db.Goals.Single().Name);
            }
        }
 public Goal CreateGoal(Goal goal, string teamName)
 {
     _goalService.CreateGoal(goal, teamName);
     return(goal);
 }