public void Can_Return_Empty_Queryable() { //Arrange var context = new Mock <IDbContext>(); context.Setup(x => x.Set <TestModel>()).Returns(new List <TestModel>().AsQueryable); var projector = new Projector <TestModel>(context.Object); //Act var result = projector.GetAll().ToList(); //Assert Assert.That(result, Is.Empty); }
public void Failure_Getting_Set_Will_Bubble_Through() { //Arrange const string exceptionMessage = "Test Exception"; var context = new Mock <IDbContext>(); context.Setup(x => x.Set <TestModel>()).Throws(new Exception(exceptionMessage)); var projector = new Projector <TestModel>(context.Object); //Act IQueryable <TestModel> TestDelegate() => projector.GetAll(); //Assert Assert.That(TestDelegate, Throws.Exception.With.Message.EqualTo(exceptionMessage)); }
public void Returns_Queryable_Of_Type() { //Arrange var expectedCollection = new List <TestModel> { new TestModel(0), new TestModel(1) }; var context = new Mock <IDbContext>(); context.Setup(x => x.Set <TestModel>()).Returns(expectedCollection.AsQueryable()); var projector = new Projector <TestModel>(context.Object); //Act var actualCollection = projector.GetAll().ToList(); //Assert Assert.That(actualCollection, Has.Count.EqualTo(expectedCollection.Count)); Assert.That(actualCollection.First().Id, Is.EqualTo(0)); }