public async Task GetAttemptsAsync_GivenInvalidGoalId_ShouldReturnNotFound()
        {
            // Arrange.
            var attemptStore = Substitute.For <IGoalAttemptStore>();
            var goalStore    = Substitute.For <IGoalStore>();
            var tokenStore   = Substitute.For <ITokenStore>();
            var userStore    = Substitute.For <IUserStore>();
            var log          = Substitute.For <ILogger>();
            var testObject   = new GoalAttemptController(attemptStore, goalStore, tokenStore, userStore, log);

            testObject.ControllerContext = new HttpControllerContext
            {
                Request = new HttpRequestMessage()
            };
            testObject.ControllerContext.Request.Headers.Add("auth", Guid.NewGuid().ToString());

            tokenStore.GetExistingValidTokenByGuidAsync(Arg.Any <Guid>()).Returns(new Token());
            userStore.GetUserAsync(Arg.Any <Token>()).Returns(new User());

            // Act.
            var result = await testObject.GetAttemptsAsync(123);

            // Assert.
            Assert.IsInstanceOf <NotFoundResult>(result);
        }
        public async Task GetAttemptsAsync_GivenValidGoal_ShouldReturnAttempts()
        {
            // Arrange.
            MapperConfig.Initialise();

            var attemptStore = Substitute.For <IGoalAttemptStore>();
            var goalStore    = Substitute.For <IGoalStore>();
            var tokenStore   = Substitute.For <ITokenStore>();
            var userStore    = Substitute.For <IUserStore>();
            var log          = Substitute.For <ILogger>();
            var testObject   = new GoalAttemptController(attemptStore, goalStore, tokenStore, userStore, log);

            testObject.ControllerContext = new HttpControllerContext
            {
                Request = new HttpRequestMessage()
            };
            testObject.ControllerContext.Request.Headers.Add("auth", Guid.NewGuid().ToString());

            tokenStore.GetExistingValidTokenByGuidAsync(Arg.Any <Guid>()).Returns(new Token());
            userStore.GetUserAsync(Arg.Any <Token>()).Returns(new User());
            goalStore.GetGoalAsync(123).Returns(new Goal());

            var attempts = new List <GoalAttempt>
            {
                new GoalAttempt
                {
                    Id        = 1,
                    GoalId    = 123,
                    Timestamp = DateTime.Now
                },
                new GoalAttempt
                {
                    Id        = 2,
                    GoalId    = 123,
                    Timestamp = DateTime.Now
                }
            };

            attemptStore.GetAttempts(123).Returns(
                new MockDbAsyncEnumerable <GoalAttempt>(attempts));

            // Act.
            var result = await testObject.GetAttemptsAsync(123);

            // Assert.
            var okResult = result as OkNegotiatedContentResult <string>;

            Assert.NotNull(okResult);

            var attemptDatas = new List <GoalAttemptData>();

            attempts.ForEach(a => attemptDatas.Add(Mapper.Map <GoalAttemptData>(a)));

            Assert.AreEqual(JsonConvert.SerializeObject(attemptDatas), okResult.Content);
        }
        public async Task GetAttemptsAsync_GivenNoHeaderToken_ShouldReturnBadRequest()
        {
            // Arrange.
            var attemptStore = Substitute.For <IGoalAttemptStore>();
            var goalStore    = Substitute.For <IGoalStore>();
            var tokenStore   = Substitute.For <ITokenStore>();
            var userStore    = Substitute.For <IUserStore>();
            var log          = Substitute.For <ILogger>();
            var testObject   = new GoalAttemptController(attemptStore, goalStore, tokenStore, userStore, log);

            // Act.
            var result = await testObject.GetAttemptsAsync(123);

            // Assert.
            Assert.IsInstanceOf <BadRequestErrorMessageResult>(result);
        }