private void SaveCompany() { CreateCompanyModel createCompanyModel = new CreateCompanyModel(razaoSocialTextBox.Text , fantasiaTextBox.Text , cnpjTextBox.Text , telefoneTextBox.Text , emailTextBox.Text); if (createCompanyModel.Invalid) { foreach (var item in createCompanyModel.Notifications) { switch (item.Property) { case "Email": emailLabel.Text = item.Message; break; case "CNPJ": cnpjLabel.Text = item.Message; break; case "Razão Social": nameLabel.Text = item.Message; break; } } } else { CompanyController.CreateCompany(createCompanyModel); ClearFields(); this.Close(); } }
public void CreateCompanyTest() { // Arrange CompanyController controller = new CompanyController(new TestDataHandler()); CompanyModel company = new CompanyModel { Isin = "IE1234567899", exchange = "ISEQ", name = "Brian Inc", ticker = "BAJQ", website = "https://www.startrek.com" }; // Act var result = controller.CreateCompany(company); IHttpActionResult actionResult = controller.GetCompanies(); OkNegotiatedContentResult <List <CompanyModel> > companyList = actionResult as OkNegotiatedContentResult <List <CompanyModel> >; // Assert Assert.IsTrue(companyList.Content.Contains(company)); }
public void UpdateCompanyTest() { // Arrange CompanyController controller = new CompanyController(new TestDataHandler()); CompanyModel expectedCompany = new CompanyModel { Isin = "IE1234567899", exchange = "ISEQ", name = "Brian Inc", ticker = "BAJQ", website = "https://www.startrek.com" }; controller.CreateCompany(expectedCompany); // Act var result = controller.UpdateCompany(new CompanyModel { Isin = "IE1234567899", exchange = "NASDAQ", name = "Brian Q Inc", ticker = "BAJQ", website = "https://www.starwars.com" }); IHttpActionResult actionResult = controller.GetCompanyByISIN("IE1234567899"); OkNegotiatedContentResult <CompanyModel> actualCompany = actionResult as OkNegotiatedContentResult <CompanyModel>; // Assert Assert.AreEqual(expectedCompany.Isin, actualCompany.Content.Isin); Assert.AreNotEqual(expectedCompany, actualCompany.Content); }
public void CreateExistingCompanyTest() { // Arrange CompanyController controller = new CompanyController(new TestDataHandler()); IHttpActionResult expectedActionResult = controller.GetCompanies(); OkNegotiatedContentResult <List <CompanyModel> > expectedCompanyList = expectedActionResult as OkNegotiatedContentResult <List <CompanyModel> >; int expectedCount = expectedCompanyList.Content.Count; // Act // Try to add an existing company to the list IHttpActionResult result = controller.CreateCompany(expectedCompanyList.Content.First()); NegotiatedContentResult <string> response = result as NegotiatedContentResult <string>; IHttpActionResult actualActionResult = controller.GetCompanies(); OkNegotiatedContentResult <List <CompanyModel> > actualCompanyList = actualActionResult as OkNegotiatedContentResult <List <CompanyModel> >; // Assert Assert.IsNotNull(result); Assert.IsTrue(response.StatusCode == HttpStatusCode.BadRequest); Assert.IsTrue(actualCompanyList.Content.Count == expectedCount); }