Exemple #1
0
        public void CreateANewProjectFailToAddToDb()
        {
            //Arrange

            _dbContext.SaveChanges().Returns(0);

            Project creatProject = new Project();

            creatProject.Title = "test";
            creatProject.Description = "test description";

            Photograph newPhoto = new Photograph();
            newPhoto.PhotographId = Guid.NewGuid();
            newPhoto.Title = "Test Title";
            newPhoto.Location = "location of photo";

            var photographs = new List<Photograph>();

            photographs.Add(newPhoto);

            creatProject.Photographs = photographs;

            _projectRepository.Add(creatProject).Returns(false);
            //Act

            bool result = _projectService.CreateProject(creatProject);

            //Assert

            Assert.IsFalse(result);
        }
Exemple #2
0
        public bool UploadPhotography(Photograph photograph)
        {
            if (photograph == null)
                throw new ArgumentNullException("userToCreate");

              //  userToCreate.Validate();

            /*
             * Typical usage of DbContextScope for a read-write business transaction.
             * It's as simple as it looks.
             */

            if (string.IsNullOrWhiteSpace(photograph.Title) || string.IsNullOrWhiteSpace (photograph.Location))
            {

                return false;
            }

            using (var dbContextScope = _dbContextScopeFactory.Create())
            {

                //-- Persist
                if( _photographRepository.Add(photograph))
                    {
                        return dbContextScope.SaveChanges() != 0 ? true : false;
                    }

                    else{ return false; }
            }
        }
        public void GetListOfAllPhotographs()
        {
            //Arrange
            PhotographController photoController = new PhotographController(_photographServices);

            var photoListToReturn = new List<Photograph>();

            var projectList = new List<Project>();
            projectList.Add(
                 new Project {
                     ProjectId = Guid.NewGuid(),
                     Title = "Project Title",
                     Description = "Description tex"
                 }

                );

            projectList.Add(
              new Project
              {
                  ProjectId = Guid.NewGuid(),
                  Title = "Project Title 2",
                  Description = "Description tex2"
              }

             );

            Photograph photo1 = new Photograph
            {
                PhotographId = Guid.NewGuid(),
                Title = "Test title",
                Location = "Test location",
                Projects = projectList

            };
            Photograph photo2 = new Photograph
            {
                PhotographId = Guid.NewGuid(),
                Title = "Test title 2",
                Location = "Test location 2",
                Projects = projectList
            };

            photoListToReturn.Add(photo1);
            photoListToReturn.Add(photo2);

            _photographServices.GetAllPhotographs().Returns(photoListToReturn);

            var result = photoController.ListOfPhotos() as ViewResult;

            var photographList = result.Model as List<Photograph>;

            Assert.IsNotNull(result);

            Assert.AreEqual(photographList, new[] { photo1, photo2 });
        }
Exemple #4
0
        public bool RemovePhotography(Photograph photograph)
        {
            using (var dbContextScope = _dbContextScopeFactory.Create())
            {

                //-- Persist
                if (_photographRepository.Remove(photograph))
                {
                    return dbContextScope.SaveChanges() != 0 ? true : false;
                }
                else{ return false; }

            }
        }
        public void CreateANewPhotographFailToSave()
        {
            //Arrange

            _dbContext.SaveChanges().Returns(0);
            Photograph newPhoto = new Photograph();
            newPhoto.Title = "test";
            newPhoto.Location = "testlocation";
            _photographRepository.Add(newPhoto).Returns(true);
            //Act

            bool result = _photographService.UploadPhotography(newPhoto);

            //Assert

            Assert.IsFalse(result);
        }
Exemple #6
0
        public void CreateANewPhotograph()
        {
            var dbContextScopeFactory = new DbContextScopeFactory();
            var ambientDbContextLocator = new AmbientDbContextLocator();
            var photographRepository = new PhotographRepository(ambientDbContextLocator);

            var photographService = new PhotographServices(dbContextScopeFactory, photographRepository);
            //var userQueryService = new UserQueryService(dbContextScopeFactory, userRepository);
            //var userEmailService = new UserEmailService(dbContextScopeFactory);
            //var userCreditScoreService = new UserCreditScoreService(dbContextScopeFactory);

                Photograph newPhoto = new Photograph();

                newPhoto.Location = "testlocation";

            Assert.IsTrue(photographService.UploadPhotography(newPhoto));

            Guid uploadID = newPhoto.PhotographId;
            Assert.IsTrue(photographService.RemovePhotography(newPhoto));
        }
Exemple #7
0
 public bool Add(Photograph photograph)
 {
     return DbContext.Photographs.Add(photograph) != null ? true : false;
     //DbContext.Photographs.Add(photograph);
     //return DbContext.SaveChanges() == 1 ? true : false;
 }
Exemple #8
0
        public bool Remove(Photograph photograph)
        {
            bool currentValidation = DbContext.Configuration.ValidateOnSaveEnabled;
            try {
                DbContext.Configuration.ValidateOnSaveEnabled = false;
                DbContext.Photographs.Attach(photograph);
                DbContext.Entry(photograph).State = EntityState.Deleted;
                return true;
            }
            catch
            {

                return false;
            }
            finally
            {
                DbContext.Configuration.ValidateOnSaveEnabled = currentValidation;
            }
            //return DbContext.Photographs.Remove(photograph) != null ? true : false;
        }
        public void GetExistingPhotograph()
        {
            //Arrange
            Photograph newPhoto = new Photograph();
            newPhoto.PhotographId = Guid.NewGuid();
            newPhoto.Title = "Test Title";
            newPhoto.Location = "location of photo";
            _photographRepository.Get(newPhoto.PhotographId).Returns(newPhoto);

            //Act

            Photograph existingPhoto = _photographService.GetPhotograph(newPhoto.PhotographId);

            //Assert
            Assert.AreEqual(newPhoto.PhotographId, existingPhoto.PhotographId);
            Assert.AreEqual(newPhoto.Title, existingPhoto.Title);
            Assert.AreEqual(newPhoto.Location, existingPhoto.Location);
        }
        public void GetAllPhotograph()
        {
            //Arrange
            Photograph newPhoto = new Photograph();
            newPhoto.PhotographId = Guid.NewGuid();
            newPhoto.Title = "Test Title";
            newPhoto.Location = "location of photo";

            Photograph newPhoto2 = new Photograph();
            newPhoto2.PhotographId = Guid.NewGuid();
            newPhoto2.Title = "Test Title";
            newPhoto2.Location = "location of photo";

            List<Photograph> photoList = new List<Photograph>();

            _photographRepository.GetAll().Returns(photoList);

            //Act

            List<Photograph> existingPhoto = _photographService.GetAllPhotographs();

            for (int i = 0;i<existingPhoto.Count;i++)
            {
                Assert.AreEqual(photoList[i].PhotographId, existingPhoto[i].PhotographId);
                Assert.AreEqual(photoList[i].Title, existingPhoto[i].Title);
                Assert.AreEqual(photoList[i].Location, existingPhoto[i].Location);

            }

            //Assert
        }
        public void CreateAPhotographWithoutLocationAndTitle()
        {
            //Arrange

            _dbContext.SaveChanges().Returns(1);
            Photograph newPhoto = new Photograph();
            _photographRepository.Add(newPhoto).Returns(true);
            //Act

            bool result = _photographService.UploadPhotography(newPhoto);

            //Assert

            Assert.IsFalse(result);
        }
Exemple #12
0
        public void CreateAProjectWithoutDescription()
        {
            //Arrange

            Project creatProject = new Project();

            creatProject.Title = "test";
            Photograph newPhoto = new Photograph();
            newPhoto.PhotographId = Guid.NewGuid();
            newPhoto.Title = "Test Title";
            newPhoto.Location = "location of photo";

            var photographs = new List<Photograph>();

            photographs.Add(newPhoto);

            creatProject.Photographs = photographs;

            _projectRepository.Add(creatProject).Returns(true);
            //Act

            bool result = _projectService.CreateProject(creatProject);

            //Assert

            Assert.IsFalse(result);
        }