コード例 #1
0
        public void ReturnNull_WhenRepositoryMethodAll_ReturnsNull()
        {
            //Arrange
            var brands = new Mock <IEfGenericRepository <Brand> >();

            brands.Setup(x => x.All()).Returns(() => null);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            Assert.IsNull(result);
        }
コード例 #2
0
        public void InvokeRepositoryMethosAllOnce()
        {
            //Arrange
            var brands           = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollection = DataHelper.GetBrands();

            brands.Setup(x => x.All()).Returns(brandsCollection);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            brands.Verify(x => x.All(), Times.Once);
        }
コード例 #3
0
        public void ReturnCorrectInstance()
        {
            //Arrange
            var brands           = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollection = DataHelper.GetBrands();

            brands.Setup(x => x.All()).Returns(brandsCollection);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            Assert.IsInstanceOf <IQueryable <Brand> >(result);
        }
コード例 #4
0
        public void ReturnCorrectModel()
        {
            //Arrange
            var brands           = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollection = DataHelper.GetBrands();

            brands.Setup(x => x.All()).Returns(brandsCollection);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, brandsCollection);
        }
コード例 #5
0
        public void ReturnCorrectModelWithRightProperties()
        {
            //Arrange
            var brands           = new Mock <IEfGenericRepository <Brand> >();
            var brandsCollection = DataHelper.GetBrands();

            brands.Setup(x => x.All()).Returns(brandsCollection);
            var brandsService = new BrandsService(brands.Object);

            //Act
            var result = brandsService.GetAll();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result, brandsCollection);
            Assert.AreEqual(result.FirstOrDefault().Id, brandsCollection.FirstOrDefault().Id);
            Assert.AreEqual(result.FirstOrDefault().Name, brandsCollection.FirstOrDefault().Name);
            Assert.AreEqual(result.FirstOrDefault().WebSite, brandsCollection.FirstOrDefault().WebSite);
        }