public async void Handle_ReturnsListOfEmployees()
        {
            employees = A.CollectionOfDummy <Employee>(5);
            database.Employees.AddRange(employees);
            await database.SaveChangesAsync(CancellationToken.None);

            var request = A.Dummy <GetEmployees>();

            var result = await sut.Handle(request, CancellationToken.None);

            result.Should().BeEquivalentTo(employees);
        }
Пример #2
0
        public async Task <Unit> Handle(DeleteEmployee request, CancellationToken token)
        {
            var employee = await database.Employees
                           .FirstOrDefaultAsync(o => o.EmployeeId == request.EmployeeId, token);

            if (employee == null)
            {
                return(Unit.Value);
            }

            database.Employees.Remove(employee);

            await database.SaveChangesAsync(token);

            return(Unit.Value);
        }
Пример #3
0
        public async void Handle_ReturnsTheSalaryForAnEmployee()
        {
            var employee = new Employee
            {
                EmployeeId   = Guid.NewGuid(),
                EmployeeName = "Mark",
                Salary       = 100000m
            };

            database.Employees.Add(employee);
            await database.SaveChangesAsync(CancellationToken.None);

            var request = A.Dummy <GetSalaryForEmployee>();

            request.EmployeeId = employee.EmployeeId;

            var response = await sut.Handle(request, CancellationToken.None);

            response.Should().Be(employee.Salary);
        }
Пример #4
0
        public async Task <Unit> Handle(AddEmployee request, CancellationToken token)
        {
            var found = await database.Employees
                        .FirstOrDefaultAsync(o => o.EmployeeId == request.EmployeeId, token);

            if (found != null)
            {
                return(Unit.Value);
            }

            var employee = new Employee
            {
                EmployeeId   = request.EmployeeId,
                Salary       = request.Salary,
                EmployeeName = request.EmployeeName
            };

            database.Employees.Add(employee);

            await database.SaveChangesAsync(token);

            return(Unit.Value);
        }