Example #1
0
        public void GetAllByProduct_ShouldThrowArgumentException_IfNoProductsForTheGivenId()
        {
            Mapper.Initialize(x => x.AddProfile <MapperConfiguration>());
            var repo     = new Mock <IRepository <Comment> >();
            var comments = GetTestData().AsQueryable();

            repo.Setup(r => r.All()).Returns(comments);
            var service = new CommentsService(repo.Object);

            var  expected = typeof(ArgumentException);
            Type actual   = null;

            try
            {
                //do
                var result = service.GetAllByProduct(2);
            }
            catch (ArgumentException e)
            {
                actual = e.GetType();
            }

            //assert
            Assert.Equal(expected, actual);
        }
Example #2
0
        public void GetAllByProduct_ShouldReturnCorrectNumber()
        {
            Mapper.Initialize(x => x.AddProfile <MapperConfiguration>());
            var repo     = new Mock <IRepository <Comment> >();
            var comments = GetTestData().AsQueryable();

            repo.Setup(r => r.All()).Returns(comments);
            var service = new CommentsService(repo.Object);

            //do
            var result = service.GetAllByProduct(1);

            //assert
            Assert.Equal(2, result.Count());
        }