示例#1
0
        public void GivenAnotherUsersPrivateMedia_ThenMediaDoesNotBelongToUserIsThrown()
        {
            var givenUser1         = "user1";
            var givenUser2         = "user2";
            var givenMediaId       = "abcdefgh";
            var givenMediaInstance = new MediaInstance()
            {
                Id        = givenMediaId,
                AuthorId  = givenUser1,
                DataType  = "png",
                IsPrivate = true
            };
            var givenTags = new List <string>()
            {
                "test everything"
            };

            _contextMock.MediaInstances.Add(givenMediaInstance);
            _contextMock.SaveChanges();

            var    command = UpdateTagsCommand.Create(givenMediaId, givenTags, givenUser2);
            var    handler = new UpdateTagsCommandHandler(_contextMock, _timeProviderMock.Object);
            Action act     = () => handler.Handle(command, CancellationToken.None).Wait();

            act.Should().Throw <MediaDoesNotBelongToUserException>();
        }
示例#2
0
        private async Task CreateMediaInstanceInDatabase(string id, string dataType, string?authorId, FileUploadDto mediaDto)
        {
            var mediaInstance = new MediaInstance()
            {
                Id        = id,
                DataType  = dataType,
                AuthorId  = authorId,
                IsPrivate = mediaDto.IsPrivate,
                Timestamp = mediaDto.Timestamp
            };

            ICollection <MediaTag> mediaTags = ConvertStringsToTags(mediaDto.Tags)
                                               .Select(t => new MediaTag()
            {
                MediaInstance = mediaInstance,
                Tag           = t
            })
                                               .ToList();

            mediaInstance.MediaTags = mediaTags;

            await _context.MediaInstances.AddAsync(mediaInstance);

            await _context.SaveChangesAsync(CancellationToken.None);
        }
示例#3
0
        public void GivenMediaChangeIsSavedInDatabase_MediaChangeIsOfTypeUpdate()
        {
            var givenUser          = "******";
            var givenMediaId       = "abcdefgh";
            var givenMediaInstance = new MediaInstance
            {
                Id       = givenMediaId,
                AuthorId = givenUser,
                DataType = "png"
            };
            var givenTags = new List <string>
            {
                "test everything"
            };

            _contextMock.MediaInstances.Add(givenMediaInstance);
            _contextMock.SaveChanges();

            var command = UpdateTagsCommand.Create(givenMediaId, givenTags, givenUser);
            var handler = new UpdateTagsCommandHandler(_contextMock, _timeProviderMock.Object);

            handler.Handle(command, CancellationToken.None).Wait();

            _contextMock.MediaChanges.Should().ContainSingle(mc => mc.Type == MediaChangeType.Update);
        }
示例#4
0
        private void Dispose(bool disposing)
        {
            if (disposing && MediaInstance != IntPtr.Zero)
            {
                UnregisterEvents();
                MediaInstance.Dispose();
            }

            GC.SuppressFinalize(this);
        }
        private void AddMediaInstance(string id)
        {
            var newMediaInstance = new MediaInstance()
            {
                Id       = id,
                DataType = "png"
            };

            _contextMock.MediaInstances.Add(newMediaInstance);
            _contextMock.SaveChanges();
        }
示例#6
0
        public void GivenNoMediaChanges_EmptyCollectionIsReturned()
        {
            var givenMediaInstanceId = "abcdefgh";
            var givenMediaInstance   = new MediaInstance
            {
                Id       = givenMediaInstanceId,
                DataType = "png"
            };

            AddMediaInstance(givenMediaInstance);

            var query = MediaRevisionHistoryQuery.Create(givenMediaInstanceId, string.Empty);
            IRequestHandler <MediaRevisionHistoryQuery, IEnumerable <MediaRevisionHistoryDto> > handler =
                new MediaRevisionHistoryQueryHandler(_contextMock);
            var result = handler.Handle(query, CancellationToken.None).Result;

            result.Should().BeEmpty();
        }
示例#7
0
        public MediaInstance CreateExampleDatabaseInstance()
        {
            var mediaInstance = new MediaInstance()
            {
                Id       = "k8wetest",
                DataType = "file",
            };
            var tags = new List <string>()
            {
                "pigeons", "flying rats", "little mermaid"
            };
            ICollection <MediaTag> mediaTags = tags.Select(t => new MediaTag()
            {
                MediaInstance = mediaInstance,
                Tag           = new Tag()
                {
                    Name = t
                }
            }).ToList();

            return(mediaInstance);
        }
示例#8
0
        public void GivenAnotherUsersPrivateMedia_ThenMediaDoesNotBelongToUserIsThrown()
        {
            var givenUser1         = "user1";
            var givenUser2         = "user2";
            var givenMediaId       = "abcdefgh";
            var givenMediaInstance = new MediaInstance()
            {
                Id        = givenMediaId,
                AuthorId  = givenUser1,
                DataType  = "png",
                IsPrivate = true
            };

            AddMediaInstance(givenMediaInstance);

            var query = MediaRevisionHistoryQuery.Create(givenMediaId, givenUser2);
            IRequestHandler <MediaRevisionHistoryQuery, IEnumerable <MediaRevisionHistoryDto> > handler =
                new MediaRevisionHistoryQueryHandler(_contextMock);
            Action act = () => handler.Handle(query, CancellationToken.None).Wait();

            act.Should().Throw <MediaDoesNotBelongToUserException>();
        }
示例#9
0
        public void GivenMediaInstanceWithMediaChanges_CorrespondingMediaRevisionHistoryDtoAreReturned()
        {
            var givenUserId            = "user";
            var givenMediaInstanceId   = "abcdefgh";
            var givenMediaCreationTime = new DateTime(2010, 1, 1, 0, 0, 0);
            var givenMediaUpdateTime   = new DateTime(2010, 1, 1, 1, 0, 0);
            var givenMediaChanges      = new List <MediaChange>
            {
                new MediaChange {
                    MediaInstanceId = givenMediaInstanceId, UserId = givenUserId,
                    Timestamp       = givenMediaCreationTime, Type = MediaChangeType.Create
                },
                new MediaChange {
                    MediaInstanceId = givenMediaInstanceId, UserId = givenUserId,
                    Timestamp       = givenMediaUpdateTime, Type = MediaChangeType.Update
                },
            };
            var givenMediaInstance = new MediaInstance
            {
                Id           = givenMediaInstanceId,
                DataType     = "png",
                MediaChanges = givenMediaChanges
            };

            AddMediaInstance(givenMediaInstance);

            var expectedMediaRevisionHistoryDtos = new List <MediaRevisionHistoryDto>
            {
                new MediaRevisionHistoryDto(givenUserId, MediaChangeType.Create, givenMediaCreationTime),
                new MediaRevisionHistoryDto(givenUserId, MediaChangeType.Update, givenMediaUpdateTime)
            };

            var query = MediaRevisionHistoryQuery.Create(givenMediaInstanceId, givenUserId);
            IRequestHandler <MediaRevisionHistoryQuery, IEnumerable <MediaRevisionHistoryDto> > handler =
                new MediaRevisionHistoryQueryHandler(_contextMock);
            var result = handler.Handle(query, CancellationToken.None).Result;

            result.Should().BeEquivalentTo(expectedMediaRevisionHistoryDtos);
        }
示例#10
0
        private IEnumerable <Tag> ConvertStringsToTags(IEnumerable <string> stringTags, MediaInstance media)
        {
            var tagNames = _context.Tags.Select(t => t.Name);
            var tags     = stringTags.Select(st =>
                                             tagNames.Contains(st) ? _context.Tags.Single(t => t.Name == st) : new Tag()
            {
                Name = st
            });

            return(tags);
        }
示例#11
0
 private void AddMediaInstance(MediaInstance mediaInstance)
 {
     _contextMock.MediaInstances.Add(mediaInstance);
     _contextMock.SaveChanges();
 }