public void Can_Delete_Single_Item()
        {
            // Get proj id to delete items from
            var projId = 1;

            // Instantiate ProjectCollection Repo
            var repo = new ProjectCollectionRepository(_context);

            // Get projCol
            var projCol = repo.GetByProjectId(projId);

            // Get original counts
            var originalCount = repo.GetByCollectionId(projId).Count;

            // Add Item to List
            var projectCollections = new List <ProjectCollection>()
            {
                projCol[0]
            };

            // Delete items
            repo.Delete(projectCollections);

            // Get new count
            var newCount = repo.GetByProjectId(projId).Count;

            //New count should be -1 original
            Assert.True(newCount == originalCount - 1);
        }
        public void Can_Add_Single_Item()
        {
            // Get a ProjectId to add
            var projId = 4;

            // Make ProjectCollection
            var newProjCol1 = new ProjectCollection()
            {
                ProjectId    = projId,
                CollectionId = 1,
            };

            // Instantiate ProjectCollection Repo
            var repo = new ProjectCollectionRepository(_context);

            // Get a count of collections in Project
            var originalCount = repo.GetByProjectId(projId).Count;

            // Add Items to List
            var projectCollections = new List <ProjectCollection>()
            {
                newProjCol1,
            };

            // Add items
            repo.Add(projectCollections);

            // Get new count
            var newCount = repo.GetByProjectId(projId).Count;

            // New count should be +1 original
            Assert.True(newCount == originalCount + 1);
        }
        public void User_Can_Not_Update_Collections_With_Duplicate_Names()
        {
            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_ID_1"),
            }, "TestAuthentication"));

            // Instantiate a real repos
            var collectionRepo = new CollectionRepository(_context);
            var userRepo       = new UserRepository(_context);
            var projColRepo    = new ProjectCollectionRepository(_context);

            // Instantiate a real CollectionController, passing in CollectionRepo
            var controller = new CollectionController(userRepo, collectionRepo, projColRepo);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Create a collection with a duplicate name
            // create a new collectionFormViewModel
            var collectionForm = new CollectionFormViewModel()
            {
                Collection = new Collection()
                {
                    Id               = 2,
                    UserId           = 1,
                    CategorizationId = 1,
                    Name             = "Monsters",
                    Description      = "HA-HA! The titles match >:)",
                    Pinned           = false,
                    CreationDate     = DateTime.Now - TimeSpan.FromDays(15)
                },

                ProjectCollections = new List <ProjectCollection>()
                {
                    new ProjectCollection()
                    {
                        ProjectId    = 1,
                        CollectionId = 0 // I won't know this until it's made
                    },
                    new ProjectCollection()
                    {
                        ProjectId    = 2,
                        CollectionId = 0 // I won't know this until it's made
                    }
                }
            };

            // Attempt to Update collection
            var response = controller.Put(collectionForm.Collection.Id, collectionForm);

            // Should return created result
            Assert.IsType <NotFoundResult>(response);
        }
        public void User_Can_Not_Update_Projects_With_Duplicate_Names()
        {
            // Make a new project to pass in to update
            var projectForm = new ProjectFormViewModel
            {
                Project = new Project()
                {
                    Id           = 2,
                    UserId       = 1,
                    Name         = "It",
                    CreationDate = DateTime.Now - TimeSpan.FromDays(15)
                },

                ProjectCollections = new List <ProjectCollection>()
                {
                    new ProjectCollection()
                    {
                        ProjectId    = 2, // I won't know this until it's made
                        CollectionId = 2
                    },
                    new ProjectCollection()
                    {
                        ProjectId    = 2, // I won't know this until it's made
                        CollectionId = 1
                    }
                }
            };

            // Spoof an authenticated user by generating a ClaimsPrincipal
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.NameIdentifier, "FIREBASE_ID_1"),
            }, "TestAuthentication"));

            // Instantiate a real repos
            var projectRepo = new ProjectRepository(_context);
            var userRepo    = new UserRepository(_context);
            var projColRepo = new ProjectCollectionRepository(_context);

            // Instantiate a real ProjectController, passing in ProjectRepo
            var controller = new ProjectController(userRepo, projectRepo, projColRepo);

            controller.ControllerContext             = new ControllerContext(); // Required to create the controller
            controller.ControllerContext.HttpContext = new DefaultHttpContext {
                User = user
            };                                                                                 // Pretend the user is making a request to the controller

            // Attempt to Update project
            var response = controller.Put(projectForm.Project.Id, projectForm);

            // Should return created result
            Assert.IsType <NotFoundResult>(response);
        }
        public void If_No_Joined_Proj_Coll_Return_Empty_List()
        {
            // Get a valid Project Id without any items
            var id = 4;

            // Instantiate ProjectCollection Repo
            var repo = new ProjectCollectionRepository(_context);

            // Get result of all projects
            var result = repo.GetByProjectId(id);

            // Should return an empty list
            Assert.Empty(result);
        }
        public void Can_Get_All_Related_To_A_Project_Id()
        {
            // Get a valid Project Id (only valid Ids will ever get to the repo anyway)
            var id = 1;

            // Instantiate ProjectCollection Repo
            var repo = new ProjectCollectionRepository(_context);

            // Get count of all projects
            var count = repo.GetByProjectId(id).Count;

            // Should have retrieved two items
            Assert.True(count == 2);
        }