public async void Events_Unchanged() { var focusStore = new Mock <IFocusStore>(MockBehavior.Strict); var event1 = new Event() { Id = "Test1", Start = new DateTimeOffset(2018, 1, 1, 10, 0, 0, TimeSpan.Zero), Location = new LocationData() { Text = "Location1" } }; focusStore.Setup(v => v.GetCalendarItemsAsync(userId)).Returns(Task.FromResult(new FocusItem[] { new FocusItem() { CalendarEventId = "Test1", CalendarEventHash = event1.GenerateHash() } })); var calendarService = new Mock <ICalendarServiceClient>(MockBehavior.Strict); calendarService .Setup(v => v.Users[userId].Events.Get(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())) .Returns(Task.FromResult(new Event[] { event1 })); IFocusCalendarSyncService focusCalendarSyncService = new FocusCalendarSyncService(calendarService.Object, focusStore.Object); var res = await focusCalendarSyncService.SyncAsync(userId, DateTimeOffset.Now, DateTimeOffset.Now.AddHours(2)); Assert.Empty(res.AddedItems); Assert.Empty(res.RemovedItems); Assert.Empty(res.ChangedItems); }
public async void Events_Added_Removed() { var focusStore = new Mock <IFocusStore>(MockBehavior.Strict); focusStore.Setup(v => v.GetCalendarItemsAsync(userId)).Returns(Task.FromResult(new FocusItem[] { new FocusItem() { CalendarEventId = "Test2", Start = DateTimeOffset.Now.AddHours(1), End = DateTimeOffset.Now.AddHours(1.5), } })); focusStore.Setup(v => v.StoreCalendarEventAsync(userId, It.IsAny <Event>())).Returns <string, Event>(async(v, e) => new FocusItem() { CalendarEventId = e.Id }); focusStore.Setup(v => v.RemoveAsync(It.IsAny <FocusItem>())).Returns(Task.CompletedTask); var calendarService = new Mock <ICalendarServiceClient>(MockBehavior.Strict); calendarService .Setup(v => v.Users[userId].Events.Get(It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>())) .Returns(Task.FromResult(new Event[] { new Event() { Id = "Test1" } })); IFocusCalendarSyncService focusCalendarSyncService = new FocusCalendarSyncService(calendarService.Object, focusStore.Object); var res = await focusCalendarSyncService.SyncAsync(userId, DateTimeOffset.Now, DateTimeOffset.Now.AddHours(2)); Assert.Collection(res.AddedItems, v => Assert.Equal("Test1", v.CalendarEventId)); Assert.Collection(res.RemovedItems, v => Assert.Equal("Test2", v.CalendarEventId)); Assert.Empty(res.ChangedItems); }