Example #1
0
        internal static WishListItemState CreateState(WishListItemStatus status)
        {
            switch (status)
            {
            case WishListItemStatus.Requested:
                return(Requested);

            case WishListItemStatus.RequestedToDirector:
                return(RequestedToDirector);

            case WishListItemStatus.Rejected:
                return(Rejected);

            case WishListItemStatus.Accepted:
                return(Accepted);

            case WishListItemStatus.InRealization:
                return(InRealization);

            case WishListItemStatus.Realized:
                return(Realized);

            default:
                throw new ArgumentOutOfRangeException(nameof(status), status, null);
            }
        }
Example #2
0
        public void AcceptBy(User user)
        {
            if (Status != WishListItemStatus.Requested &&
                Status != WishListItemStatus.RequestedToDirector)
            {
                throw new CannotAcceptWishListItemWithCurrentStatusException(Status);
            }

            if (Status == WishListItemStatus.Requested)
            {
                if (!user.IsLeaderOf(_owner))
                {
                    throw new UserDoesNotHavePermissionToAcceptRequestedWishListItemException();
                }

                if (ShouldBeRequestedToDirector())
                {
                    Status = WishListItemStatus.RequestedToDirector;
                }
                else
                {
                    Status = WishListItemStatus.Accepted;
                }

                return;
            }

            if (!user.IsDirectorOf(_owner))
            {
                throw new UserDoesNotHavePermissionToAcceptRequestedWishListItemException();
            }

            Status = WishListItemStatus.Accepted;
        }
Example #3
0
        public void RejectBy(User user)
        {
            if (Status != WishListItemStatus.Requested &&
                Status != WishListItemStatus.RequestedToDirector)
            {
                throw new CannotRejectWishListItemWithCurrentStatusException(Status);
            }

            if (Status == WishListItemStatus.Requested)
            {
                if (!user.IsLeaderOf(_owner))
                {
                    throw new UserDoesNotHavePermissionToRejectRequestedWishListItemException();
                }

                Status = WishListItemStatus.Rejected;

                return;
            }

            if (!user.IsDirectorOf(_owner))
            {
                throw new UserDoesNotHavePermissionToRejectRequestedWishListItemException();
            }

            Status = WishListItemStatus.Rejected;
        }
 public WishListItem(
     WishListItemStatus status,
     User owner,
     decimal itemCost,
     bool areCostsInvoiced = true)
 {
     Owner            = owner;
     ItemCost         = itemCost;
     AreCostsInvoiced = areCostsInvoiced;
     State            = WishListItemState.CreateState(status);
 }
Example #5
0
 public WishListItem(
     WishListItemStatus status,
     User owner,
     decimal itemCost,
     bool areCostsInvoiced = true)
 {
     _owner            = owner;
     Status            = status;
     _itemCost         = itemCost;
     _areCostsInvoiced = areCostsInvoiced;
 }
Example #6
0
        public void StartRealizationBy(User user)
        {
            if (Status != WishListItemStatus.Accepted)
            {
                throw new CannotStartWishListItemRealizationWithCurrentStatusException(Status);
            }

            if (!user.IsSupervisor)
            {
                throw new UserDoesNotHavePermissionToStartWishListItemRealizationException();
            }

            Status = WishListItemStatus.InRealization;
        }
Example #7
0
        public void It_should_throw_exception_for_incorrect_status(WishListItemStatus status)
        {
            // Given
            var leader = new User(_leaderId, LeaderName);
            var user   = new User(_userId, UserName, leader);

            var item = new WishListItem(
                status,
                user,
                CostAmountWithoutAdditionalAcceptance);

            // When
            // Then
            Assert.Throws <CannotAcceptWishListItemWithCurrentStatusException>(() => { item.AcceptBy(leader); });
        }
        public void It_should_throw_exception_for_incorrect_status(WishListItemStatus status)
        {
            // Given
            var supervisor = new User(_supervisorId, SupervisorName, isSupervisor: true);
            var user       = new User(_userId, UserName);

            var item = new WishListItem(
                status,
                user,
                CostAmount);

            // When
            // Then
            Assert.Throws <CannotFinishWishListItemRealizationWithCurrentStatusException>(() =>
            {
                item.FinishRealizationBy(
                    supervisor);
            });
        }
Example #9
0
        public void FinishRealizationBy(User user)
        {
            if (Status != WishListItemStatus.InRealization)
            {
                throw new CannotFinishWishListItemRealizationWithCurrentStatusException(Status);
            }

            if (!user.IsSupervisor)
            {
                throw new UserDoesNotHavePermissionToFinishWishListItemRealizationException();
            }

            if (!_areCostsInvoiced)
            {
                throw new CannotFinishWishListItemRealizationWithNotInvoicedException();
            }

            Status = WishListItemStatus.Realized;
        }
 public CannotAcceptWishListItemWithCurrentStatusException(
     WishListItemStatus status)
     : base($"Cannot accept wish list item in {status} status.")
 {
     Status = status;
 }
Example #11
0
 private WishListItemState(
     WishListItemStatus status)
 {
     Status = status;
 }
Example #12
0
 public CannotFinishWishListItemRealizationWithCurrentStatusException(
     WishListItemStatus status)
     : base($"Cannot finish wish list item realization in {status} status.")
 {
     Status = status;
 }