Ejemplo n.º 1
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            jobNew.SetCarID(carID);
            jobNew.SetStartDate(DateTimeStart.Text);
            jobNew.SetEndDate(DateTimeEnd.Text);
            jobNew.SetProblem(TextBoxProblem.Text);
            jobNew.SetSolution(TextBoxSolution.Text);
            if (TextBoxMilage.Text != "")
            {
                jobNew.SetMilage(Int32.Parse(TextBoxMilage.Text));
            }
            if (TextBoxCost.Text != "")
            {
                jobNew.SetCost(float.Parse(TextBoxCost.Text));
            }
            if (TextBoxRevenue.Text != "")
            {
                jobNew.SetRevenue(float.Parse(TextBoxRevenue.Text));
            }

            if (jobOld == null)
            {
                jobsController.CreateJob(jobNew);
            }
            else
            {
                jobsController.EditJob(jobNew, jobOld);
            }

            Close();
        }
        public async Task CreateWithNullAndBadRequestObjectResult()
        {
            // Arrange & Act
            var mockRepo   = new Mock <IRepository>();
            var controller = new JobsController(mockRepo.Object, _logger);

            controller.ModelState.AddModelError("Error", "Null job object inputted");
            mockRepo.Setup(repo => repo.Create <Job>(null));

            // Act
            var result = await controller.CreateJob(null);

            // Assert
            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.IsType <SerializableError>(badRequestResult.Value);

            _logger.Log(LogLevel.Debug, 0, "Logging exeution of method CreateWithNullAndBadRequestObjectResult", null, null);
        }
        public async Task CreateJobValidModelWithOkResult()
        {
            // Arrange & Act
            var mockRepo   = new Mock <IRepository>();
            var controller = new JobsController(mockRepo.Object, _logger);

            var fastenJob = new Job {
                JobId = 14001, Name = "Fasten Job"
            };

            mockRepo.Setup(repo => repo.Create(fastenJob)).Returns(Task.FromResult(fastenJob));

            // Act
            var jobsModel = JobAssistantMapper.Map <JobModel>(fastenJob);
            var result    = await controller.CreateJob(jobsModel);

            // Assert
            Assert.IsType <OkResult>(result);

            _logger.Log(LogLevel.Debug, 0, "Logging exeution of method CreateJobValidModelWithOkResult", null, null);
        }