public void UpdateCollection_CollectionNotOwnedByUserButHasEditRights_Ok()
        {
            //Arrange
            var userId1 = NewGuid;
            var userId2 = NewGuid;

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

            ShareCollection(collection.Id, userId2, true);
            var collectionData = new CollectionUpdateData {
                Description = NewGuid, Name = NewGuid
            };

            //Act
            IActionResult result = null;

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

            //Assert
            result.Should().BeOfType <OkResult>();
        }
        public void UpdateCollection_MultipleFieldsUpdate_ProperlyUpdated(string newName, string newDescription)
        {
            //Arrange
            var userId = NewGuid;

            AddUser(userId);
            var collection     = AddCollection(userId, 5);
            var collectionData = new CollectionUpdateData {
                Description = newDescription, Name = newName
            };

            //Act
            IActionResult result = null;

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

            //Assert
            result.Should().BeOfType <OkResult>();
            InTransaction(context =>
            {
                var collectionFromContext = context.Collection.Single();
                collectionFromContext.Description.Should().Be(newDescription ?? collection.Description);
                collectionFromContext.Name.Should().Be(newName ?? collection.Name);
            });
        }
        public void UpdateCollection_NewDescriptionProvided_CollectionDescriptionUpdated(string initialDescription, string newDescription)
        {
            //Arrange
            var userId = NewGuid;

            AddUser(userId);
            var collection     = AddCollection(userId, 5, description: initialDescription);
            var collectionData = new CollectionUpdateData {
                Description = newDescription
            };

            //Act
            IActionResult result = null;

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

            //Assert
            result.Should().BeOfType <OkResult>();
            InTransaction(context =>
            {
                var collectionFromContext = context.Collection.Single();
                collectionFromContext.Description.Should().Be(newDescription);
            });
        }
        public void UpdateCollection_NewNameProvided_CollectionNameUpdated(string initialName, string newName)
        {
            //Arrange
            var userId = NewGuid;

            AddUser(userId);
            var collection     = AddCollection(userId, 5, initialName);
            var collectionData = new CollectionUpdateData {
                Name = newName
            };

            //Act
            InTransaction(context =>
            {
                var controller = new CollectionsController(context, GetUserProviderMock(userId), getCollectionConfigurationProviderMock());
                controller.UpdateCollection(collection.Id, collectionData);
            });

            //Assert
            InTransaction(context =>
            {
                var collectionFromContext = context.Collection.Single();
                collectionFromContext.Name.Should().Be(newName);
            });
        }
        public async Task UpdateCollection_ReturnsBadRequestResponse_GivenNoCollection()
        {
            //Act
            var response = await _controller.UpdateCollection(Guid.Empty, null);

            //Assert
            Assert.IsType <BadRequestResult>(response);
        }
        public void UpdateCollection_CollectionNotOwnedByUserAndNoEditRights_Forbidden()
        {
            //Arrange
            var userId = NewGuid;

            AddUser(userId);
            var collection     = AddCollection(userId, 5);
            var collectionData = new CollectionUpdateData {
                Description = NewGuid, Name = NewGuid
            };

            //Act
            IActionResult result = null;

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

            //Assert
            result.Should().BeOfType <ForbidResult>();
        }
        public void UpdateCollection_CollectionDoesntExist_NotFound()
        {
            //Arrange
            var userId = NewGuid;

            AddUser(userId);
            var collection     = AddCollection(userId, 5);
            var collectionData = new CollectionUpdateData {
                Description = NewGuid, Name = NewGuid
            };

            //Act
            IActionResult result = null;

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

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