public async Task GetUserPreferences_Returns_The_User_Preferences_From_The_Preferences_Service() { Mock <IUserPreferencesService> prefsServiceMock = new Mock <IUserPreferencesService>(); var expectedUserPreferences = new UserPreferences { UrgencyConfiguration = new UrgencyConfiguration { ImminentDays = 123, SoonDays = 321 } }; prefsServiceMock .Setup(m => m.GetUserPreferencesAsync(It.IsAny <string>())) .ReturnsAsync(expectedUserPreferences); PreferencesController uut = new PreferencesController(prefsServiceMock.Object); string userId = "someUserId|1234"; uut.SetUserContext(userId); var result = await uut.GetUserPreferences(); var okResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(expectedUserPreferences, okResult.Value); }
public async Task GetUserPreferences_Calls_The_Preferences_Service_With_The_Current_User_ID() { Mock <IUserPreferencesService> prefsServiceMock = new Mock <IUserPreferencesService>(); prefsServiceMock .Setup(m => m.GetUserPreferencesAsync(It.IsAny <string>())) .ReturnsAsync(new UserPreferences()); PreferencesController uut = new PreferencesController(prefsServiceMock.Object); string userId = "someUserId|1234"; uut.SetUserContext(userId); await uut.GetUserPreferences(); prefsServiceMock.Verify(m => m.GetUserPreferencesAsync(userId)); }