Ejemplo n.º 1
0
        public void GetRandomJoke_ReturnsJokeModel_Type()
        {
            //Arrange
            var mockJokeRepository = new Mock <IJokeRepository>();

            mockJokeRepository.Setup(x => x.GetRandomJoke()).Returns(new JokeModel());
            var mockRepositoryFactory = new Mock <IRepositoryFactory>();

            mockRepositoryFactory.Setup(x => x.GetDataRepository <IJokeRepository>()).Returns(mockJokeRepository.Object);
            var business = new JokeBusiness(mockRepositoryFactory.Object, new Shared.Utilities.JokesHelper());

            //Act
            JokeModel result = business.GetRandomJoke();

            //Assert
            Assert.IsInstanceOfType(result, typeof(JokeModel));
        }
Ejemplo n.º 2
0
        public void GetJokesByTerm_Returns_JokesModels_Type()
        {
            //Arrange
            var term = "red";
            var mockJokeRepository = new Mock <IJokeRepository>();

            mockJokeRepository.Setup(x => x.GetJokesByTerm(It.IsAny <string>())).Returns(new JokesModels());
            var mockRepositoryFactory = new Mock <IRepositoryFactory>();

            mockRepositoryFactory.Setup(x => x.GetDataRepository <IJokeRepository>()).Returns(mockJokeRepository.Object);
            var business = new JokeBusiness(mockRepositoryFactory.Object, new Shared.Utilities.JokesHelper());

            //Act
            JokesModels result = business.GetJokesByTerm(term);

            //Assert
            Assert.IsInstanceOfType(result, typeof(JokesModels));
        }
Ejemplo n.º 3
0
        public void GetJokesByTerm_ReturnsNull_WhenJokesModelsResults_AreNull()
        {
            //Arrange
            var term = "red";
            List <JokeModel> results = null;
            var mockJokeRepository   = new Mock <IJokeRepository>();

            mockJokeRepository.Setup(x => x.GetJokesByTerm(It.IsAny <string>())).Returns(new JokesModels()
            {
                Results = results, SearchTerm = "test"
            });
            var mockRepositoryFactory = new Mock <IRepositoryFactory>();

            mockRepositoryFactory.Setup(x => x.GetDataRepository <IJokeRepository>()).Returns(mockJokeRepository.Object);
            var mockHighlighter = new Mock <IHighlighter>();
            var business        = new JokeBusiness(mockRepositoryFactory.Object, new Shared.Utilities.JokesHelper());

            //Act
            JokesModels result = business.GetJokesByTerm(term);

            //Assert
            Assert.IsNull(result.Results);
        }
Ejemplo n.º 4
0
        public void GetJokesByTerm_ReturnsCorrectNumberOf_JokesModels()
        {
            //Arrange
            var term    = "red";
            var results = new List <JokeModel> {
                new JokeModel()
            };
            var mockJokeRepository = new Mock <IJokeRepository>();

            mockJokeRepository.Setup(x => x.GetJokesByTerm(It.IsAny <string>())).Returns(new JokesModels()
            {
                Results = results, SearchTerm = "test"
            });
            var mockRepositoryFactory = new Mock <IRepositoryFactory>();

            mockRepositoryFactory.Setup(x => x.GetDataRepository <IJokeRepository>()).Returns(mockJokeRepository.Object);
            var business = new JokeBusiness(mockRepositoryFactory.Object, new Shared.Utilities.JokesHelper());

            //Act
            JokesModels result = business.GetJokesByTerm(term);

            //Assert
            Assert.AreEqual(result.Results.Count, 1);
        }