-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds TogglProxy business logic tests using Moq to mock togglapi
- Loading branch information
Showing
14 changed files
with
355 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace DailyStatus.Common.Services | ||
{ | ||
public interface ITogglReportApi | ||
{ | ||
Task<TimeSpan> GetHoursSum(DateTime since, DateTime until, long userId, long workspaceId); | ||
Task<long> GetUserId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using DailyStatus.Common.Services; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Toggl.Multivac.Models; | ||
using Toggl.Ultrawave; | ||
|
||
namespace DailyStatus.CommonTests | ||
{ | ||
[TestClass()] | ||
public class TogglProxyTests | ||
{ | ||
[TestMethod] | ||
public async Task Given3hYesterdayAnd5hToday_WhenGettingStatus_ShouldIncludeTodayHours() | ||
{ | ||
const int HoursWithoutToday = 3; | ||
const int HoursToday = 5; | ||
|
||
const long WorkSpaceId = -1L; | ||
var yesterdayEntry = new Mock<ITimeEntry>(); | ||
yesterdayEntry.Setup(e => e.ServerDeletedAt).Returns(() => null); | ||
yesterdayEntry.Setup(e => e.WorkspaceId).Returns(() => WorkSpaceId); | ||
yesterdayEntry.Setup(e => e.Duration).Returns(() => (long)TimeSpan.FromHours(HoursToday).TotalSeconds); | ||
yesterdayEntry.Setup(e => e.Start).Returns(() => DateTime.Today.AddHours(1)); | ||
|
||
var observable = Observable.Create<List<ITimeEntry>>((obs) => | ||
{ | ||
obs.OnNext(new List<ITimeEntry>() { yesterdayEntry.Object }); | ||
obs.OnCompleted(); | ||
return () => { }; | ||
}); | ||
|
||
var togglMock = new Mock<ITogglApi>(); | ||
togglMock.Setup(t => t.TimeEntries.GetAllSince(It.IsAny<DateTimeOffset>())) | ||
.Returns(observable); | ||
|
||
var workspaceMock = new Mock<IWorkspace>(); | ||
workspaceMock.Setup(w => w.Name).Returns("test"); | ||
workspaceMock.Setup(w => w.Id).Returns(WorkSpaceId); | ||
|
||
var observableWorkspace = Observable.Create<List<IWorkspace>>((obs) => | ||
{ | ||
obs.OnNext(new List<IWorkspace>() { workspaceMock.Object }); | ||
obs.OnCompleted(); | ||
return () => { }; | ||
}); | ||
|
||
togglMock.Setup(t => t.Workspaces.GetAll()) | ||
.Returns(observableWorkspace); | ||
|
||
var reportMock = new Mock<ITogglReportApi>(); | ||
reportMock.Setup(r => r.GetUserId()).Returns(Task.FromResult(-1L)); | ||
reportMock.Setup(r => r.GetHoursSum(It.IsAny<DateTime>(), It.IsAny<DateTime>(), | ||
It.IsAny<long>(), It.IsAny<long>())) | ||
.Returns(Task.FromResult(TimeSpan.FromHours(HoursWithoutToday))); | ||
|
||
|
||
var sut = new TogglProxy(reportMock.Object, togglMock.Object); | ||
var status = await sut.GetStatus(new DateTime(2020, 02, 04)); | ||
status.TodaysHours.Should().Be(TimeSpan.FromHours(HoursToday)); | ||
status.TimeInMonth.Should().BeGreaterThan(TimeSpan.FromHours(HoursToday)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Castle.Core" version="4.4.0" targetFramework="net461" /> | ||
<package id="FluentAssertions" version="5.10.2" targetFramework="net461" /> | ||
<package id="Moq" version="4.13.1" targetFramework="net461" /> | ||
<package id="MSTest.TestAdapter" version="1.2.0" targetFramework="net461" /> | ||
<package id="MSTest.TestFramework" version="1.2.0" targetFramework="net461" /> | ||
<package id="System.Reactive" version="4.3.2" targetFramework="net461" /> | ||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" /> | ||
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net461" /> | ||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" /> | ||
</packages> |
Oops, something went wrong.