public PaymentVoucherRepositoryTest()
        {
            user = new UserProfile();
            user.UserId = 1;
            user.UserName = "******";

            project = createTestProject(user.UserId);
            var projects = new ProjectRepository();
            projects.Create(project);
        }
        public void ProjectRepository_CreateCollaboration_ShouldCreateNewCollaborationInDB()
        {
            var projects = new ProjectRepository();
            var mockProjectID = Guid.NewGuid();

            var invitation = projects.CreateCollaboration(mockProjectID, "*****@*****.**");

            Assert.AreEqual(mockProjectID, invitation.ProjectID);
            Assert.AreEqual("*****@*****.**", invitation.Email);
        }
        public void ProjectRepository_Create_ShouldCreateNewProjectInDB()
        {
            var project = new Project();
            project.DateStarted = DateTime.Now;
            project.Name = "test";
            project.Owner = user;
            project.OwnerID = user.UserId;

            var repo = new ProjectRepository();

            repo.Create(project);
        }
        public void ProjectRepository_AcceptInvitation_ShouldSavetheUserIDInTheDB()
        {
            //create a test user in the database
            var db = new ApplicationDBContext();
            var user = new UserProfile();
            user.UserName = "******" + Guid.NewGuid().ToString();
            db.UserProfiles.Add(user);
            db.SaveChanges();

            //ok. on to the test now
            var projects = new ProjectRepository();
            var project = createTestProject(987);
            projects.Create(project);

            var invitation = projects.CreateCollaboration(project.ID, "*****@*****.**");
            projects.AcceptCollaboration(invitation.ID, user.UserId);

            var sharedProjectIDs = new List<Guid>();
            CollectionAssert.DoesNotContain(sharedProjectIDs, project.ID);
            sharedProjectIDs = projects.FindProjectsSharedWithUser(user.UserId).Select(col => col.ID).ToList();
            CollectionAssert.Contains(sharedProjectIDs, project.ID);
        }
        public void ProjectRepository_Delete_ShouldRemoveAProjectFromTheDB()
        {
            var project = new Project();
            project.DateStarted = DateTime.Now;
            project.Name = "test";
            project.Owner = user;
            project.OwnerID = user.UserId;

            var repo = new ProjectRepository();
            repo.Create(project);

            Assert.IsNotNull(repo.FindProjectByID(project.ID));

            repo.Delete(project);
            Assert.IsNull(repo.FindProjectByID(project.ID));
        }
 /// <summary>
 /// removes existing proejcts from teh database so we can count the projects correctly
 /// </summary>
 /// <param name="userID"></param>
 private void removeExistingProjectsFromUser(int userID)
 {
     var projects = new ProjectRepository();
     var ownedProjects = projects.FindProjectsOwnedByUser(userID);
     foreach (var project in ownedProjects)
     {
         var foundProject = projects.FindProjectByID(project.ID);
         projects.Delete(foundProject);
     }
 }
        public void ProjectRepository_SendInvitation_ShoudltryToSendAnEmailWithInvitaion()
        {
            var projects = new ProjectRepository();
            var mockProjectID = Guid.NewGuid();
            var mockEmailSender = A.Fake<IEmailSender>();
            var invitation = projects.CreateCollaboration(mockProjectID, "*****@*****.**");

            A.CallTo(() => mockEmailSender.SendMail("", "", "")).WithAnyArguments().MustNotHaveHappened();
            projects.SendInvitation(invitation, mockEmailSender);
            A.CallTo(() => mockEmailSender.SendMail("", "", "")).WithAnyArguments().MustHaveHappened();

            Assert.AreEqual(mockProjectID, invitation.ProjectID);
            Assert.AreEqual("*****@*****.**", invitation.Email);
        }
        public void ProjectRepository_Find_ShouldReturnOneProjectFromTheDB_IfItExists()
        {
            var project = new Project();
            project.DateStarted = DateTime.Now;
            project.Name = "test";
            project.Owner = user;
            project.OwnerID = user.UserId;

            var repo = new ProjectRepository();
            repo.Create(project);

            var foundProject = repo.FindProjectByID(project.ID);

            Assert.IsNotNull(foundProject);
            Assert.AreEqual(project.DateStarted, foundProject.DateStarted);
            Assert.AreEqual(project.Name, foundProject.Name);
            Assert.AreEqual(project.OwnerID, foundProject.OwnerID);
        }
        public void ProjectRepository_Find_ShouldReturnNull_IftheProjectDoesntExist()
        {
            var repo = new ProjectRepository();
            var foundProject = repo.FindProjectByID(Guid.NewGuid());

            Assert.IsNull(foundProject);
        }
        public void ProjectRepository_FindProjectsOwnedByUser_ShouldReturnAllOwedProjectsOfUser()
        {
            removeExistingProjectsFromUser(1);
            removeExistingProjectsFromUser(2);

            var project = new ProjectRepository();
            project.Create(createTestProject(1));
            project.Create(createTestProject(2));
            project.Create(createTestProject(1));

            var ownedProjects = project.FindProjectsOwnedByUser(1);
            Assert.AreEqual(2, ownedProjects.Count());

            ownedProjects = project.FindProjectsOwnedByUser(2);
            Assert.AreEqual(1, ownedProjects.Count());
        }
        public void ProjectRepository_Edit_ShouldUpdateTheDB()
        {
            var project = new Project();
            project.DateStarted = DateTime.Now;
            project.Name = "test";
            project.Owner = user;
            project.OwnerID = user.UserId;

            var repo = new ProjectRepository();
            repo.Create(project);

            var foundProject = repo.FindProjectByID(project.ID);

            Assert.IsNotNull(foundProject);
            Assert.AreEqual(project.DateStarted, foundProject.DateStarted);
            Assert.AreEqual(project.Name, foundProject.Name);
            Assert.AreEqual(project.OwnerID, foundProject.OwnerID);

            foundProject.Name = "other";

            repo.Update(project);

            var newFoundProject = repo.FindProjectByID(foundProject.ID);
            Assert.IsNotNull(newFoundProject);
            Assert.AreEqual(foundProject.DateStarted, newFoundProject.DateStarted);
            Assert.AreEqual(foundProject.Name, newFoundProject.Name);
            Assert.AreEqual(foundProject.OwnerID, newFoundProject.OwnerID);
        }