public async void LunchService_GetRestaurantAsync_ThrowTooManyRequestsWhenOutOfSuggestions() { Mock <IGetLunchOptions> mockOptions = new Mock <IGetLunchOptions>(); Mock <IRepository> mockRepo = new Mock <IRepository>(); Mock <IChaos> mockRandom = new Mock <IChaos>(); IRestaurantCache cache = new RestaurantCacheMock(); const string expected = "bob's burgers"; Guid sessionId = Guid.NewGuid(); mockOptions.Setup(x => x.GetAvailableRestaurantOptionsAsync(sessionId, It.IsAny <SearchOptions>())).ReturnsAsync(new List <RestaurantDto> { new RestaurantDto { Name = expected, }, }); LunchService target = new LunchService(mockOptions.Object, mockRepo.Object, mockRandom.Object, cache); // act var result = await target.GetRestaurantAsync(sessionId, new SearchOptions()); // assert await Assert.ThrowsAsync <TooManyRequestsException>(async() => await target.GetRestaurantAsync(sessionId, new SearchOptions())); }
public async void LunchService_GetRestaurantAsync_FiltersOutNopes() { // arrange Mock <IGetLunchOptions> mockOptions = new Mock <IGetLunchOptions>(); Mock <IRepository> mockRepo = new Mock <IRepository>(); Mock <IChaos> mockRandom = new Mock <IChaos>(); IRestaurantCache cache = new RestaurantCacheMock(); mockRandom.Setup(m => m.Next(It.IsAny <int>())).Returns(0); Guid sessionGuid = Guid.NewGuid(); mockOptions.Setup(x => x.GetAvailableRestaurantOptionsAsync(sessionGuid, It.IsAny <SearchOptions>())).ReturnsAsync(new List <RestaurantDto> { new RestaurantDto { Name = "COok OOout", Id = "rest3" }, new RestaurantDto { Name = "Jimmy Pesto's Pizzaria", Id = "rest2" }, new RestaurantDto { Name = "Bob's Burgers", Id = "rest1" }, }); mockRepo.Setup(x => x.GetNopesAsync(It.IsAny <IEnumerable <int> >())).ReturnsAsync(new List <string> { "rest2", "rest3" }); List <int> users = new List <int> { 1, 2 }; LunchService target = new LunchService(mockOptions.Object, mockRepo.Object, mockRandom.Object, cache); // act var result = await target.GetRestaurantAsync(sessionGuid, new SearchOptions() { UserIds = users }); // assert Assert.Equal("Bob's Burgers", result.Name); }
public async void LunchService_GetRestaurantAsync_ReturnsRestaurantDto() { // arrange Mock <IGetLunchOptions> mockOptions = new Mock <IGetLunchOptions>(); Mock <IRepository> mockRepo = new Mock <IRepository>(); Mock <IChaos> mockRandom = new Mock <IChaos>(); Mock <IRestaurantCache> mockCache = new Mock <IRestaurantCache>(); LunchService target = new LunchService(mockOptions.Object, mockRepo.Object, mockRandom.Object, mockCache.Object); const string expected = "bob's burgers"; Guid sessionId = Guid.NewGuid(); mockOptions.Setup(x => x.GetAvailableRestaurantOptionsAsync(sessionId, It.IsAny <SearchOptions>())).ReturnsAsync(new List <RestaurantDto> { new RestaurantDto { Name = expected, }, }); // act var result = await target.GetRestaurantAsync(sessionId, new SearchOptions()); // assert Assert.Equal(expected, result.Name); }