Example #1
0
        Validate_ReturnsCantChangeStatusFromStartedButPostponedToToReading_When_OldStatusIsStartedButPostponedAndNewStatusIsToReading()
        {
            var item = new PrivateBookListItem
            {
                Status = BookItemStatus.StartedButPostponed
            };

            var ex = Assert.Throws <CannotChangeStatusException>(() =>
                                                                 PrivateBookListItemStatusValidator.Validate(item.Status, BookItemStatus.ToReading));

            Assert.Equal(ExceptionMessages.CannotChangeStatusFromTo.F(item.Status.ToStringFromDescription(),
                                                                      BookItemStatus.ToReading.ToStringFromDescription()), ex.Message);
        }
Example #2
0
        public void Validate_ReturnsCantChangeStatusFromReadToReading_When_OldStatusIsReadAndNewStatusIsReading()
        {
            var item = new PrivateBookListItem
            {
                Status = BookItemStatus.Read
            };

            var ex = Assert.Throws <CannotChangeStatusException>(() =>
                                                                 PrivateBookListItemStatusValidator.Validate(item.Status, BookItemStatus.Reading));

            Assert.Equal(
                ExceptionMessages.CannotChangeStatusFromTo.F(item.Status.ToString("G"),
                                                             BookItemStatus.Reading.ToString("G")), ex.Message);
        }
Example #3
0
        protected override Task Validate(PrivateBookListItem entity, UpdatePrivateListItem command)
        {
            if (entity == null)
            {
                throw new ObjectNotExistException <PrivateBookListItem>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = command.ItemId.ToString()
                });
            }

            var accessSpecification = new BookListOwnerAccessSpecification(entity.BookList);

            if (!accessSpecification.SatisfiedBy(command.UserId))
            {
                throw new AccessDeniedException <BookList>(new OnExceptionObjectDescriptor
                {
                    ["Id"] = entity.BookListId.ToString()
                });
            }

            PrivateBookListItemStatusValidator.Validate(entity.Status, (BookItemStatus)command.Status);

            return(Task.CompletedTask);
        }