private void MockServiceResponses(bool fileExists, ImportantInfoResponse response) { _importantInfoService .Setup(mock => mock.ConfigFileExists()) .Returns(fileExists); _importantInfoService .Setup(mock => mock.ParseConfig(It.IsAny <ImportantInfoRequest>())) .Returns(response); }
public void ParseConfig_LanguageIsNotPresent_ReturnsResponseWithEmptyText() { _configuration.Setup(config => config[BannerConfigurationFileConfig]) .Returns(BannerConfigurationFile); ImportantInfoResponse response = _service.ParseConfig(new ImportantInfoRequest() { lang = "SE" }); Assert.NotNull(response); Assert.Null(response.text); }
public async Task TestGetImportantInfo_InfoInLanguageAvailable_ReturnsInfo() { string infoText = "Important"; MockServiceResponses(true, new ImportantInfoResponse() { text = infoText }); IActionResult result = await _controller.GetImportantInfo("NB"); Assert.That(result, Is.InstanceOf <OkObjectResult>()); OkObjectResult okResult = result as OkObjectResult; Assert.That(okResult.Value, Is.InstanceOf <ImportantInfoResponse>()); ImportantInfoResponse infoResponse = okResult.Value as ImportantInfoResponse; Assert.AreEqual(infoText, infoResponse.text); _importantInfoService.Verify(mock => mock.ConfigFileExists(), Times.Once); _importantInfoService.Verify(mock => mock.ParseConfig(It.IsAny <ImportantInfoRequest>()), Times.Once); }