public StudentServiceTest() { _studentService = MockBaseRepository.Create <IStudentService>(); _studentRepository = MockBaseRepository.Create <IStudentRepository>(); _loggerRepository = MockBaseRepository.Create <ILoggerRepository>(); _target = new StudentService(_studentRepository.Object, _loggerRepository.Object); }
public void GetAllStudentById() { //Arrange var studentBusiness = TestFixture.Create <Task <StudentDTOs> >(); _studentRepository.Setup(x => x.GetStudentByID(It.IsAny <int>())).Returns(studentBusiness); //Act var result = _target.GetStudentByID(1); //Assert MockBaseRepository.VerifyAll(); Assert.NotNull(result); }
public void GetAllStudentName() { //Arrange var studentBusinesstest = TestFixture.Create <Task <string> >(); _studentRepository.Setup(x => x.GetAllStudentName()).Returns(studentBusinesstest); //Act var result = _target.GetAllStudentName(); //Assert MockBaseRepository.VerifyAll(); Assert.NotNull(result); }
public void DeleteStudentById() { //Arrange var studentBusinesstest = TestFixture.Create <Task <bool> >(); _studentRepository.Setup(x => x.DeleteStudentById(It.IsAny <int>())).Returns(studentBusinesstest); //Act var result = _target.DeleteStudentById(1); //Assert MockBaseRepository.VerifyAll(); Assert.NotNull(result); }
public void UpdateStudentTest() { //Arrange var studentBusiness = TestFixture.Create <StudentDTOs>(); var studentBusinesstest = TestFixture.Create <Task <bool> >(); _studentRepository.Setup(x => x.UpdateStudent(It.IsAny <int>(), It.IsAny <Student>())).Returns(studentBusinesstest); //Act var result = _target.Update(1, studentBusiness); //Assert MockBaseRepository.VerifyAll(); Assert.NotNull(result); }
public void FindAllReturnsNoRecords() { var fakeTransactionType = new TransactionType[] { }; var options = new DbContextOptionsBuilder().Options; var context = new Mock<AccountingContext>(options); context.Setup(x => x.TransactionTypes).ReturnsDbSet(fakeTransactionType); context.Setup(i => i.Set<TransactionType>()).ReturnsDbSet(fakeTransactionType); var sut = new MockBaseRepository<TransactionType>(context.Object); var result = sut.FindAll(); var resultList = result.ToList(); result.Should().NotBeNull("the TransactionTypes should not exist but an emtpy IQueryable should be returned"); resultList.Count.Should().Be(0, "there are no TransactionTypes"); }
public void FindAllWhereReturnCorrectRecords() { var fakeTransactionType = new TransactionType[] { new TransactionType { Id = 1, Name="FakeTransaction1" }, new TransactionType { Id = 2, Name="FakeTransaction2" }, new TransactionType { Id = 3, Name="FakeTransaction3" }, new TransactionType { Id = 4, Name="FakeTransaction1" } }; var options = new DbContextOptionsBuilder().Options; var context = new Mock<AccountingContext>(options); context.Setup(x => x.TransactionTypes).ReturnsDbSet(fakeTransactionType); context.Setup(i => i.Set<TransactionType>()).ReturnsDbSet(fakeTransactionType); var sut = new MockBaseRepository<TransactionType>(context.Object); var result = sut.FindAllWhere(t => t.Name.Equals("FakeTransaction1", StringComparison.InvariantCultureIgnoreCase)); var resultList = result.ToList(); resultList.Should().NotBeNull("the TransactionType should exist therefore it should be returned in a set and not be Null"); resultList.Count.Should().BeGreaterThan(0, "there are TransactionTypes therefore there are more than 0"); resultList.Count.Should().Be(2, "there are only 2 TransactionTypes with the name \"FakeTransaction1\" therefore there must be only 2"); resultList.Should().Contain(fakeTransactionType[0], "this is one of the fakeTransactions that should exist with the name therefore it should be in the set returned"); resultList.Should().Contain(fakeTransactionType[3], "this is one of the fakeTransactions that should exist with the name therefore it should be in the set returned"); }
public void FindAllReturnsAllRecords() { var fakeTransactionType = new TransactionType[] { new TransactionType { Id = 1, Name="FakeTransaction1" }, new TransactionType { Id = 2, Name="FakeTransaction2" }, new TransactionType { Id = 3, Name="FakeTransaction3" } }; var options = new DbContextOptionsBuilder().Options; var context = new Mock<AccountingContext>(options); context.Setup(x => x.TransactionTypes).ReturnsDbSet(fakeTransactionType); context.Setup(i => i.Set<TransactionType>()).ReturnsDbSet(fakeTransactionType); var sut = new MockBaseRepository<TransactionType>(context.Object); var result = sut.FindAll(); var resultList = result.ToList(); result.Should().NotBeNull("the TransactionTypes should exist therefore they should be returned and not be Null"); resultList.Count.Should().BeGreaterThan(0, "there are TransactionTypes therefore there are more than 0"); resultList.Count.Should().BeLessThan(4, "there are only 3 TransactionTypes therefore there must be less than 4"); resultList.Should().Contain(fakeTransactionType[0], "this is one of the fakeTransactions that should exist therefore be in the set returned"); resultList.Should().Contain(fakeTransactionType[1], "this is one of the fakeTransactions that should exist therefore be in the set returned"); resultList.Should().Contain(fakeTransactionType[2], "this is one of the fakeTransactions that should exist therefore be in the set returned"); }
public void FindAllWhereReturnNoRecords() { var fakeTransactionType = new TransactionType[] { new TransactionType { Id = 1, Name="FakeTransaction1" }, new TransactionType { Id = 2, Name="FakeTransaction2" }, new TransactionType { Id = 3, Name="FakeTransaction3" }, new TransactionType { Id = 4, Name="FakeTransaction1" } }; var options = new DbContextOptionsBuilder().Options; var context = new Mock<AccountingContext>(options); context.Setup(x => x.TransactionTypes).ReturnsDbSet(fakeTransactionType); context.Setup(i => i.Set<TransactionType>()).ReturnsDbSet(fakeTransactionType); var sut = new MockBaseRepository<TransactionType>(context.Object); var result = sut.FindAllWhere(t => t.Name.Equals("FakeTransaction4", StringComparison.InvariantCultureIgnoreCase)); var resultList = result.ToList(); resultList.Should().NotBeNull("the TransactionType even though empty should just return an empty set and not be Null"); resultList.Count.Should().Be(0, "there are no TransactionTypes therefore there should be 0"); }
public void FindByIdReturnsNothing() { var fakeTransactionType = new TransactionType[] { new TransactionType { Id = 1, Name="FakeTransaction1" }, new TransactionType { Id = 2, Name="FakeTransaction2" }, }; var options = new DbContextOptionsBuilder().Options; var context = new Mock<AccountingContext>(options); context.Setup(x => x.TransactionTypes).ReturnsDbSet(fakeTransactionType); context.Setup(i => i.Set<TransactionType>()).ReturnsDbSet(fakeTransactionType); var sut = new MockBaseRepository<TransactionType>(context.Object); var result = sut.FindById(3); result.Should().BeNull("the TransactionType should'nt therefore nothing should be returned i.e Be Null"); }
public void FindByIdReturnsARecord() { var fakeTransactionType = new TransactionType[] { new TransactionType { Id = 1, Name="FakeTransaction1" }, new TransactionType { Id = 2, Name="FakeTransaction2" }, }; var options = new DbContextOptionsBuilder().Options; var context = new Mock<AccountingContext>(options); context.Setup(x => x.TransactionTypes).ReturnsDbSet(fakeTransactionType); context.Setup(i => i.Set<TransactionType>()).ReturnsDbSet(fakeTransactionType); var sut = new MockBaseRepository<TransactionType>(context.Object); var result = sut.FindById(1); result.Should().NotBeNull("the TransactionType should exist therefore should be returned and not be Null"); result.Id.ShouldBeEquivalentTo(1, "this is the ID we used to retrieve the TransactionType"); }