public async Task DeleteCollection_ReturnsNotFoundResponse_GivenInvalidCollectionId()
        {
            //Act
            var response = await _controller.DeleteCollection(Guid.Empty);

            //Assert
            Assert.IsType <NotFoundResult>(response);
        }
        public void DeleteCollection_CollectionIsSaved_SavedCollectionDeleted()
        {
            //Arrange
            var userId1 = NewGuid;
            var userId2 = NewGuid;

            AddUser(userId1);
            AddUser(userId2);
            var collection = AddCollection(userId1, 5);

            SaveCollection(collection.Id, userId2);

            //Act
            IActionResult result = null;

            InTransaction(context =>
            {
                var controller = new CollectionsController(context, GetUserProviderMock(userId1), getCollectionConfigurationProviderMock());
                result         = controller.DeleteCollection(collection.Id);
            });

            //Assert
            result.Should().BeOfType <OkResult>();
            InTransaction(context =>
            {
                var savedCollections = context.SavedCollection.ToList();
                savedCollections.Should().BeEmpty();
            });
        }
        public void DeleteCollection_UserHasMultipleCollections_Only1CollectionDeleted()
        {
            //Arrange
            var userId = NewGuid;
            var collectionToDeleteName = NewGuid;

            AddUser(userId);
            var collection = AddCollection(userId, 5, name: collectionToDeleteName);

            for (var i = 0; i < 10; i++)
            {
                AddCollection(userId, 5);
            }

            //Act
            IActionResult result = null;

            InTransaction(context =>
            {
                var controller = new CollectionsController(context, GetUserProviderMock(userId), getCollectionConfigurationProviderMock());
                result         = controller.DeleteCollection(collection.Id);
            });

            //Assert
            result.Should().BeOfType <OkResult>();
            InTransaction(context =>
            {
                var collections = context.Collection.ToList();
                collections.Should().HaveCount(10);
                collections.Where(c => c.Id == collection.Id).Should().HaveCount(0);
                collections.Where(c => c.Name == collectionToDeleteName).Should().HaveCount(0);
            });
        }
        public void DeleteCollection_CollectionHasNElements_AllElementsDeleted(int elementCount)
        {
            //Arrange
            var userId = NewGuid;

            AddUser(userId);
            var collection = AddCollection(userId, elementCount);

            //Act
            IActionResult result = null;

            InTransaction(context =>
            {
                var controller = new CollectionsController(context, GetUserProviderMock(userId), getCollectionConfigurationProviderMock());
                result         = controller.DeleteCollection(collection.Id);
            });

            //Assert
            result.Should().BeOfType <OkResult>();
            InTransaction(context =>
            {
                var elements = context.Element.ToList();
                elements.Should().BeEmpty();
            });
        }
        public void DeleteCollection_CollectionNotOwnedByUser_Forbidden()
        {
            //Arrange
            var userId1 = NewGuid;
            var userId2 = NewGuid;

            AddUser(userId1);
            AddUser(userId2);
            var collection = AddCollection(userId1, 5);

            //Act
            IActionResult result = null;

            InTransaction(context =>
            {
                var controller = new CollectionsController(context, GetUserProviderMock(userId2), getCollectionConfigurationProviderMock());
                result         = controller.DeleteCollection(collection.Id);
            });

            //Assert
            result.Should().BeOfType <ForbidResult>();
        }