public StatsController(UserService userService, GoalService goalService, TogglHelper TogglHelper, ResponseHelper responseHelper) { _userService = userService; _goalService = goalService; _TogglHelper = TogglHelper; _responseHelper = responseHelper; }
public DailyGoalController(UserService userService, GoalService goalService, TogglHelper TogglHelper, IValidator <Goal> createGoalValidator, ResponseHelper responseHelper) { _userService = userService; _goalService = goalService; _TogglHelper = TogglHelper; _createGoalValidator = createGoalValidator; _responseHelper = responseHelper; }
public void GivenEmptyGoalObjectWithValidUserObject_WhenGetGoalResultForProjectIsEnvoked_ThenReturnsNull() { // Arrange var mockConfiguration = new Mock <IConfiguration>(); var mockConfigurationHelper = new Mock <ConfigurationHelper>(mockConfiguration.Object); var mockCryptHelper = new Mock <CryptHelper>(mockConfigurationHelper.Object); var mockTogglHttpClient = new Mock <TogglHttpClient>(mockCryptHelper.Object); mockTogglHttpClient.Setup(s => s.PostAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <HttpContent>())) .ReturnsAsync(string.Empty); var sut = new TogglHelper(mockTogglHttpClient.Object); // Act var result = sut.GetGoalResultForProject(_emptyGoal, _validUser, _startDate, _endDate); // Assert Assert.Null(result); }
public void GivenValidObjectsWithTogglResultData_WhenGetGoalResultForProjectIsEnvoked_ThenReturnsParsedResults() { // Arrange var validJsonResponseString = "{ \"seconds\": 12360, \"rates\": null, \"graph\": [ { \"seconds\": 0, \"by_rate\": null }, { \"seconds\": 1560, \"by_rate\": null }, { \"seconds\": 0, \"by_rate\": null }, { \"seconds\": 3600, \"by_rate\": null }, { \"seconds\": 0, \"by_rate\": null }, { \"seconds\": 7200, \"by_rate\": null }, { \"seconds\": 0, \"by_rate\": null } ], \"resolution\": \"day\"}"; var mockConfiguration = new Mock <IConfiguration>(); var mockConfigurationHelper = new Mock <ConfigurationHelper>(mockConfiguration.Object); var mockCryptHelper = new Mock <CryptHelper>(mockConfigurationHelper.Object); var mockTogglHttpClient = new Mock <TogglHttpClient>(mockCryptHelper.Object); mockTogglHttpClient.Setup(s => s.PostAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <HttpContent>())) .ReturnsAsync(validJsonResponseString); var sut = new TogglHelper(mockTogglHttpClient.Object); // Act var result = sut.GetGoalResultForProject(_validGoal, _validUser, _startDate, _endDate); var resultTrackiedlist = result.TrackedEntryDetails.ToList(); // Assert Assert.NotNull(result); Assert.Equal(_validGoal.Id, result.GoalId); Assert.Equal(_validGoal.GoalFriendlyName, result.GoalFriendlyName); // We have all tracked entries Assert.NotEmpty(result.TrackedEntryDetails); Assert.Equal(7, result.TrackedEntryDetails.Count()); // Using our sample result the 2nd entry should match the following Assert.True(resultTrackiedlist[1].GoalMet); Assert.Equal("1560000", resultTrackiedlist[1].GoalTrackedDurationInMs); Assert.Equal("00h:26m:00s", resultTrackiedlist[1].GoalTrackedDurationParsed); Assert.Equal(DateTime.Parse("2019-05-06T08:30:39.9120605+01:00").ToLongDateString(), resultTrackiedlist[1].Date.ToLongDateString()); // And the last should match these Assert.False(resultTrackiedlist[6].GoalMet); Assert.Equal("0", resultTrackiedlist[6].GoalTrackedDurationInMs); Assert.Equal("00h:00m:00s", resultTrackiedlist[6].GoalTrackedDurationParsed); Assert.Equal(DateTime.Parse("2019-05-11T08:30:39.9120605+01:00").ToLongDateString(), resultTrackiedlist[6].Date.ToLongDateString()); }