public async Task UserStreamControllerTests_CountReturnsCountFromRepository() { //Arrange var mockRepository = new Mock <IUserStreamRepository>(); mockRepository.Setup(r => r.GetUserStreamCount(It.IsAny <string>())).Returns(() => Task.FromResult(3)); var mockLogger = new Mock <ILogger <UserStreamController> >(); var appSettingsMock = new Mock <IOptions <AppSettings> >(); var userStreamController = new UserStreamController(mockRepository.Object, appSettingsMock.Object, mockLogger.Object); //Act var userStreamCount = await userStreamController.Count("test-user") as OkObjectResult; //Assert Assert.IsNotNull(userStreamCount); Assert.AreEqual(3, userStreamCount.Value); }
public async Task UserStreamControllerTests_StopDecrementsStreamCount() { //Arrange var mockRepository = new Mock <IUserStreamRepository>(); mockRepository.Setup(r => r.GetUserStreamCount(It.IsAny <string>())).Returns(() => Task.FromResult(2)); var mockLogger = new Mock <ILogger <UserStreamController> >(); var appSettingsMock = new Mock <IOptions <AppSettings> >(); appSettingsMock.Setup(s => s.Value).Returns(() => new AppSettings { MaximumConcurrentUserStreams = 3 }); var userStreamController = new UserStreamController(mockRepository.Object, appSettingsMock.Object, mockLogger.Object); //Act var userStreamStartResponse = await userStreamController.Stop("test-user") as OkResult; //Assert Assert.IsNotNull(userStreamStartResponse); mockRepository.Verify(r => r.DecrementUserStreamCount(It.IsAny <string>()), Times.Once); }