Exemplo n.º 1
0
 public ControllerUnitTests()
 {
     _jokeService = new Mock <IJokeService>();
     _jokeService
     .Setup(js => js.GetAJoke())
     .ReturnsAsync("joke");
     _controller = new JokesController(_jokeService.Object);
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public async void GetJokesCategories_From_JokesController()
        {
            //Arrange
            JokesController jokesController = new JokesController(_jokesService);

            //Act
            var res = jokesController.GetJokesCategories().Result;

            //Assert
            Assert.NotNull(((ObjectResult)res).Value);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 8
0
 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();
        }
Exemplo n.º 12
0
 public JokesControllerTest()
 {
     _jokesController = new JokesController(_jokesServices.Object);
 }