public void GetQuestion_WhenQuestionIsFound_ReturnsQuestion() { var mockQuestion = new QuestionGetSingleResponse { QuestionId = 1, Title = "test" }; var mockDataRepository = new Mock <IDataRepository>(); mockDataRepository.Setup(repo => repo.GetQuestion(1)) .Returns(() => mockQuestion); var mockQuestionCache = new Mock <IQuestionCache>(); mockQuestionCache.Setup(cache => cache.Get(1)) .Returns(() => mockQuestion); var mockConfigurationRoot = new Mock <IConfigurationRoot>(); mockConfigurationRoot.SetupGet(config => config[It.IsAny <string>()]).Returns("some setting"); var questionsController = new QuestionsController(mockDataRepository.Object, null, mockQuestionCache.Object, null, mockConfigurationRoot.Object); var result = questionsController.GetQuestion(1); var actionResult = Assert.IsType <ActionResult <QuestionGetSingleResponse> >(result); var questionResult = Assert.IsType <QuestionGetSingleResponse>(actionResult.Value); Assert.Equal(1, questionResult.QuestionId); }
public async void GetQuestion_WhenQuestionIsFound_ReturnsQuestion() { var mockQuestion = new QuestionGetSingleResponse { QuestionId = 1, Title = "test" }; var mockQuestionCache = new Mock <IQuestionCache>(); mockQuestionCache .Setup(cache => cache.Get(1)) .Returns(() => null); var mockDataRepo = new Mock <IDataRepository>(); mockDataRepo .Setup(repo => repo.GetQuestion(1)) .Returns(() => Task.FromResult(mockQuestion)); var mockConfig = new Mock <IConfigurationRoot>(); mockConfig .SetupGet(config => config[It.IsAny <string>()]) .Returns("String"); var questionsController = new QuestionsController( mockDataRepo.Object, null, mockQuestionCache.Object, null); var result = await questionsController.GetQuestion(1); var actionResult = Assert.IsType <ActionResult <QuestionGetSingleResponse> >(result); }
public void Set(QuestionGetSingleResponse question) { var entryOptions = new MemoryCacheEntryOptions() { Size = 1 }; _cache.Set(GetCacheKey(question.QuestionId), question, entryOptions); }
public void Set(QuestionGetSingleResponse question) { // specify the size of the question // This ties in with the size limitwe set on the cache so that the cache will // start to remove questions from the cache when there are 100 questions in it var cacheEntryOptions = new MemoryCacheEntryOptions().SetSize(1); _cache.Set(GetCacheKey(question.QuestionId), question, cacheEntryOptions); }
GetQuestion_WhenQuestionIsFound_ReturnsQuestion() { var mockQuestion = new QuestionGetSingleResponse { QuestionId = 1, Title = "test" }; var mockDataRepository = new Mock <IDataRepository>(); mockDataRepository .Setup(repo => repo.GetQuestion(1)) .Returns(() => Task.FromResult(mockQuestion)); var mockQuestionCache = new Mock <IQuestionCache>(); mockQuestionCache .Setup(c => c.Get(1)) .Returns(() => mockQuestion); var mockConfigurationRoot = new Mock <IConfigurationRoot>(); mockConfigurationRoot .SetupGet(config => config[It.IsAny <string>()]).Returns("some setting"); var questionsController = new QuestionsController( mockDataRepository.Object, null, // AutoMapper null, // SignalR Hub mockQuestionCache.Object, null, // HttpClientFactory mockConfigurationRoot.Object ); var result = await questionsController.GetQuestion(1); var actionResult = Assert.IsType <ActionResult <QuestionGetSingleResponse> >(result); var questionResult = Assert.IsType <QuestionGetSingleResponse>(actionResult.Value); Assert.Equal(1, questionResult.QuestionId); }