public void GetTop_ShouldReturnInstanceOfIQueryable() { // Arrange var mockedRepository = new Mock <IRepository <EmployeePaycheck> >(); var paycheckService = new EmployeePaycheckService(mockedRepository.Object); var employee = new FakeEmployeePaycheck() { Id = 5 }; var employee2 = new FakeEmployeePaycheck() { Id = 6 }; var employee3 = new FakeEmployeePaycheck() { Id = 7 }; // Act paycheckService.Create(employee); paycheckService.Create(employee2); paycheckService.Create(employee3); var query = paycheckService.GetTop(3); // Assert Assert.IsInstanceOf <IQueryable <EmployeePaycheck> >(query); }
public void GetTop_ShouldInvokeOnlyOnce() { // Arrange var mockedRepository = new Mock <IRepository <EmployeePaycheck> >(); var paycheckService = new EmployeePaycheckService(mockedRepository.Object); var employee = new FakeEmployeePaycheck() { Id = 1 }; var employee2 = new FakeEmployeePaycheck() { Id = 2 }; var employee3 = new FakeEmployeePaycheck() { Id = 3 }; // Act paycheckService.Create(employee); paycheckService.Create(employee2); paycheckService.Create(employee3); paycheckService.GetTop(3); // Assert mockedRepository.Verify(r => r.All, Times.Once); }
public void Create_ShouldThrowArgumentNullException_WhenParameterIsNull() { // Arrange var mockedRepository = new Mock <IRepository <EmployeePaycheck> >(); var paycheckService = new EmployeePaycheckService(mockedRepository.Object); // Act & Assert Assert.That(() => paycheckService.Create(null), Throws.InstanceOf <ArgumentNullException>().With.Message.Contains("The argument is null")); }
public void Create_ShouldInvokeOnce_WhenParameterIsCorrect() { // Arrange var mockedRepository = new Mock <IRepository <EmployeePaycheck> >(); var paycheckService = new EmployeePaycheckService(mockedRepository.Object); var paycheck = new FakeEmployeePaycheck(); // Act paycheckService.Create(paycheck); // Assert mockedRepository.Verify(r => r.Add(paycheck), Times.Once); }
public void Delete_ShouldInvokeOnce_WhenValidId_IsPassedCorrectly() { // Arrange var mockedRepository = new Mock <IRepository <EmployeePaycheck> >(); var paycheckService = new EmployeePaycheckService(mockedRepository.Object); EmployeePaycheck employee = new FakeEmployeePaycheck(); employee.Id = 2; // Act paycheckService.Create(employee); paycheckService.DeleteById(2); // Assert mockedRepository.Verify(r => r.Delete(It.IsAny <int>()), Times.Once); }
public void Update_ShouldUpdateEmployeeCorrectly() { // Arrange var mockedRepository = new Mock <IRepository <EmployeePaycheck> >(); var emplPaycheckService = new EmployeePaycheckService(mockedRepository.Object); EmployeePaycheck paycheck = new FakeEmployeePaycheck(); paycheck.Id = 2; // Act emplPaycheckService.Create(paycheck); emplPaycheckService.UpdateById(2, paycheck); // Assert mockedRepository.Verify(x => x.Update(paycheck), Times.Once); }
public void GetById_ShouldInvokeOnlyOnce() { // Arrange var mockedRepository = new Mock <IRepository <EmployeePaycheck> >(); var paycheckService = new EmployeePaycheckService(mockedRepository.Object); var paycheck = new FakeEmployeePaycheck(); paycheck.Id = 2; // Act paycheckService.Create(paycheck); paycheckService.GetById(paycheck.Id); // Assert mockedRepository.Verify(r => r.GetById(paycheck.Id), Times.Once); }