public void GetSunrise_CalledMultipleTimesWithSameDate_CallsServiceOnce() { DateTime currentDate = new DateTime(2015, 02, 15); Mock <ISunsetService> serviceMock = new Mock <ISunsetService>(); serviceMock.Setup(s => s.GetServiceData(It.IsAny <DateTime>())) .Returns(sampleData); SunsetTDD provider = new SunsetTDD(); provider.SunsetService = serviceMock.Object; DateTime result1 = provider.GetSunrise(currentDate); DateTime result2 = provider.GetSunrise(currentDate); serviceMock.Verify(s => s.GetServiceData(currentDate), Times.Once()); }
public void GetSunrise_WithDate_ReturnsSunriseForDate() { DateTime currentDate = new DateTime(2015, 02, 15); DateTime expected = new DateTime(2015, 02, 15, 07, 35, 18); Mock <ISunsetService> serviceMock = new Mock <ISunsetService>(); serviceMock.Setup(s => s.GetServiceData(It.IsAny <DateTime>())) .Returns(sampleData); SunsetTDD provider = new SunsetTDD(); provider.SunsetService = serviceMock.Object; DateTime result = provider.GetSunrise(currentDate); Assert.AreEqual(expected, result); }