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); }
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); }
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); }
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); }
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); }