Пример #1
0
        public async Task <IEnumerable <MediaRevisionHistoryDto> > GetMediaRevisionHistory(string id)
        {
            var query  = MediaRevisionHistoryQuery.Create(id, User.GetUserId());
            var result = await _mediator.Send(query);

            return(result);
        }
Пример #2
0
        public void GivenNullUserId_ArgumentNullExceptionIsThrown()
        {
            string givenUserId = null;

            Action act = () => MediaRevisionHistoryQuery.Create("abcedfgh", givenUserId);

            act.Should().Throw <ArgumentNullException>();
        }
Пример #3
0
        public void GivenNullMediaInstanceId_ArgumentNullExceptionIsThrown()
        {
            string givenMediaInstanceId = null;

            Action act = () => MediaRevisionHistoryQuery.Create(givenMediaInstanceId, string.Empty);

            act.Should().Throw <ArgumentNullException>();
        }
Пример #4
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();
        }
Пример #5
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>();
        }
Пример #6
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);
        }