Example #1
0
        public void CheckIfBrandExists_ShouldReturnTrue()
        {
            var data = new List<article>{
                new article{ brand = "DefinitelyNotApple", id = 1, description = "This thing is anything but Applish", image_loc = "somewhere.jpg" }
            }.AsQueryable();

            var mockSet = new Mock<DbSet<article>>();
            mockSet.As<IQueryable<article>>().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As<IQueryable<article>>().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As<IQueryable<article>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As<IQueryable<article>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock<BetsyEntities>();
            mockContext.Setup(c => c.article).Returns(mockSet.Object);

            var service = new BetsyService(mockContext.Object);
            var checkTrue = service.CheckIfBrandExists("DefinitelyNotApple");
            var checkFalse = service.CheckIfBrandExists("Apple");

            Assert.AreEqual(true, checkTrue);
            Assert.AreEqual(false, checkFalse);
        }