Esempio n. 1
0
        public async Task UpdateSchool_ShouldUpdateSchoolSuccessfully()
        {
            string errorMessagePrefix = "School UpdateAsync() does not work properly.";

            var context = NetBookDbContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            this.schoolService = new SchoolService(context);

            var testSchool = new SchoolServiceModel
            {
                Name         = "TestName1",
                Town         = "Test1",
                Municipality = "Test1",
                Region       = "Test1",
                Area         = "Test1",
            };

            var actualResult = await this.schoolService.UpdateAsync(testSchool);

            Assert.True(actualResult, errorMessagePrefix);

            var updatedSchool = context.School.First();

            Assert.True(updatedSchool.Name == testSchool.Name, errorMessagePrefix + " " + "School Name is not set properly.");
            Assert.True(updatedSchool.Town == testSchool.Town, errorMessagePrefix + " " + "School Town is not set properly.");
            Assert.True(updatedSchool.Municipality == testSchool.Municipality, errorMessagePrefix + " " + "School Municipality is not set properly.");
            Assert.True(updatedSchool.Region == testSchool.Region, errorMessagePrefix + " " + "School Region is not set properly.");
            Assert.True(updatedSchool.Area == testSchool.Area, errorMessagePrefix + " " + "School Area is not set properly.");
        }
Esempio n. 2
0
        public async Task <bool> EditSchool(int id, SchoolServiceModel model)
        {
            var schoolFromDb = await this.schoolRepository
                               .All()
                               .SingleOrDefaultAsync(x => x.Id == id);

            if (schoolFromDb == null)
            {
                throw new NullReferenceException(string.Format(GlobalConstants.NullReferenceSchoolId, id));
            }

            schoolFromDb.Name         = model.Name;
            schoolFromDb.Address      = schoolFromDb.Address;
            schoolFromDb.DirectorName = model.DirectorName;
            schoolFromDb.District     = schoolFromDb.District;
            schoolFromDb.Email        = model.Email;
            schoolFromDb.FreeSpots    = model.FreeSpots;
            schoolFromDb.PhoneNumber  = model.PhoneNumber;
            schoolFromDb.URLOfMap     = schoolFromDb.URLOfMap;
            schoolFromDb.URLOfSchool  = model.URLOfSchool;

            this.schoolRepository.Update(schoolFromDb);
            var result = await this.schoolRepository.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 3
0
        public async Task GetSchoolIdByName_WithExistName_ShouldReturnSchoolId()
        {
            this.SeedTestData(this.DbContext);

            SchoolServiceModel school = this.DbContext.Schools.To <SchoolServiceModel>().First();
            string             name   = school.Name;
            int expected = this.DbContext.Schools.First(n => n.Name == name).Id;

            int actual = await this.SchoolsServiceMock.GetSchoolIdByName(name);

            Assert.True(
                expected == actual,
                "SchoolsService GetSchoolIdByName() not works properly!");
        }
Esempio n. 4
0
        public async Task <bool> UpdateAsync(SchoolServiceModel model)
        {
            var schoolToUpdate = AutoMapper.Mapper.Map <School>(model);

            var schoolToDelete = this.context.School.FirstOrDefault();

            this.context.School.Remove(schoolToDelete);

            await this.context.School.AddAsync(schoolToUpdate);

            int result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 5
0
        public async Task <IActionResult> ViewDocuments()
        {
            var userIdentity = this.User.Identity.Name;

            SchoolServiceModel directorsSchool = await this.schoolsService.GetSchoolForEdit(userIdentity);

            if (directorsSchool == null)
            {
                return(this.Redirect("/"));
            }

            var documents = this.cloudinaryService
                            .ViewDocuments(directorsSchool.Id)
                            .To <ViewDocumentViewModel>()
                            .ToList();

            return(this.View(documents));
        }
Esempio n. 6
0
        public IActionResult EditSchool(int id, EditSchoolInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                var allDistricts = this.districtsService.GetAllDistricts();
                this.ViewData["Districts"] = allDistricts.Select(d => new EditSchoolDistrictModel {
                    Name = d.Name
                }).ToList();

                return(this.View(input));
            }

            SchoolServiceModel schoolToEdit = input.To <SchoolServiceModel>();

            this.schoolsService.EditSchool(id, schoolToEdit);

            return(this.Redirect("/"));
        }
Esempio n. 7
0
        public async Task GetSchoolDetails_WithCorrectInputData_ShouldReturnSchoolDetails()
        {
            this.SeedTestData(this.DbContext);

            SchoolServiceModel expected = this.DbContext.Schools.To <SchoolServiceModel>().First();

            SchoolServiceModel actual = await this.SchoolsServiceMock.GetSchoolDetailsById(expected.Id);

            Assert.True(
                expected.Name == actual.Name,
                "SchoolsService GetSchoolDetailsById() not works properly!");
            Assert.True(
                expected.PhoneNumber == actual.PhoneNumber,
                "SchoolsService GetSchoolDetailsById() not works properly!");
            Assert.True(
                expected.District.Name == actual.District.Name,
                "SchoolsService GetSchoolDetailsById() not works properly!");
            Assert.True(
                expected.DirectorName == actual.DirectorName,
                "SchoolsService GetSchoolDetailsById() not works properly!");
            Assert.True(
                expected.Address == actual.Address,
                "SchoolsService GetSchoolDetailsById() not works properly!");
        }