Example #1
0
        public void EditTherapist_ReturnsBadRequest()
        {
            EditTherapistDTO editTherapistDTO = _dummyData.EditTherapistDTO;

            _therapistRepository.Setup(tr => tr.TherapistTypeExists(editTherapistDTO.TherapistTypeId)).Returns(false);
            _therapistRepository.Setup(tr => tr.HasInvalidOpeningTimes(It.IsAny <IList <string> >())).Returns(true);
            _therapistRepository.Setup(tr => tr.UpdateTherapist(It.IsAny <Therapist>()));
            var okResult = _therapistsController.EditTherapist(editTherapistDTO) as BadRequestResult;

            Assert.IsType <BadRequestResult>(okResult);
        }
Example #2
0
 public static Therapist MapEditTherapistDTOToTherapist(EditTherapistDTO therapist, Therapist edited, TherapistType tt)
 {
     edited.City          = therapist.City;
     edited.Email         = therapist.Email;
     edited.FirstName     = therapist.FirstName;
     edited.HouseNumber   = therapist.HouseNumber;
     edited.LastName      = therapist.LastName;
     edited.PhoneNumber   = therapist.PhoneNumber;
     edited.PostalCode    = therapist.PostalCode;
     edited.Street        = therapist.Street;
     edited.Website       = therapist.Website;
     edited.TherapistType = tt;
     return(edited);
 }
        public IActionResult EditTherapist(EditTherapistDTO therapist)
        {
            if (therapist == null || string.IsNullOrEmpty(therapist.City) || string.IsNullOrEmpty(therapist.Email) || string.IsNullOrEmpty(therapist.FirstName) ||
                string.IsNullOrEmpty(therapist.LastName) || string.IsNullOrEmpty(therapist.PhoneNumber) || string.IsNullOrEmpty(therapist.Street) ||
                string.IsNullOrEmpty(therapist.Website))
            {
                return(BadRequest());
            }

            if (therapist.PostalCode < 1000 || 9999 < therapist.PostalCode)
            {
                return(BadRequest());                                                           //Belgian postal codes
            }
            if (therapist.HouseNumber < 1 || 999 < therapist.HouseNumber)
            {
                return(BadRequest());                                                         //House numbers
            }
            TherapistType tt = _therapistRepo.GetTherapistType(therapist.TherapistTypeId);

            if (tt == null)
            {
                return(BadRequest());           //Therapist type
            }
            Therapist edited = _therapistRepo.GetById(therapist.TherapistId);

            if (edited == null)
            {
                return(BadRequest());
            }
            edited = Therapist.MapEditTherapistDTOToTherapist(therapist, edited, tt);
            _therapistRepo.EditOpeningsTimes(edited.OpeningTimes.ToList());
            _therapistRepo.UpdateTherapist(edited);
            try
            {
                _therapistRepo.SaveChanges();
            }
            catch (Exception) {
                return(StatusCode(500));
            }
            return(Ok());
        }
        //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();
        }