public void ReturnNull_WhenRepositoryMethodAll_ReturnsNull() { //Arrange var supplements = new Mock <IEfGenericRepository <Supplement> >(); supplements.Setup(x => x.All()).Returns(() => null); var supplementsService = new SupplementsService(supplements.Object); //Act var result = supplementsService.GetAll(); //Assert Assert.IsNull(result); }
public void InvokeRepositoryMethosAllOnce() { //Arrange var supplements = new Mock <IEfGenericRepository <Supplement> >(); var supplementsCollection = DataHelper.GetSupplements(); supplements.Setup(x => x.All()).Returns(supplementsCollection); var supplementsService = new SupplementsService(supplements.Object); //Act var result = supplementsService.GetAll(); //Assert supplements.Verify(x => x.All(), Times.Once); }
public void ReturnCorrectInstance() { //Arrange var supplements = new Mock <IEfGenericRepository <Supplement> >(); var supplementsCollection = DataHelper.GetSupplements(); supplements.Setup(x => x.All()).Returns(supplementsCollection); var supplementsService = new SupplementsService(supplements.Object); //Act var result = supplementsService.GetAll(); //Assert Assert.IsInstanceOf <IQueryable <Supplement> >(result); }
public void ReturnCorrectModel() { //Arrange var supplements = new Mock <IEfGenericRepository <Supplement> >(); var supplementsCollection = DataHelper.GetSupplements(); supplements.Setup(x => x.All()).Returns(supplementsCollection); var supplementsService = new SupplementsService(supplements.Object); //Act var result = supplementsService.GetAll(); //Assert Assert.IsNotNull(result); Assert.AreEqual(result, supplementsCollection); }
public void ReturnCorrectModelWithRightProperties() { //Arrange var supplements = new Mock <IEfGenericRepository <Supplement> >(); var supplementsCollection = DataHelper.GetSupplements(); supplements.Setup(x => x.All()).Returns(supplementsCollection); var supplementsService = new SupplementsService(supplements.Object); //Act var result = supplementsService.GetAll(); //Assert Assert.IsNotNull(result); Assert.AreEqual(result, supplementsCollection); Assert.AreEqual(result.FirstOrDefault().Id, supplementsCollection.FirstOrDefault().Id); Assert.AreEqual(result.FirstOrDefault().Name, supplementsCollection.FirstOrDefault().Name); Assert.AreEqual(result.FirstOrDefault().ImageUrl, supplementsCollection.FirstOrDefault().ImageUrl); }