public async Task <Guid> Create(Employee item) { var employee = EmployeeAggregate.Create(item.UserId, item.IsDeleted); await _employeeAggregateRepo.Add(employee); return(employee.Id); }
public void EmployeeUpdateTest() { var employeeBuilder = new EmployeeAggregateBuilder(); var employeeAggregate = employeeBuilder.GetRandomEmployeeAggregate(); var employee = EmployeeAggregate.Update(employeeAggregate.Id, employeeAggregate); employeeAggregate.Should().BeEquivalentTo(employee); }
public async Task <Guid> Create(EmployeeCreateRequest request) { var employee = EmployeeAggregate.CreateFromRequest(request); await _repo.Add(employee); return(employee.Id); }
public void CreateTest() { var builder = new EmployeeAggregateBuilder(); var employee = EmployeeAggregate.Create( builder.userId, builder.isDelete); employee.Should().As <EmployeeAggregate>(); }
public void EmployeeAggregate_CreateRandomFromRequest() { //Arrange var request = AggregatesRequestBuilder.CreateRandomEmployeeCreateRequest(); //Act var employee = EmployeeAggregate.CreateFromRequest(request); // Assert employee.UserId.Should().Be(request.UserId); employee.IsDeleted.Should().BeFalse(); }
public void EmployeeAggregate_ShouldBeDeleted() { //Arrange var request = AggregatesRequestBuilder.CreateRandomEmployeeCreateRequest(); var employee = EmployeeAggregate.CreateFromRequest(request); //Act employee.MarkAsDeleted(); //Assert employee.IsDeleted.Should().BeTrue(); }
public void TestBasicEditCommandHandling() { var target = new EmployeeAggregate(CreateDataModelMock()); var cmd = new EmployeeEditCommand() { Arg = CreateExistingEmployeeModel() }; var results = target.Handle(cmd).ToArray(); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); var empEditedEvent = results.First() as EmployeeEditedEvent; Assert.IsNotNull(empEditedEvent); }
public async Task CreateEmployee(EmployeeAggregate employee) { await UnitOfWorkAsync(async (conn, tran) => { var employeeId = await GetService <IDapperRepository <EmployeeAggregate, long> >().InsertAndGetIdAsync(employee, conn, tran); var userInfo = new UserInfo() { Email = employee.Email, EmployeeId = employeeId, Phone = employee.Phone, UserName = employee.UserName }; var rpcParams = new Dictionary <string, object>() { { "confName", IdentityConstants.SysConfPwdModeName } }; var pwdConfig = await GetService <IServiceProxyProvider>().Invoke <GetSystemConfOutput>(rpcParams, ApiConsts.BasicData.GetSysConfApi); if (pwdConfig == null) { throw new BusinessException("获取用户加密模式失败,请先完成系统初始化"); } var generatePwdMode = ConvertHelper.ParseEnum <GeneratePwdMode>(pwdConfig.ConfigValue); var plainPwd = string.Empty; if (generatePwdMode == GeneratePwdMode.Fixed) { rpcParams = new Dictionary <string, object>() { { "confName", IdentityConstants.SysConfFieldModeName } }; var fixedPwdConf = await GetService <IServiceProxyProvider>().Invoke <GetSystemConfOutput>(rpcParams, ApiConsts.BasicData.GetSysConfApi); if (pwdConfig == null) { throw new BusinessException("未配置员工用户默认密码"); } plainPwd = fixedPwdConf.ConfigValue; } else { plainPwd = PasswordGenerator.GetRandomPwd(IdentityConstants.RandomLen); // :todo email send pwd } userInfo.Password = GetService <IPasswordHelper>().EncryptPassword(userInfo.UserName, plainPwd); await GetService <IDapperRepository <UserInfo, long> >().InsertAsync(userInfo, conn, tran); }, Connection); }
public async Task Update(EmployeeAggregate item) { _context.Employees.Update(item); await _context.SaveChangesAsync(); }
public async Task Add(EmployeeAggregate item) { await _context.Employees.AddAsync(item); await _context.SaveChangesAsync(); }
public void TestBasicPayCalculation() { var target = new EmployeeAggregate(CreateDataModelMock()); var cmd = new EmployeeCreateCommand() { Arg = CreateNewEmployeeModel() }; var results = target.Handle(cmd).ToArray(); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); var empCreatedEvent = results.First() as EmployeeCreatedEvent; Assert.IsNotNull(empCreatedEvent); Assert.AreEqual(2000M, empCreatedEvent.Data.GrossPay); Assert.AreEqual(38M, empCreatedEvent.Data.Benefits); Assert.AreEqual(1962M, empCreatedEvent.Data.NetPay); }
public void TestBasicPayWithDependentCalculation() { var target = new EmployeeAggregate(CreateDataModelMock()); var arg = CreateNewEmployeeModel(); arg.Dependents = new DependentModel[] { new DependentModel() { Name = "OtherGuy" } }; var cmd = new EmployeeCreateCommand() { Arg = arg }; var results = target.Handle(cmd).ToArray(); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); var empCreatedEvent = results.First() as EmployeeCreatedEvent; Assert.IsNotNull(empCreatedEvent); Assert.AreEqual(2000M, empCreatedEvent.Data.GrossPay); Assert.AreEqual(57M, empCreatedEvent.Data.Benefits); Assert.AreEqual(1943M, empCreatedEvent.Data.NetPay); }
public EmployeeAggregate GetRandomEmployeeAggregate() { var employeeAggregate = EmployeeAggregate.Create(userId, isDelete); return(employeeAggregate); }