public IActionResult EditTherapistType(EditTherapistTypeDTO edit) { if (edit == null || string.IsNullOrEmpty(edit.Type)) { return(BadRequest()); } TherapistType therapistType = _therapistRepo.GetTherapistType(edit.Id); if (therapistType == null || !_categoryRepository.CategoriesExist(edit.Categories)) { return(BadRequest()); } therapistType.Categories = _categoryRepository.GetCategoriesById(edit.Categories).ToList(); therapistType.Type = edit.Type; _therapistRepo.EditTherapistType(therapistType); try { _therapistRepo.SaveChanges(); return(Ok()); } catch (Exception) { return(StatusCode(500)); } }
public void EditTherapistType_ReturnsBadRequest() { EditTherapistTypeDTO editTherapistTypeDTO = _dummyData.EditTherapistTypeDTO; _therapistRepository.Setup(tr => tr.GetTherapistType(0)).Returns(_dummyData.TherapistTypes.First); _categoryRepository.Setup(cr => cr.CategoriesExist(editTherapistTypeDTO.Categories)).Returns(false); _categoryRepository.Setup(cr => cr.GetCategoriesById(editTherapistTypeDTO.Categories)).Returns(_dummyData.Categories); var okResult = _therapistsController.EditTherapistType(editTherapistTypeDTO) as StatusCodeResult; Assert.NotNull(okResult); Assert.Equal(400, okResult.StatusCode); }
public void EditTherapistType_ReturnsOk() { EditTherapistTypeDTO editTherapistTypeDTO = _dummyData.EditTherapistTypeDTO; _categoryRepository.Setup(cr => cr.CategoriesExist(editTherapistTypeDTO.Categories)).Returns(true); _therapistRepository.Setup(tr => tr.GetTherapistType(editTherapistTypeDTO.Id)).Returns(_dummyData.TherapistTypes.First); _categoryRepository.Setup(cr => cr.GetCategoriesById(editTherapistTypeDTO.Categories)).Returns(_dummyData.Categories); _therapistRepository.Setup(tr => tr.TherapistTypeExists(It.IsAny <TherapistType>())).Returns(true); _therapistRepository.Setup(tr => tr.EditTherapistType(It.IsAny <TherapistType>())); var okResult = _therapistsController.EditTherapistType(editTherapistTypeDTO) as OkResult; Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); }
//Init used data public DummyProject3_BackendContext() { // Create objects Category category1 = new Category { CategoryId = 0, Name = "Afvallen" }; Challenge challenge1 = new Challenge { ChallengeId = 0, ChallengeImage = "Image url", Description = "Loop 1500 meter", Title = "First run" }; Challenge challenge2 = new Challenge { ChallengeId = 1, ChallengeImage = "Image url", Description = "Loop 2000 meter", Title = "Second run" }; Company company1 = new Company { CompanyId = 0, City = "Wetteren", Contract = new DateTime(2020, 05, 15), Country = "België", HouseNumber = 3, Mail = "*****@*****.**", Name = "Xenox", Phone = "0474139526", PostalCode = 9230, Site = "www.google.com", Street = "Kalkensteenweg" }; User user1 = new User { UserId = 0, Phone = "0473139526", Contract = new DateTime(2020, 05, 15), Email = "*****@*****.**", ExperiencePoints = 0, FamilyName = "Grillaert", FirstName = "Ruben" }; User user2 = new User { UserId = 1, Phone = "0412345678", Contract = new DateTime(2020, 05, 15), Email = "*****@*****.**", ExperiencePoints = 0, FamilyName = "Boel", FirstName = "Arno" }; Therapist therapist1 = new Therapist { TherapistId = 0, City = "stad", Email = "*****@*****.**", FirstName = "Thor", HouseNumber = 2, LastName = "Krets", PhoneNumber = "093661686", PostalCode = 9000, Street = "straat", Website = "www.test.be" }; OpeningTimes openingTimes1 = new OpeningTimes { OpeningTimesId = 0, Interval = "09:00 - 18:30" }; OpeningTimes openingTimes2 = new OpeningTimes { OpeningTimesId = 1, Interval = "09:00 - 18:30" }; TherapistType therapistType1 = new TherapistType { TherapistTypeId = 0, Type = "therapisttype", }; // Create many to many objects ChallengeUser challengeUser1 = new ChallengeUser { Challenge = challenge1, ChallengeId = challenge1.ChallengeId, ChallengeUserId = 0, User = user1, UserId = user1.UserId }; ChallengeUser challengeUser2 = new ChallengeUser { Challenge = challenge2, ChallengeId = challenge2.ChallengeId, ChallengeUserId = 1, User = user1, UserId = user1.UserId }; TherapistUser therapistUser1 = new TherapistUser { TherapistUserId = 0, Therapist = therapist1, TherapistId = therapist1.TherapistId, User = user1, UserId = user1.UserId }; TherapistUser therapistUser2 = new TherapistUser { TherapistUserId = 1, Therapist = therapist1, TherapistId = therapist1.TherapistId, User = user2, UserId = user2.UserId }; // Set connections between objects challenge1.Category = category1; challenge2.Category = category1; company1.CompanyMembers = new List <User>() { user1, user2 }; therapist1.OpeningTimes = new List <OpeningTimes>() { openingTimes1 }; therapist1.TherapistType = therapistType1; therapistType1.Categories = new List <Category>() { category1 }; user1.Categories = new List <CategoryUser>() { new CategoryUser() { CategoryId = category1.CategoryId, Category = category1, User = user1, UserId = user1.UserId } }; user2.Categories = new List <CategoryUser>() { new CategoryUser() { CategoryId = category1.CategoryId, Category = category1, User = user2, UserId = user2.UserId } }; user1.Challenges = new List <ChallengeUser>() { challengeUser1, challengeUser2 }; user2.Challenges = new List <ChallengeUser>(); user1.Company = company1; user2.Company = company1; user1.Therapists = new List <TherapistUser>() { therapistUser1 }; user2.Therapists = new List <TherapistUser>() { therapistUser2 }; // Init properties Category = category1; Categories = new[] { category1 }; Companies = new[] { company1 }; Challenges = new[] { challenge1, challenge2 }; Therapists = new[] { therapist1 }; Users = new[] { user1, user2 }; ChallengesUser = new[] { challengeUser1, challengeUser2 }; TherapistTypes = new[] { therapistType1 }; OpeningTimes = new[] { openingTimes1, openingTimes2, openingTimes2, openingTimes2, openingTimes2, openingTimes2, openingTimes2 }; // Create DTO's AddUserDTO = new AddUserDTO { Categories = new List <int>() { 1 }, Company = 1, Email = "*****@*****.**", FamilyName = "test", FirstName = "test", Phone = "0471236548", Therapists = new List <int>() { 1 } }; EditUserDTO = new EditUserDTO { Categories = new List <int>() { 1 }, Email = "*****@*****.**", FamilyName = "test", FirstName = "test", Phone = "0471236548", UserId = 1, Contract = new DateTime() }; AddTherapistDTO = new AddTherapistDTO { City = "test", Email = "test", FirstName = "test", HouseNumber = 1, LastName = "test", PhoneNumber = "test", PostalCode = 9000, Street = "test", TherapistTypeId = 0, Website = "test" }; AddTherapistTypeDTO = new AddTherapistTypeDTO { Categories = new List <int>() { 1 }, Type = "test" }; EditTherapistDTO = new EditTherapistDTO { City = "test", Email = "test", FirstName = "test", HouseNumber = 1, LastName = "test", PhoneNumber = "test", PostalCode = 5000, Street = "test", TherapistId = 0, Website = "test", TherapistTypeId = 0, OpeningTimes = new List <OpeningTimes>() { new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 } } }; EditTherapistTypeDTO = new EditTherapistTypeDTO { Id = 0, Categories = new List <int>() { 0 }, Type = "therapisttype" }; AddCompanyDTO = new AddCompanyDTO { City = "test", Contract = new DateTime(), Country = "test", HouseNumber = 3, Mail = "test", Name = "test", Phone = "test", PostalCode = 9000, Site = "test", Street = "test" }; EditCompanyDTO = new EditCompanyDTO { City = "test", Contract = new DateTime(), Country = "test", HouseNumber = 3, Mail = "test", Name = "test", Phone = "test", PostalCode = 9000, Site = "test", Street = "test", CompanyId = 0, CompanyMembers = new List <User>() { user1, user2 } }; AddChallengeDTO = new AddChallengeDTO { CategoryId = 0, ChallengeImage = "test", Description = "test", Title = "test" }; CompleteChallengeDTO = new CompleteChallengeDTO { ChallengeID = 0, UserID = 0, Rating = 3, Feedback = "test", CompletedOn = CompleteChallengeDate }; ChallengesUserDTO = new ChallengesUserDTO { ChallengeIds = new List <int>() { 0 }, UserId = 0 }; EditAppUserDTO = new EditAppUserDTO { UserId = 1, Email = "*****@*****.**", FamilyName = "test", FirstName = "tests", Phone = "0474139526" }; //UserManager IdentityUser = new IdentityUser(); }