public async Task Should_create_company_employee_profile_success_via_company_service() { var scope = Factory.Services.CreateScope(); var scopeServices = scope.ServiceProvider; CompanyDbContext context = scopeServices.GetRequiredService <CompanyDbContext>(); CompanyDto companyDto = new CompanyDto(); companyDto.Name = "IBM"; companyDto.Employees = new List <EmployeeDto>() { new EmployeeDto() { Name = "Tom", Age = 19 } }; companyDto.Profile = new ProfileDto() { RegisteredCapital = 100010, CertId = "100", }; CompanyService companyService = new CompanyService(context); await companyService.AddCompanyAsync(companyDto); Assert.Equal(1, context.Companies.Count()); Assert.Equal(companyDto.Employees.Count, context.Companies.Select(company => company.Employees).ToList().Count); Assert.Equal(companyDto.Employees[0].Age, context.Companies.FirstOrDefault().Employees.FirstOrDefault().Age); Assert.Equal(companyDto.Employees[0].Name, context.Companies.FirstOrDefault().Employees.FirstOrDefault().Name); Assert.Equal(companyDto.Profile.CertId, context.Companies.FirstOrDefault().Profile.CertId); Assert.Equal(companyDto.Profile.RegisteredCapital, context.Companies.FirstOrDefault().Profile.RegisteredCapital); }
public async Task Should_delete_company_and_related_employee_and_profile_via_company_service() { var scope = Factory.Services.CreateScope(); var scopeServices = scope.ServiceProvider; CompanyDbContext context = scopeServices.GetRequiredService <CompanyDbContext>(); CompanyDto companyDto = new CompanyDto(); companyDto.Name = "IBM"; companyDto.Employees = new List <EmployeeDto>() { new EmployeeDto() { Name = "Tom", Age = 19 } }; companyDto.Profile = new ProfileDto() { RegisteredCapital = 100010, CertId = "100", }; CompanyService companyService = new CompanyService(context); var companyId = await companyService.AddCompanyAsync(companyDto); await companyService.DeleteCompany(companyId); Assert.Equal(0, context.Companies.Count()); }
public async Task CompanyService_AddCompany() { AddAndEditCompanyBindingModel model = new AddAndEditCompanyBindingModel() { Name = "STP", Description = "Some description" }; AutoMapper.Mapper.Initialize(config => config.AddProfile <AutoMapperProfile>()); var service = new CompanyService(dbContext, AutoMapper.Mapper.Instance); await service.AddCompanyAsync(model); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Name == "STP")); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Description == "Some description")); }
public async Task CompanyService_CompanyDetails() { AddAndEditCompanyBindingModel model = new AddAndEditCompanyBindingModel() { Id = 1, Name = "STPDelete", Description = "Some description" }; dbContext.SaveChanges(); var service = new CompanyService(dbContext, AutoMapper.Mapper.Instance); await service.AddCompanyAsync(model); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Name == "STPDelete")); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Description == "Some description")); var companyDetailsModel = await service.CompanyDetailsAsync(1); Assert.AreEqual(companyDetailsModel.Name, dbContext.Companies.Find(1).Name); Assert.AreEqual(companyDetailsModel.Description, dbContext.Companies.Find(1).Description); }
public async Task CompanyService_DeleteCompany() { AddAndEditCompanyBindingModel model = new AddAndEditCompanyBindingModel() { Id = 1, Name = "STPDelete", Description = "Some description" }; dbContext.SaveChanges(); var service = new CompanyService(dbContext, AutoMapper.Mapper.Instance); await service.AddCompanyAsync(model); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Name == "STPDelete")); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Description == "Some description")); await service.DeleteCompanyAsync(1); Assert.IsNull(dbContext.Companies.FirstOrDefault(c => c.Name == "STPDelete")); Assert.IsNull(dbContext.Companies.FirstOrDefault(c => c.Description == "Some other description")); }