Example #1
0
        public void WhenRetrievingEmployeeByIdShouldReturnSingleEmployee()
        {
            // Arrange
            var expectedId = Guid.NewGuid();
            var employeeRepositoryMock = new Mock<IEntityRepository<Employee>>(MockBehavior.Strict);
            employeeRepositoryMock.Setup(r => r.Single(It.IsAny<IQueryObject<Employee>>(), It.IsAny<string[]>()))
                                  .Returns(new Employee { Id = expectedId });
            var employeeService = new EmployeeService(employeeRepositoryMock.Object);

            // Act
            var actual = employeeService.SingleById(expectedId);

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedId, actual.Id);
            employeeRepositoryMock.Verify(r => r.Single(It.IsAny<IQueryObject<Employee>>(), It.IsAny<string[]>()), Times.Once());
        }
Example #2
0
        public void WhenFilterEmployeesByNameShouldReturnEmployees()
        {
            // Arrange
            var employeeList = this.GetEmployeeList();
            var argument = "arcos";
            var expectedList = employeeList.Where(e => e.FirstName.Contains(argument) || e.LastName.Contains(argument)).ToList();
            var employeeRepositoryMock = new Mock<IEntityRepository<Employee>>(MockBehavior.Strict);
            employeeRepositoryMock.Setup(r => r.FindBy(It.IsAny<IQueryObject<Employee>>(), It.IsAny<string[]>()))
                                  .Returns(expectedList);
            var employeeService = new EmployeeService(employeeRepositoryMock.Object);

            // Act
            var actual = employeeService.FilterByName(argument);

            // Assert
            Assert.IsNotNull(actual);
            CollectionAssert.AreEqual(expectedList, actual.ToList());
            employeeRepositoryMock.Verify(r => r.FindBy(It.IsAny<IQueryObject<Employee>>(), It.IsAny<string[]>()), Times.Once());
        }
Example #3
0
        public void GetEmployeeById()
        {
            // Arrange
            var repository = new EntityRepository<Employee>(this.Context);
            var employeeService = new EmployeeService(repository);
            var expectedFirstName = "TestName";
            var expectedLastName = "TestLastName";
            var expectedEmail = "*****@*****.**";
            var employee = this.CreateEmployee(expectedFirstName, expectedLastName, expectedEmail);
            var savedEmployee = employeeService.Save(employee);

            // Act
            var actual = employeeService.SingleById(savedEmployee.Id);

            // Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedFirstName, actual.FirstName);
            Assert.AreEqual(expectedLastName, actual.LastName);
            Assert.IsNotNull(actual.Profile);
            Assert.IsNotNull(actual.Profile.Bio);
        }