public ControllerUnitTests() { _jokeService = new Mock <IJokeService>(); _jokeService .Setup(js => js.GetAJoke()) .ReturnsAsync("joke"); _controller = new JokesController(_jokeService.Object); }
public void Setup() { _clientMock = new Mock <IJokeHttpClient>(); _loggerMock = new Mock <ILogger <JokesController> >(); _jokesHandlerMock = new Mock <IJokesHandler>(); _loggerMock.Setup(x => x.Log(It.IsAny <LogLevel>(), It.IsAny <string>())); _jokesController = new JokesController(_clientMock.Object, _loggerMock.Object, _jokesHandlerMock.Object); }
public async void GetJokesCategories_From_JokesController() { //Arrange JokesController jokesController = new JokesController(_jokesService); //Act var res = jokesController.GetJokesCategories().Result; //Assert Assert.NotNull(((ObjectResult)res).Value); }
public async void GetRandomJoke_From_JokesController() { //Arrange string jokeCategory = "Dev"; JokesController jokesController = new JokesController(_jokesService); //Act var res = await jokesController.GetRnadomJoke(jokeCategory); //Assert Assert.NotNull(((ObjectResult)res).Value); }
public void RandomJoke_ReturnsNull_WhenJokeIsNull() { var factory = new Mock <IBusinessFactory>(); factory.Setup(src => src.GetBusinessClass <IJokeBusiness>().GetRandomJoke()).Returns(new JokeModel()); var controller = new JokesController(factory.Object); var returns = controller.RandomJoke() as NegotiatedContentResult <JokeModel>; Assert.IsNull(returns); }
public void ShouldAllowMoreThanTheLimit() { var limit = 30; var loggerFactory = new LoggerFactory(); var logger = new Logger <JokesController>(loggerFactory); var httpClient = new HttpClient(); var jokeHttpClient = new JokeHttpClient(httpClient); var jokeHandler = new JokesHandler(logger, jokeHttpClient, new SimpleEmphasis()); var jokesController = new JokesController(jokeHttpClient, logger, jokeHandler); var result = jokesController.GetJokes("a", true, limit, false).Result; TotalCuratedJokes(result).Should().Be(limit); }
public void RandomJoke_ReturnsJokeModel_WhenJokeIsNotNull() { var randomJoke = new JokeModel { Joke = "this is not a joke" }; var factory = new Mock <IBusinessFactory>(); factory.Setup(src => src.GetBusinessClass <IJokeBusiness>().GetRandomJoke()).Returns(randomJoke); var controller = new JokesController(factory.Object); var returns = controller.RandomJoke() as OkNegotiatedContentResult <JokeModel>; Assert.AreEqual(returns.Content, randomJoke); }
public void ByIdShouldWorkCorrectly() { var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(typeof(JokesController).Assembly); const string JokeContent = "SomeContent"; var jokesServiceMock = new Mock<IJokesService>(); jokesServiceMock.Setup(x => x.GetById(It.IsAny<string>())) .Returns(new Joke { Content = JokeContent, Category = new JokeCategory { Name = "asda" } }); var controller = new JokesController(jokesServiceMock.Object); controller.WithCallTo(x => x.ById("asdasasd")) .ShouldRenderView("ById") .WithModel<JokeViewModel>( viewModel => { Assert.AreEqual(JokeContent, viewModel.Content); }).AndNoModelErrors(); }
public void JokesByTerm_ReturnsNull_WhenNoJokesWereFound() { var jokeList = new List <JokeModel>(); var jokeModels = new JokesModels { Results = jokeList }; var factory = new Mock <IBusinessFactory>(); factory.Setup(src => src.GetBusinessClass <IJokeBusiness>().GetJokesByTerm(It.IsAny <string>())).Returns(jokeModels); var controller = new JokesController(factory.Object); var returns = controller.JokesByTerm("this") as NegotiatedContentResult <JokesModels>; Assert.IsNull(returns); }
public void JokesByTerm_ReturnsJokeModels_WhenItHasJokes() { var jokeModel = new JokeModel { Joke = "this is not a joke" }; var jokeList = new List <JokeModel> { jokeModel }; var jokeModels = new JokesModels { Results = jokeList }; var factory = new Mock <IBusinessFactory>(); factory.Setup(src => src.GetBusinessClass <IJokeBusiness>().GetJokesByTerm(It.IsAny <string>())).Returns(jokeModels); var controller = new JokesController(factory.Object); var returns = controller.JokesByTerm("this") as OkNegotiatedContentResult <JokesModels>; Assert.AreEqual(returns.Content, jokeModels); }
public void ByIdShouldWorkCorrectly() { var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(typeof(JokesController).Assembly); const string JokeContent = "SomeContent"; var jokesServiceMock = new Mock <IJokesService>(); jokesServiceMock.Setup(x => x.GetById(It.IsAny <string>())) .Returns(new Joke { Content = JokeContent, Category = new JokeCategory { Name = "asda" } }); var controller = new JokesController(jokesServiceMock.Object); controller.WithCallTo(x => x.ById("asdasasd")) .ShouldRenderView("ById") .WithModel <JokeViewModel>( viewModel => { Assert.AreEqual(JokeContent, viewModel.Content); }).AndNoModelErrors(); }
public JokesControllerTest() { _jokesController = new JokesController(_jokesServices.Object); }