public void GetSunset_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.GetSunset(currentDate); DateTime result2 = provider.GetSunset(currentDate); serviceMock.Verify(s => s.GetServiceData(currentDate), Times.Once()); }
public void GetSunset_CalledWithDifferentDates_CallsServiceMoreThanOnce() { DateTime date1 = new DateTime(2015, 02, 15); DateTime date2 = new DateTime(2015, 02, 16); 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.GetSunset(date1); DateTime result2 = provider.GetSunset(date2); serviceMock.Verify(s => s.GetServiceData(It.IsAny <DateTime>()), Times.Exactly(2)); }
public void GetSunset_WithDate_ReturnsSunsetForDate() { DateTime currentDate = new DateTime(2015, 02, 15); DateTime expected = new DateTime(2015, 02, 15, 18, 35, 58); 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.GetSunset(currentDate); Assert.AreEqual(expected, result); }
static void Main(string[] args) { var sunsetProvider = new SunsetTDD(); var sunset = sunsetProvider.GetSunset(DateTime.Today.AddDays(1)); Console.WriteLine("Sunset Tomorrow: {0}", sunset.ToString("G")); Console.WriteLine("Starting Test"); var controller = new HouseController(); controller.Commander = new FakeCommander(); controller.SendCommand(5, DeviceCommands.On); controller.SendCommand(5, DeviceCommands.Off); var currentTime = DateTime.Now; controller.ScheduleOneTimeItem(currentTime.AddMinutes(1), 1, DeviceCommands.On); controller.ScheduleOneTimeItem(currentTime.AddMinutes(2), 2, DeviceCommands.On); controller.ScheduleOneTimeItem(currentTime.AddMinutes(3), 1, DeviceCommands.Off); controller.ScheduleOneTimeItem(currentTime.AddMinutes(4), 2, DeviceCommands.Off); Console.WriteLine("Test Completed"); string command = ""; while (command != "q") { command = Console.ReadLine(); if (command == "s") { var schedule = controller.GetCurrentScheduleItems(); foreach (var item in schedule) { Console.WriteLine("{0} - {1} ({2}), Device: {3}, Command: {4}", item.Info.EventTime.ToString("G"), item.Info.TimeType.ToString(), item.Info.RelativeOffset.ToString(), item.Device.ToString(), item.Command.ToString()); } } } }