Ejemplo n.º 1
0
        public bool CreateProject(Project project)
        {
            if (project == null)
                throw new ArgumentNullException("createProject");

            //  userToCreate.Validate();

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

            if (string.IsNullOrWhiteSpace(project.Title))
            {
                return false;
            }

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

                //-- Persist
                _projectRepository.Add(project);
                return dbContextScope.SaveChanges() != 0 ? true : false;
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void CreateNewProjectWithPhotograph()
        {
            var dbContextScopeFactory = new DbContextScopeFactory();
            var ambientDbContextLocator = new AmbientDbContextLocator();
            var projectRepository = new ProjectRepository(ambientDbContextLocator);

            var photographs = new List<Photograph>();
            photographs.Add(new Photograph {

                Location="home",
                Title="photo title"

            });

            photographs.Add(new Photograph
            {

                Location = "home2",
                Title = "photo title2"

            });

            var projectService = new ProjectServices(dbContextScopeFactory, projectRepository);

            Project project = new Project
            {
                Description = "test",
                Title = "Test title",
                Photographs = photographs
            };

            projectService.CreateProject(project);
        }
Ejemplo n.º 4
0
        public bool RemoveProject(Project project)
        {
            using (var dbContextScope = _dbContextScopeFactory.Create())
            {

                //-- Persist
                _projectRepository.Remove(project);
                return dbContextScope.SaveChanges() != 0 ? true : false;
            }
        }
Ejemplo n.º 5
0
        public bool Remove(Project project)
        {
            bool currentValidation = DbContext.Configuration.ValidateOnSaveEnabled;
            try
            {
                DbContext.Configuration.ValidateOnSaveEnabled = false;
                DbContext.Projects.Attach(project);
                DbContext.Entry(project).State = EntityState.Deleted;
                return true;
            }
            catch
            {

                return false;
            }
            finally
            {
                DbContext.Configuration.ValidateOnSaveEnabled = currentValidation;
            }
        }
Ejemplo n.º 6
0
 public bool Add(Project project)
 {
     return DbContext.Projects.Add(project) != null ? true : false;
 }
Ejemplo n.º 7
0
        public void GetExistingProject()
        {
            //Arrange
            Project existingProject = new Project();
            existingProject.Description = "project descriptiopn";
            existingProject.Title = "Project title";
            existingProject.ProjectId = Guid.NewGuid();

            _projectRepository.Get(existingProject.ProjectId).Returns(existingProject);

            //Act

            Project projectFromDB = _projectService.GetProject(existingProject.ProjectId);

            //Assert
            Assert.AreEqual(existingProject.ProjectId, projectFromDB.ProjectId);
            Assert.AreEqual(existingProject.Title, projectFromDB.Title);
            Assert.AreEqual(existingProject.Description, projectFromDB.Description);
        }
Ejemplo n.º 8
0
        public void CreateAProjectWithoutDescriptionTitleAndPhoto()
        {
            //Arrange

            _dbContext.SaveChanges().Returns(1);

            Project creatProject = new Project();

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

            bool result = _projectService.CreateProject(creatProject);

            //Assert

            Assert.IsFalse(result);
        }
Ejemplo n.º 9
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);
        }