public async Task Should_Create_Many_Companies_Success_Via_Service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; var context = scopedServices.GetRequiredService <CompanyDbContext>(); CompanyService companyService = new CompanyService(context); 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", }; await companyService.AddCompany(companyDto); await companyService.AddCompany(companyDto); Assert.Equal(2, context.Companies.Count()); }
public async Task Should_create_many_companies_success_Service_Test() { //given 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", }; var context = GetContext(); var companyService = new CompanyService(context); //when await companyService.AddCompany(companyDto); await companyService.AddCompany(companyDto); //then Assert.Equal(2, context.Companies.Count()); }
public async Task Should_get_allcompanies_success_via_company_service() { await companyService.AddCompany(companyDto); List <CompanyDto> companyDtos = await companyService.GetAll(); Assert.Equal(1, context.Companies.Count()); Assert.Equal(companyDto.Employees.Count, companyDtos[0].Employees.Count); Assert.Equal(companyDto.Employees[0].Age, companyDtos[0].Employees[0].Age); Assert.Equal(companyDto.Employees[0].Name, companyDtos[0].Employees[0].Name); Assert.Equal(companyDto.Profile.CertId, companyDtos[0].Profile.CertId); Assert.Equal(companyDto.Profile.RegisteredCapital, companyDtos[0].Profile.RegisteredCapital); }
public async Task Should_create_company_employee_profile_success_via_company_service() { // given // when await companyService.AddCompany(companyDto); // then Assert.Equal(1, context.Companies.Count()); Assert.Equal(companyDto.Name, context.Companies.First().Name); Assert.Equal(2, context.Employees.Count()); Assert.Equal(companyDto.Profile.RegisteredCapital, context.Profiles.First().RegisteredCapital); Assert.Equal(companyDto.Profile.CertId, context.Profiles.First().CertId); }
public async Task Should_get_correct_company_by_id_Service_Test() { //given 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", }; CompanyDto companyDto2 = new CompanyDto(); companyDto2.Profile = new ProfileDto() { RegisteredCapital = 20002, CertId = "110", }; companyDto2.Name = "I2BM"; companyDto2.Employees = new List <EmployeeDto>() { new EmployeeDto() { Name = "Tomy", Age = 20, }, }; var context = GetContext(); var companyService = new CompanyService(context); await companyService.AddCompany(companyDto2); var id = await companyService.AddCompany(companyDto); //when var acutalCompany = await companyService.GetById(id); //then Assert.Equal(companyDto, acutalCompany); }
public async Task Should_delete_company_via_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; CompanyDbContext context = scopedServices.GetRequiredService <CompanyDbContext>(); context.Companies.RemoveRange(context.Companies); context.SaveChanges(); 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 id = await companyService.AddCompany(companyDto); await companyService.DeleteCompany(id); Assert.Equal(0, context.Companies.Count()); }
private async void saveCompanyButton_Click(object sender, RoutedEventArgs e) { try { saveCompanyButton.IsEnabled = false; // Create a Company object await _companyService.AddCompany(new Company() { CompanyName = companyNameTexbox.Text }); companyNameTexbox.Text = null; saveCompanyButton.IsEnabled = true; setCompanyAmountLabel(); PopulateCompaniesComboBox(); } catch (ArgumentException ex) { companyNameTexbox.Focus(); companyNameTexbox.SelectAll(); MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public async Task Should_Create_Company_Success_Via_Company_Service() { var companyDto = new CompanyDto { Name = "IBM", Employees = new List <EmployeeDto>() { new EmployeeDto() { Name = "Tom", Age = 20, }, }, Profile = new ProfileDto() { RegisteredCapital = 100010, CertId = "100", }, }; var companyService = new CompanyService(context); await companyService.AddCompany(companyDto); Assert.Equal(1, context.Companies.Count()); }
public async Task Should_Get_Company_Success_Via_Company_Service() { var companyDto = new CompanyDto { Name = "IBM", Employees = new List <EmployeeDto>() { new EmployeeDto() { Name = "Tom", Age = 20, }, }, Profile = new ProfileDto() { RegisteredCapital = 100010, CertId = "100", }, }; var companyService = new CompanyService(context); await companyService.AddCompany(companyDto); var allCompanies = await companyService.GetAll(); Assert.Single(allCompanies); }
public Company Post([FromBody] Company company) { var returnCompany = _companyService.AddCompany(company); HttpContext.Response.StatusCode = (int)HttpStatusCode.Created; return(returnCompany); }
public async Task Should_get_company_by_id_success_via_company_service() { 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", }; var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; var context = scopedServices.GetRequiredService <CompanyDbContext>(); var companyService = new CompanyService(context); var id = await companyService.AddCompany(companyDto); var company = await companyService.GetById(id); Assert.Equal("IBM", company.Name); Assert.Equal("Tom", company.Employees[0].Name); Assert.Equal(19, company.Employees[0].Age); Assert.Equal(100010, company.Profile.RegisteredCapital); Assert.Equal("100", company.Profile.CertId); }
public async Task Should_delete_a_company_by_id_using_CompanyService_DeleteCompany_success() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; var companyContext = scopedServices.GetRequiredService <CompanyDbContext>(); companyContext.Database.EnsureDeleted(); companyContext.Database.EnsureCreated(); CompanyDto companyDto = new CompanyDto { Name = "IBM", Employees = new List <EmployeeDto>() { new EmployeeDto() { Name = "Tom", Age = 19 } }, Profile = new ProfileDto() { RegisteredCapital = 100010, CertId = "100" } }; var companyService = new CompanyService(companyContext); await companyService.AddCompany(companyDto); await companyService.DeleteCompany(1); var i = companyContext.Employees.Count(); var j = companyContext.Profiles.Count(); Assert.Equal(0, companyContext.Companies.Count()); }
public Task StartAsync(CancellationToken cancellationToken) { _companyService.AddCompany(new Company("AMZN")); _companyService.AddCompany(new Company("TSLA")); _companyService.AddCompany(new Company("BLKFNCH")); _companyService.IssueShares("AMZN", 40, 100000); _companyService.IssueShares("TSLA", 420, 10000); _companyService.IssueShares("BLKFNCH", 60, 600); _orderService.AddOrder(new Order("AMZN", 40, 40, 100, OrderType.Buy)); _orderService.AddOrder(new Order("TSLA", 200, 1000, 2000, OrderType.Buy)); _orderService.AddOrder(new Order("BLKFNCH", 60, 60, 300, OrderType.Buy)); return(Task.CompletedTask); }
private void AddCompany() { CompanyService.AddCompany(new Company() { Name = $"Name-{random.Next()}", Timestamp = DateTime.Now, }); }
public JsonResult AddCompany(CompanyViewModel vmodel) { CompanyService.AddCompany(vmodel); return(Json(new JsonResultDataEntity <object>() { Code = 0 })); }
public async void CreateCompany(string name, string description, string keyWordsString, Categories categorie, Owner owner, ICollection <Location> locations, List <OpeningHours> openingHours, string leaveOfAbsence, SocialMedia socialMedia) { // is overwritten in the backend List <Promotion> promotions = null; var company = new Company(name, description, keyWordsString, categorie, owner, locations, openingHours, null, socialMedia, promotions); var responseCompany = await _companyService.AddCompany(company); AlertService.Toast($"{responseCompany.Name} aangemaakt", $"{responseCompany.Name} succesvol toegevoegd"); await _navigationService.NavigateToCompaniesAsync(); }
public void AddCompanyToDabatase_WhenInvokedWithValidParameterAndCompanyNotAlreadyAddedToDatabase() { //Arrange var dbContextMock = new Mock <ISportscardSystemDbContext>(); var mapperMock = new Mock <IMapper>(); var expectedCompany = new Company() { Name = "Company4" }; var data = new List <Company> { new Company { Name = "Company1" }, new Company { Name = "Company2" }, new Company { Name = "Company3" }, }.AsQueryable(); var mockSet = new Mock <DbSet <Company> >(); mockSet.As <IQueryable <Company> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Company> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Company> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Company> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator); mockSet.Setup(m => m.Add(It.IsAny <Company>())); dbContextMock .Setup(x => x.Companies) .Returns(mockSet.Object); var companyDto = new CompanyDto() { Name = "Company4" }; mapperMock .Setup(x => x.Map <Company>(companyDto)) .Returns(expectedCompany); var companyService = new CompanyService(dbContextMock.Object, mapperMock.Object); //Act companyService.AddCompany(companyDto); //Assert mockSet.Verify(x => x.Add(expectedCompany), Times.Once); //Assert.AreEqual(4, mockSet.Object.Count()); }
public void ThrowArgumentNullException_WhenInvokedWithInvalidParameter() { //Arrange var dbContextMock = new Mock <SportscardSystemDbContext>(); var mapperMock = new Mock <IMapper>(); CompanyDto companyDto = null; var companyService = new CompanyService(dbContextMock.Object, mapperMock.Object); //Act && Assert Assert.ThrowsException <ArgumentNullException>(() => companyService.AddCompany(companyDto)); }
public async Task AddAsync(CompanyDto companyDto) { var company = mapper.Map <CompanyDto, Company>(companyDto); companyService.AddCompany(company); await unitOfWork.SaveChangesAsync(); var user = await userService.GetByIdAsync(company.UserId.Value); user.CompanyId = company.Id; await unitOfWork.SaveChangesAsync(); }
public void Add() { var company = new DataLayer.EfClasses.Company { CompanyName = Name, CompanyAddress = Address }; _companyService.AddCompany(company); AssociatedCompany = new CompanyViewModel(company); }
public async Task Should_create_company_success_via_company_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; CompanyDbContext context = scopedServices.GetRequiredService <CompanyDbContext>(); CompanyService companyService = new CompanyService(context); await companyService.AddCompany(companyDto); Assert.Equal(1, context.Companies.Count()); }
public async Task Should_delete_company_and_related_employees_by_id_success_via_company_service() { 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", }; var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; var context = scopedServices.GetRequiredService <CompanyDbContext>(); var companyService = new CompanyService(context); var id = await companyService.AddCompany(companyDto); await companyService.AddCompany(companyDto); await companyService.DeleteCompany(id); var companies = await companyService.GetAll(); Assert.Equal(1, companies.Count); var company = await companyService.GetById(id); Assert.Null(company); }
public IActionResult Create(CompanyCreateVM company) { service.AddCompany(company); cache.Set("supportEmail", company.Email); HttpContext.Session.SetString("CompanyName", company.CompanyName); Response.Cookies.Append("VisitDate", DateTime.Now.ToString(), new CookieOptions { Expires = DateTime.Now.AddDays(7) }); TempData["Message"] = "Dina värden har sparats!"; return(RedirectToAction(nameof(Display))); }
public void ThrowsArgumentException_WhenCompanyWithTheSameNameAlreadyExists() { //Arrange var dbContextMock = new Mock <ISportscardSystemDbContext>(); var mapperMock = new Mock <IMapper>(); var expectedCompany = new Company() { Name = "Company1" }; var data = new List <Company> { new Company { Name = "Company1" }, new Company { Name = "Company2" }, new Company { Name = "Company3" }, }; var mockSet = new Mock <DbSet <Company> >(); mockSet.SetupData(data); mockSet.Setup(m => m.Add(It.IsAny <Company>())); dbContextMock .Setup(x => x.Companies) .Returns(mockSet.Object); var companyDto = new CompanyDto() { Name = "Company1" }; mapperMock .Setup(x => x.Map <Company>(companyDto)) .Returns(expectedCompany); var companyService = new CompanyService(dbContextMock.Object, mapperMock.Object); //Act && Assert Assert.ThrowsException <ArgumentException>(() => companyService.AddCompany(companyDto)); }
/// <summary> /// Author:Gavin /// Description:加入使用企业 /// Create Data:2017-03-18 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult SubmitCompany(string id) { try { LZY.BX.Model.User user = new UserService().Get(CurrentUser.User.UserId); cService.AddCompany(user, id); CurrentUser.User = new MbContext().User.FirstOrDefault(t => t.Account == CurrentUser.User.Phone); AuthMng.Instance.InitUserCookie(HttpContext, new UserCookie( new AuthUser { User = CurrentUser.User, UseCompany = cService.GetCompanyInfo(user), ServiceCompany = CurrentUser.ServiceCompany })); return(ResultSuccess("操作成功.", "../Order/Order")); } catch (DataExistException e) { return(Json(new { error = e.Message })); } }
/// <summary> /// Author:Gavin /// Description:加入使用(服务)企业 /// Create Data:2017-03-18 /// </summary> /// <param name="appType"></param> /// <param name="id"></param> /// <returns></returns> public ActionResult AddCompany(AppType appType, string id) { try { if (AppType.Use == appType) { cService.AddCompany(ApiUser.Current, id); } else if (AppType.Service == appType) { cService.AddServerCompany(ApiUser.Current, id); } //更新缓存 ApiUser.UpdateCurrent(ApiUser.Current.UserId); return(Json(new { status = 0 })); } catch (DataExistException e) { return(Json(new { error = e.Message })); } }
public async Task Should_get_all_company_via_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; CompanyDbContext context = scopedServices.GetRequiredService <CompanyDbContext>(); context.Companies.RemoveRange(context.Companies); context.SaveChanges(); 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.AddCompany(companyDto); var returnCompanies = await companyService.GetAll(); Assert.Equal(1, returnCompanies.Count()); Assert.Equal(1, returnCompanies.Count); Assert.Equal(companyDto.Employees.Count, returnCompanies[0].Employees.Count); Assert.Equal(companyDto.Employees[0].Age, returnCompanies[0].Employees[0].Age); Assert.Equal(companyDto.Employees[0].Name, returnCompanies[0].Employees[0].Name); Assert.Equal(companyDto.Profile.CertId, returnCompanies[0].Profile.CertId); Assert.Equal(companyDto.Profile.RegisteredCapital, returnCompanies[0].Profile.RegisteredCapital); }
public void AddCompany_NewCompany_ReturnOk() { int companiesCount = companyService.GetAll().Count; Assert.AreEqual(3, companiesCount); Company newCompany = new Company() { Id = 0, Name = "Algeiba BS", Cuit = "20-12345678-4", Country = "Arg", Province = "BA", Address = "Parana 771", PhoneNumber = "+5401150204010" }; companyService.AddCompany(newCompany); companiesCount = companyService.GetAll().Count; Assert.AreEqual(4, companiesCount); }
public async Task Should_Create_Company_Success_Via_Service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; var context = scopedServices.GetRequiredService <CompanyDbContext>(); CompanyService companyService = new CompanyService(context); 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", }; await companyService.AddCompany(companyDto); var foundCompany = await context.Companies .Include(company => company.Profile) .Include(company => company.Employees) .FirstOrDefaultAsync(); Assert.Equal(1, context.Companies.Count()); Assert.Equal(companyDto.Employees.Count, foundCompany.Employees.Count); Assert.Equal(companyDto.Employees[0].Age, foundCompany.Employees[0].Age); Assert.Equal(companyDto.Employees[0].Name, foundCompany.Employees[0].Name); Assert.Equal(companyDto.Profile.CertId, foundCompany.Profile.CertId); Assert.Equal(companyDto.Profile.RegisteredCapital, foundCompany.Profile.RegisteredCapital); }
public async Task Should_Return_Company_When_Get_Company_By_Id_Via_Service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; 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", }; CompanyDbContext context = scopedServices.GetRequiredService <CompanyDbContext>(); CompanyService companyService = new CompanyService(context); context.Companies.RemoveRange(context.Companies); context.SaveChanges(); var addReturn = await companyService.AddCompany(companyDto); var getReturn = await companyService.GetById(addReturn); Assert.Equal(companyDto.Employees.Count, getReturn.Employees.Count); Assert.Equal(companyDto.Employees[0].Age, getReturn.Employees[0].Age); Assert.Equal(companyDto.Employees[0].Name, getReturn.Employees[0].Name); Assert.Equal(companyDto.Profile.CertId, getReturn.Profile.CertId); Assert.Equal(companyDto.Profile.RegisteredCapital, getReturn.Profile.RegisteredCapital); }