public void AddShouldAddProjectsCorrectly()
 {
     var projectToAdd = new Project()
     {
         Id = 5,
         Name = "John",
         EstimatedDate = DateTime.Now,
         Description = "This is my description",
         GoalMoney = 321312
     };
     var result = projectService.Add(projectToAdd);
     Assert.AreEqual(result, projectToAdd.Id);
 }
        public int Add(string name, string description, int goalMoney, int estimatedDays, int categoryId, string userId, ICollection<Image> images)
        {
            var projectToAdd = new Project
            {
                EstimatedDate = DateTime.Now.AddDays(estimatedDays),
                Name = name,
                Description = description,
                GoalMoney = goalMoney,
                CategoryId = categoryId,
                InnovatorId = userId,
                Images = images,
                IsRemoved = false,
                IsClosed = false,
                CollectedMoney = 0
            };

            this.projectsRepo.Add(projectToAdd);
            this.projectsRepo.SaveChanges();

            return projectToAdd.Id;
        }
        public void AddShouldInvokeSaveChanges()
        {
            var projectToAdd = new Project()
            {
                Id = 5,
                Name = "John",
                EstimatedDate = DateTime.Now,
                Description = "This is my description",
                GoalMoney = 321312
            };
            var result = projectService.Add(projectToAdd);

            Assert.AreEqual(1, this.projectsRepository.NumberOfSaves);
        }
        public void UpdateShouldUpdateProjectsCorrectly()
        {
            var projectToAdd = new Project()
            {
                Name = "John",
                EstimatedDate = DateTime.Now,
                Description = "This is my description",
                GoalMoney = 321312,
                Id = 1337
            };
            var result = projectService.Add(projectToAdd);

            projectToAdd.Name = "Pesho";
            projectService.Update(projectToAdd);

            var oldName = "John";
            var expectedName = this.projectsRepository.UpdatedEntities[0].Name;

            Assert.AreNotEqual(expectedName, oldName);
            Assert.AreEqual(expectedName, "Pesho");
        }
        public void UpdateShouldInvokeSaveChanges()
        {
            var projectToAdd = new Project()
            {
                Name = "John",
                EstimatedDate = DateTime.Now,
                Description = "This is my description",
                GoalMoney = 321312,
                Id = 1337
            };
            var result = projectService.Add(projectToAdd);

            projectToAdd.Name = "Pesho";
            projectService.Update(projectToAdd);

            // One for Add and one for Update
            Assert.AreEqual(2, projectsRepository.NumberOfSaves);
        }
        public void RemoveShouldRemoveAProjectCorrectly()
        {
            var projectToRemove = new Project()
            {
                Name = "John1337",
                EstimatedDate = DateTime.Now,
                Description = "This is my description",
                GoalMoney = 321312,
                Id = 1337
            };
            var added = projectService.Add(projectToRemove);
            projectService.Remove(projectToRemove);

            // When we update a project we move it to the updated list
            // Since removing isn't deleting, but setting a isRemoved to true
            // We have to do this
            var updated = projectsRepository.UpdatedEntities.Select(x => x.IsRemoved == true).Count();

            Assert.AreEqual(1, updated);
            Assert.IsFalse(projectService.GetAll().Any(x => x.Name == "John1337"));
        }
        public void RemoveShouldInvokeSaveChanges()
        {
            var projectToRemove = new Project()
            {
                Name = "John1337",
                EstimatedDate = DateTime.Now,
                Description = "This is my description",
                GoalMoney = 321312,
                Id = 1337
            };
            var initNumberOFSaves = 0;
            var added = projectService.Add(projectToRemove);
            initNumberOFSaves = projectsRepository.NumberOfSaves;

            projectService.Remove(projectToRemove);
            Assert.AreEqual(initNumberOFSaves+1, projectsRepository.NumberOfSaves);
        }
        public void RemoveByIDShouldWorkCorrectly()
        {
            var projectToRemove = new Project()
            {
                Name = "John1337",
                EstimatedDate = DateTime.Now,
                Description = "This is my description",
                GoalMoney = 321312,
                Id = 1337
            };
            var added = projectService.Add(projectToRemove);
            projectService.RemoveById(projectToRemove.Id);

            var updated = projectsRepository.UpdatedEntities.Select(x => x.IsRemoved == true).Count();

            Assert.AreEqual(1, updated);
            Assert.IsFalse(projectService.GetAll().Any(x => x.Name == "John1337"));
        }
        public void AddShouldPopulateUserAndProjectToDatabase()
        {
            var projectToAdd = new Project()
            {
                Id = 5,
                Name = "John",
                EstimatedDate = DateTime.Now,
                Description = "This is my description",
                GoalMoney = 321312
            };

            var result = this.projectService.Add(projectToAdd);

            var project = this.projectsRepository.All().FirstOrDefault(pr => pr.Name == "John");

            Assert.IsNotNull(project);
            Assert.AreEqual("John", project.Name);
            Assert.AreEqual("This is my description", project.Description);
            Assert.AreEqual(321312, project.GoalMoney);
        }
 public void Update(Project project)
 {
     this.projectsRepo.Update(project);
     this.projectsRepo.SaveChanges();
 }
 public void Remove(Project project)
 {
     project.IsRemoved = true;
     this.projectsRepo.Update(project);
     this.projectsRepo.SaveChanges();
 }