public void CreateCompanySouldCreateCompanyAndAddInDb() { var options = new DbContextOptionsBuilder <TaskPlannerDbContext>() .UseInMemoryDatabase(databaseName: "Company_CreateCompany_Database") .Options; var dbContext = new TaskPlannerDbContext(options); var companyModel = new CompanyCreateViewModel { Name = "DataCenter", Address = "asd", FieldOfService = "IT" }; var user = new ApplicationUser { Email = "*****@*****.**", FullName = "Pesho Peshev" }; var companyService = new CompanyService(dbContext, null); companyService.CreateCompany(companyModel, user); var company = dbContext.Companies.FirstOrDefault(x => x.Name == companyModel.Name); Assert.Equal(companyModel.Name, company.Name); Assert.Equal(companyModel.Address, company.Address); Assert.Equal(companyModel.FieldOfService, company.FieldOfService); }
public ActionResult CompanyCreate([DataSourceRequest] DataSourceRequest request, CompanyItem companyItem) { if (companyItem != null && ModelState.IsValid) { service.CreateCompany(companyItem); } return(Json(new[] { companyItem }.ToDataSourceResult(request, ModelState))); }
public void CreateCompany_Test() { var createComapny = new CreateCompany(); companyRepoMock.Setup(x => x.CreateCompany(It.IsAny <Company>())).Verifiable(); comapnyService.CreateCompany(createComapny); companyRepoMock.Verify(x => x.CreateCompany(It.IsAny <Company>()), Times.Once); }
public async Task <ActionResult> Register(CreateUserModel model) { if (!ModelState.IsValid) { model.LicenseList = defaultLicenseRepository.GetAll(); return(View(model)); } var createCompanyResult = companyService.CreateCompany(model.CompanyName, model.CompanyUrl, model.LicenseName); if (!createCompanyResult.Succed) { ModelState.AddModelError("", createCompanyResult.GetMessage()); model.LicenseList = defaultLicenseRepository.GetAll(); return(View(model)); } var company = createCompanyResult.GetResult(); var userInfo = new CreateUser() { UserName = model.UserName, Role = Roles.Customer, Comapany = company, FirstName = model.FirstName, LastName = model.LastName, Password = model.Password, PhoneNumber = model.PhoneNumber, Email = model.Email }; var createUserResult = await companyService.CreateUserAsync(userInfo, userManager); if (!createUserResult.Succed) { ModelState.AddModelError("", createUserResult.GetMessage()); model.LicenseList = defaultLicenseRepository.GetAll(); return(View(model)); } var user = createUserResult.GetResult(); await signInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Index", "Home")); }
protected async void CreateCompany() { Company.Creator = CurrentUser; var result = await CompanyService.CreateCompany(Company); CurrentUser.Company = result; Company = new Company(); IsInCompany = true; StateHasChanged(); }
public async void CreateCompany() { var CompanyService = new CompanyService(new MongoDataProvider("mongodb://localhost:27017")); var result = await CompanyService.CreateCompany(new CompanyEntity() { Identifier = "id" }); Assert.NotNull(result); Assert.True(result.Success); }
public void company_insert_new() { Company newObject = new Company(); Mock <IBusinessEngineFactory> mockBusinessEngineFactory = new Mock <IBusinessEngineFactory>(); mockBusinessEngineFactory.Setup(mock => mock.GetBusinessEngine <ICompanyBusinessEngine>().CompanySave(newObject)).Returns(123); CompanyService service = new CompanyService(mockBusinessEngineFactory.Object); int update_ret_val = service.CreateCompany(newObject); Assert.IsTrue(update_ret_val == 123); }
public void CreateCompany_ImplementsIRepository() { var repoMock = new Moq.Mock <ICompanyStateRepository>(); var sut = new CompanyService(repoMock.Object, new DateTimeProvider()); var stateMock = new Mock <ICompanyState>(); repoMock.Setup(t => t.CreateCompanyState(It.IsAny <Guid>(), It.IsAny <string>())).Returns(stateMock.Object); var guid = Guid.NewGuid(); var name = "New Company"; sut.CreateCompany(guid, name); repoMock.Verify(s => s.CreateCompanyState(guid, name), Times.Once); }
public HttpResponseMessage Create([FromBody] Company company) { Console.WriteLine("[HttpPost] -> /company/create"); var response = new HttpResponseMessage(); var serviceOperationResult = companyService.CreateCompany(company); if (serviceOperationResult.Id != 0) { response = Request.CreateResponse <long>(HttpStatusCode.Created, serviceOperationResult.Id); } else { response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, serviceOperationResult.Message); } return(response); }
public void CompanyService_CreateCompany_CompanyIsNull_FailResult() { var mock = new Mock <ICompanyProvider>(); mock.Setup(a => a.CreateCompany(It.IsAny <Company>())) .Returns(new Company()); ICompanyService service = new CompanyService(mock.Object, new Mock <ILogger>().Object); Company newCompany = null; ServiceResult <Company> result = null; Assert.DoesNotThrow(() => result = service.CreateCompany(newCompany)); Assert.IsNotNull(result); Assert.IsTrue(result.IsErrored); Assert.IsNull(result.Result); }
// POST /api/Company public IHttpActionResult Post(CompanyCreateViewModel company) { if (company == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CompanyService companyService = CreateCompanyService(); companyService.CreateCompany(company); return(Ok()); }
public ActionResult CompanyCreate(CompanyViewModel item) { if (ModelState.IsValid) { CompanyDTO companyDTO = new CompanyDTO(); companyDTO.Id = item.Id; companyDTO.Name = item.Name; companyDTO.Size = item.Size; companyDTO.OrganizationalForm = item.OrganizationalForm; companyService.CreateCompany(companyDTO); TempData["message"] = string.Format("Компания успешно добавлена"); return(RedirectToAction("Companies")); } else { return(View(item)); } }
public void CompanyService_CreateCompany_SuccessResult() { var mock = new Mock <ICompanyProvider>(); mock.Setup(a => a.CreateCompany(It.IsAny <Company>())) .Returns(new Company()); ICompanyService service = new CompanyService(mock.Object, new Mock <ILogger>().Object); var newCompany = new Company { Name = "Name" }; ServiceResult <Company> result = null; Assert.DoesNotThrow(() => result = service.CreateCompany(newCompany)); Assert.IsNotNull(result); Assert.IsFalse(result.IsErrored); Assert.IsInstanceOf <Company>(result.Result); }
public void TestCreateCompanyBehaviour() { Mock <ICompanyRepository> mock = new Mock <ICompanyRepository>(); CompanyService cService = new CompanyService(mock.Object); Company c = new Company { CompanyName = "Test Company", CompanyCode = 123, isCash = true, EventId = 1, AdditionalInfo = "First Test Company" }; cService.CreateCompany(c); mock.Verify(mock => mock.CreateCompany(c), Times.Once); }
public void CreateCompany() { var repository = new Mock <IRepository <Company> >(); var empService = new Mock <IEmployeeService>(); var compEmplSer = new Mock <ICompanyEmployeeService>(); var compService = new Mock <ICompanyService>(); var service = new CompanyService(repository.Object, empService.Object, compEmplSer.Object); var company = new CreateCompanyRequest { CompanyName = "Test", PrimeContactID = 2, IsLive = true }; var companyResponse = new CompanyResponse { CompanyName = "Test", IsLive = true }; compService.Setup(r => r.CreateCompany(company)).ReturnsAsync(companyResponse); var result = service.CreateCompany(company); Assert.That(result, Is.Not.Null); }
/// controls div END public async Task AddCompany() { if (NewCompany != null) { try { Validator.ValidateObject(NewCompany, new ValidationContext(NewCompany)); await CompanyService.CreateCompany(NewCompany); await AddLog(ActionMesage : ActionMessage + ": " + NewCompany.TradingName); await TempService.UpdateCompanies(); await Close(); } catch (Exception ex) { ExceptionLabel = ex.Message; ExceptionLabelDisplay = "block"; } await InvokeAsync(StateHasChanged); } }
public async Task CreateCompanyTestShouldPass() { CompanyViewModel company2 = new CompanyViewModel { ISIN = "RU0378331405", Exchange = "NYSE", Ticker = "VODs LN", Name = "Uber", WebSite = "www.company.com" }; var context = await CreateDbContext("createCompany"); var service = new CompanyService(context); await service.CreateCompany(company2); var results = await service.GetCompanys(); var count = results.Results.Count(); Assert.AreEqual(3, count); }
public void CreateCompany_GivenAValidCompany_ShouldCallAddressRepositoryUpsertCompanyAddressOncePlusOtherAddressesCount() { //Arrange var company = GetCorrectCompanyModel(); var companyRepositoryMock = new Mock <ICompanyRepository>(); companyRepositoryMock.Setup(repository => repository.CreateCompany(It.IsAny <Company>())) .Returns(Guid.NewGuid()); var addressRepositoryMock = new Mock <IAddressRepository>(); addressRepositoryMock.Setup(repository => repository.UpsertCompanyAddress(It.IsAny <CompanyAddress>())) .Returns(Guid.NewGuid()); var companyService = new CompanyService(companyRepositoryMock.Object, addressRepositoryMock.Object); //Act var result = companyService.CreateCompany(company); //Assert addressRepositoryMock.Verify(repository => repository.UpsertCompanyAddress(It.IsAny <CompanyAddress>()), Times.Exactly(1 + company.OtherAddresses.Length)); }
public void CreateCompany_GivenAValidCompany_ShouldCallCompanyRepositoryCreateCompanyOnce() { //Arrange var company = GetCorrectCompanyModel(); var companyRepositoryMock = new Mock <ICompanyRepository>(); companyRepositoryMock.Setup(repository => repository.CreateCompany(It.IsAny <Company>())) .Returns(company.Id); var addressRepositoryMock = new Mock <IAddressRepository>(); addressRepositoryMock.Setup(repository => repository.UpsertCompanyAddress(It.IsAny <CompanyAddress>())) .Returns(Guid.NewGuid()); var companyService = new CompanyService(companyRepositoryMock.Object, addressRepositoryMock.Object); //Act var result = companyService.CreateCompany(company); //Assert companyRepositoryMock.Verify(repository => repository.CreateCompany(It.Is <Company>( companyEntity => companyEntity.Id == company.Id)), Times.Once); }
public ActionResult CreateCompany(AdminViewModel model) { _companyService.CreateCompany(model.Company.Name); return(RedirectToAction("Index")); }
public async Task Create([FromBody] CompanyViewModel companyModel) { await companyService.CreateCompany(companyModel); }