public void CreateInstructor_UnderNormalConditions_AddsInstructorToInstructorList() { //arrange var instructorToBeCreated = new InstructorDto() { InstructorName = "test instructor name", IsActive = true }; var originalCountOfInstructors = _instructorList.Count; var mockInstructorRepo = Mock.Create <IInstructorRepository>(); Mock.Arrange(() => mockInstructorRepo.Create(Arg.IsAny <Instructor>())) .DoInstead(() => _instructorList.Add(instructorToBeCreated)) .OccursOnce(); _instructorService = new InstructorService(mockInstructorRepo); //act _instructorService.Create(instructorToBeCreated); var actualCount = _instructorList.Count; //assert Mock.Assert(mockInstructorRepo); Assert.That(actualCount, Is.EqualTo(originalCountOfInstructors + 1)); }
/// <summary> /// Validates the data stored in the Dto being passed through from the Client side /// </summary> public bool ValidateRestData(InstructorDto instructor) { var context = new ValidationContext(instructor); var results = new List <ValidationResult>(); return(Validator.TryValidateObject(instructor, context, results)); }
public async Task Add(InstructorDto ınstructorDto, string path) { HttpResponseMessage response = await _httpClient.PostAsJsonAsync( path, ınstructorDto); response.EnsureSuccessStatusCode(); }
public async Task <ActionResult> LoginPage(LoginUserModel loginUserModel) { if (ModelState.IsValid) { TokenContent rest = await _loginApiService.Authenticate(ApiUrl + "token", loginUserModel); if (rest.access_token != null) { InstructorDto ınstructorDto = await _userApiService.Get(rest.access_token, ApiUrl + "api/User", loginUserModel); string[] roles = new string[ınstructorDto.Roles.Count]; for (int i = 0; i < ınstructorDto.Roles.Count; i++) { ınstructorDto.Roles.ForEach(x => roles[i] = x.Name.ToString()); } AuthenticationHelper.CreateAuthCookie(ınstructorDto.Id, ınstructorDto.UserName, DateTime.Now.AddDays(1), roles, false, ınstructorDto.FirstName, ınstructorDto.LastName); //FormsAuthentication.SetAuthCookie(loginUserModel.Username, false); Session["access_token"] = rest.access_token; return(RedirectToAction("Index", "Home")); } ViewBag.LoginError = "Kullanıcı Adı ve paralo uyuşmamaktadır!"; } return(View(loginUserModel)); }
public async Task <PartialViewResult> UserProfile() { Identity ıdentity = (Identity)HttpContext.User.Identity; InstructorDto ınstructor = await _ınstructorApiService.Get(ApiUrl + "api/Instructor/" + ıdentity.Id, Session["access_token"] as String); return(PartialView("_ProfilePartial", ınstructor)); }
public void CreateInstructor_UnderNormalConditions_ReturnsOkResponse() { //Arrange var instructorToBeCreated = new InstructorDto() { InstructorId = 10, InstructorName = "Wayne Gretzky", IsActive = true }; Mock.Arrange(() => _instructorService.Create(instructorToBeCreated)) .Returns(instructorToBeCreated) .OccursOnce(); var instructorController = new InstructorController(_instructorService) { Request = new HttpRequestMessage() { RequestUri = new Uri("http://localhost/api/instructor/create") } }; //Act var actual = instructorController.Post(instructorToBeCreated) as CreatedNegotiatedContentResult <InstructorDto>; var actualContent = actual.Content; //Assert Mock.Assert(_instructorService); Assert.That(actual, Is.Not.Null); Assert.That(actualContent, Is.EqualTo(instructorToBeCreated)); Assert.That(actual, Is.TypeOf <CreatedNegotiatedContentResult <InstructorDto> >()); }
public IHttpActionResult Post([FromBody] InstructorDto ınstructorDto) { Instructor ınstructor = _autoMapperBase.MapToSameType <InstructorDto, Instructor>(ınstructorDto); _ınstructorService.Add(ınstructor); return(Ok()); }
public async Task <IActionResult> Post([FromBody] InstructorDto newInstructor) { if (newInstructor == null) { return(BadRequest()); } var instructorToCreate = new Instructor(); instructorToCreate.FirstMidName = newInstructor.FirstMidName; instructorToCreate.LastName = newInstructor.LastName; instructorToCreate.HireDate = newInstructor.HireDate; instructorToCreate.OfficeAssignment = null; if (!string.IsNullOrEmpty(newInstructor.Location)) { instructorToCreate.OfficeAssignment = new OfficeAssignment { Location = newInstructor.Location }; } instructorToCreate.CourseAssignments = new List <CourseAssignment>(); foreach (var course in newInstructor.Courses) { var courseToAdd = new CourseAssignment { InstructorID = newInstructor.Id, CourseID = course.CourseID }; instructorToCreate.CourseAssignments.Add(courseToAdd); } _context.Add(instructorToCreate); await _context.SaveChangesAsync(); return(CreatedAtRoute("GetInstructor", new { id = newInstructor.Id })); }
public IHttpActionResult Post(InstructorDto instructor) { using (_instructorService) { var response = _instructorService.Create(instructor); return(Created(new Uri(Request.RequestUri, $"{response.InstructorId}"), response)); } }
public IHttpActionResult Put(InstructorDto instructor) { using (_instructorService) { var response = _instructorService.Update(instructor); return(Ok(response)); } }
public async Task <InstructorDto> AddAsync(InstructorDto addnew) { var uri = API.Instructor.InstructorCommand(_instructorByPassUrl, "Add"); var content = new StringContent(JsonConvert.SerializeObject(addnew), Encoding.UTF8, "application/json"); var response = await _apiClient.PostAsync(uri, content); response.EnsureSuccessStatusCode(); return(addnew); }
public async Task <ActionResult> Create(InstructorDto ınstructor) { if (ModelState.IsValid) { ViewBag.result = await _ınstructorApiService.AddInstructor(ınstructor, ApiUrl + "api/Instructor/", Session["access_token"] as String); } return(View(ınstructor)); }
/// <summary> /// This is the basic 'Update' method for Instructor /// </summary> public async Task <bool> UpdateInstructor(InstructorDto update) { if (instructorLogic.ValidateRestData(update)) { return(await client.UpdateInstructorAsync(instructorLogic.MapToSoap(update))); } else { return(false); } }
/// <summary> /// Changes the active status of an instructor /// This is essentially the 'Delete' method /// </summary> public async Task <bool> DeactivateInstructor(InstructorDto delInstructor) { if (instructorLogic.ValidateRestData(delInstructor)) { return(await client.DeleteInstructorAsync(instructorLogic.MapToSoap(delInstructor))); } else { return(false); } }
/// <summary> /// Attempts to add a new instructor after ensuring that the data entered is valid /// </summary> public async Task <bool> AddNewInstructor(InstructorDto newInstructor) { if (instructorLogic.ValidateRestData(newInstructor)) { return(await client.InsertInstructorAsync(instructorLogic.MapToSoap(newInstructor))); } else { return(false); } }
public InstructorDto Update(InstructorDto entity) { using (_instructorRepository) { var entityToUpdate = entity.ConvertToInstructorDbModel(); _instructorRepository.Update(entityToUpdate); _instructorRepository.SaveChanges(); return(entityToUpdate.ConvertToInstructorDto()); } }
public IHttpActionResult Add([FromBody] InstructorDto instructor) { try { _sqlDA.SaveData <InstructorDto>("dbo.spInstructors_Add", instructor); return(StatusCode(HttpStatusCode.Created)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static Instructor FromDto(this InstructorDto model) { if (model == null) { return(null); } return(new Instructor { Id = model.Id, Name = model.Name, Courses = model.Courses.OrEmptyIfNull().Select(m => m.FromDto()).ToList() }); }
void LoadInstructor() { Instructor = new InstructorDto(); AssignedCourses = new List <AssignedCourseData>(); foreach (var course in Courses) { AssignedCourses.Add(new AssignedCourseData { CourseID = course.Id, Title = course.Title, Assigned = false }); } }
public async Task Save_WhenInstructorDto_AddsInstructorToDb() { //Given DbContextOptions <PeopleContext> options = this.GetCosmosDbToEmulatorOptions <PeopleContext>(); using PeopleContext context = new PeopleContext(options, GetConfig()); string instructorId = GetId(); string instructorEmail = "*****@*****.**"; string assistant1Id = GetId(); string assistant2Id = GetId(); AssistantShortDto assistant1 = new AssistantShortDto() { Id = assistant1Id, Email = "*****@*****.**" }; AssistantShortDto assistant2 = new AssistantShortDto() { Id = assistant2Id, Email = "*****@*****.**" }; EllCoachShortDto coach = new EllCoachShortDto() { Id = GetId(), Email = "*****@*****.**", }; InstructorDto instructor = new InstructorDto() { Id = instructorId, Email = instructorEmail, Assistants = new List <AssistantShortDto>() { assistant1, assistant2 }, EllCoach = coach, Department = Department.EarlyChildhood }; //When context.Add(instructor); await context.SaveChangesAsync(); instructor = await context.FindAsync <InstructorDto>(instructorId); //Then Assert.Equal(instructorId, instructor.Id); Assert.Equal(instructorEmail, instructor.Email); Assert.Equal(assistant1.Id, instructor.Assistants[0].Id); Assert.Equal(assistant2.Id, instructor.Assistants[1].Id); }
public async Task <Boolean> AddInstructor(InstructorDto ınstructor, string path, string accessToken) { _httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken); var stringcontent = new StringContent(JsonConvert.SerializeObject(ınstructor), Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpClient.PostAsync(path, stringcontent); if (response.IsSuccessStatusCode) { return(true); } else { return(false); } }
public async Task <HttpResponseMessage> Delete([FromBody] InstructorDto instructor) { try { var response = Request.CreateResponse(HttpStatusCode.OK, await logic.DeactivateInstructor(instructor)); logger.Info("Delete instructor successful"); return(response); } catch (Exception ex) { LogHelper.ErrorLogger(logger, ex); return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public async Task <JsonResult> EditProfile(InstructorDto ıns) { if (!ModelState.IsValid) { return(Json(new { success = false, errors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList() }, JsonRequestBehavior.AllowGet)); } InstructorDto ınstructor = await _ınstructorApiService.Get(ApiUrl + "api/Instructor/" + ıns.Id, Session["access_token"] as String); ınstructor.FirstName = ıns.FirstName; ınstructor.LastName = ıns.LastName; ınstructor.UserName = ıns.UserName; ınstructor.Password = ıns.Password; Boolean res = await _ınstructorApiService.UpdateInstructor(ınstructor, ApiUrl + "api/Instructor/" + ıns.Id, Session["access_token"] as String); return(Json(res)); }
public async Task <bool> Create(InstructorDto instructor) { var url = $"{_baseUrl}"; var created = false; try { await _client.PostJsonAsync <InstructorDto>(url, instructor); created = true; } catch { created = false; } return(created); }
public async Task <Boolean> UpdateInstructor(InstructorDto ınstructorDto, string path, string accessToken) { _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await _httpClient.PutAsJsonAsync( path, ınstructorDto); response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { return(true); } else { return(false); } }
public async Task <ActionResult> EditInstructor(InstructorDto ıns) { if (ModelState.IsValid) { InstructorDto ınstructor = await _ınstructorApiService.Get(ApiUrl + "api/Instructor/" + ıns.Id, Session["access_token"] as String); ınstructor.FirstName = ıns.FirstName; ınstructor.LastName = ıns.LastName; ınstructor.UserName = ıns.UserName; ınstructor.Password = ıns.Password; Boolean res = await _ınstructorApiService.UpdateInstructor(ınstructor, ApiUrl + "api/Instructor/" + ıns.Id, Session["access_token"] as String); return(RedirectToAction("Index", "Instructor")); } return(View(ıns)); }
public async Task <bool> Update(InstructorDto instructor) { var url = $"{_baseUrl}/{instructor.Id}"; var updated = false; try { await _client.PutJsonAsync <CourseDto>(url, instructor); updated = true; } catch { updated = false; } return(updated); }
public async Task <IActionResult> Create([Bind("LastName,FirstName,HireDate")] InstructorDto addnew) { if (addnew == null) { return(BadRequest()); } try { await _instructorSvc.AddAsync(addnew); return(RedirectToAction(nameof(Index))); } catch (HttpRequestException ex) { return(View(addnew)); } }
public async Task <ActionResult> Put(int id, [FromBody] InstructorDto instructor) { Instructor dbInstructor = await InstructorRepository.GetAsync(id); if (instructor == null) { return(BadRequest()); } Mapper.Map(instructor, dbInstructor); if (!InstructorRepository.Update(dbInstructor)) { throw new Exception($"Updating a instructor {id} failed on save."); } return(NoContent()); }
public async Task <InstructorDto> Get(string accessToken, string path, LoginUserModel userModal) { InstructorDto ınstructorDto = new InstructorDto(); _httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken); HttpResponseMessage response = await _httpClient.PostAsJsonAsync(path, userModal); if (response.IsSuccessStatusCode) { ınstructorDto = JsonConvert.DeserializeObject <InstructorDto>(await response.Content.ReadAsStringAsync()); return(ınstructorDto); } else { ınstructorDto = null; } return(ınstructorDto); }