public static async Task TryUpdateAsync_ExistingSongDirector_Succeeds(
        string awsRegionSystemName,
        bool useDynamoDBLocal,
        string songDirectorId,
        string fullName,
        string emailAddress,
        string phoneNumber,
        string rankName,
        bool isActive)
    {
        // Arrange

        SongDirector songDirector = SongDirector
                                    .TryCreate(fullName, emailAddress, phoneNumber, rankName, isActive)
                                    .Value;

        songDirector.UpdateId(songDirectorId);

        AggregateSongDirectorRepository aggregateSongDirectorRepository =
            GetAggregateSongDirectorRepository(awsRegionSystemName, useDynamoDBLocal);

        // Act

        Result updateResult = await aggregateSongDirectorRepository
                              .TryUpdateAsync(songDirector)
                              .ConfigureAwait(false);

        // Assert

        Assert.True(updateResult.IsSuccess);
    }
    public static async Task TryAddAsync_ValidSongDirector_Succeeds(
        string awsRegionSystemName,
        bool useDynamoDBLocal,
        string fullName,
        string emailAddress,
        string phoneNumber,
        string rankName,
        bool isActive)
    {
        // Arrange

        SongDirector songDirector = SongDirector
                                    .TryCreate(fullName, emailAddress, phoneNumber, rankName, isActive)
                                    .Value;

        AggregateSongDirectorRepository aggregateSongDirectorRepository =
            GetAggregateSongDirectorRepository(awsRegionSystemName, useDynamoDBLocal);

        // Act

        Result <SongDirector> addResult = await aggregateSongDirectorRepository
                                          .TryAddAsync(songDirector)
                                          .ConfigureAwait(false);

        // Assert

        Assert.True(addResult.IsSuccess);

        Console.WriteLine(addResult.Value.Id);
    }
Exemple #3
0
    /// <summary>
    /// Tries to add a song director.
    /// </summary>
    /// <param name="request">The add song director request.</param>
    /// <returns>The result of the request.</returns>
    private async Task <TOutput> TryAddSongDirector(AddSongDirectorRequest request)
    {
        // Validate the new song director
        Result <SongDirector> createSongDirectorResult = SongDirector.TryCreate(
            request.FullName,
            request.EmailAddress,
            request.PhoneNumber,
            request.RankName,
            request.IsActive);

        // Validation failure
        if (createSongDirectorResult.IsFailed)
        {
            return(ValidationFailure(createSongDirectorResult));
        }

        SongDirector songDirector = createSongDirectorResult.Value;

        // Add the song director
        Result <SongDirector> addSongDirectorResult = await _songDirectorRepository
                                                      .TryAddAsync(songDirector)
                                                      .ConfigureAwait(false);

        if (addSongDirectorResult.IsFailed)
        {
            return(FailedToAddSongDirector(addSongDirectorResult));
        }

        SongDirectorUseCaseModel addedSongDirector = SongDirectorUseCaseModel
                                                     .GrandmasterView(songDirector);

        return(SongDirectorAdded(addedSongDirector));
    }
 /// <summary>
 /// Validates the song director's id.
 /// </summary>
 /// <param name="songDirector">The song director to validate.</param>
 /// <exception cref="ArgumentException">Thrown if id is null.</exception>
 private static void ValidateId(SongDirector songDirector)
 {
     if (songDirector.Id == null)
     {
         throw new ArgumentException("Invalid song director; id is not set.");
     }
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SongDirectorDataModel"/> class.
 /// </summary>
 /// <param name="songDirector">Song director.</param>
 public SongDirectorDataModel(SongDirector songDirector)
     : this(
         songDirector.Id,
         songDirector.FullName,
         songDirector.EmailAddress,
         songDirector.PhoneNumber,
         songDirector.Rank?.Name,
         songDirector.IsActive)
 {
 }
        /// <summary>
        /// Creates a grandmaster view of a song director model.
        /// </summary>
        /// <param name="songDirector">The song director to convert.</param>
        /// <returns><see cref="SongDirectorUseCaseModel"/>.</returns>
        public static SongDirectorUseCaseModel GrandmasterView(SongDirector songDirector)
        {
            ValidateId(songDirector);

            return(new(
                       songDirector.Id !,
                       songDirector.FullName,
                       songDirector.EmailAddress,
                       songDirector.PhoneNumber,
                       songDirector.IsActive,
                       songDirector.Rank?.Name,
                       isDeletable : true,
                       isEditable : true));
        }
        /// <summary>
        /// Creates a read-only song director model.
        /// </summary>
        /// <param name="songDirector">The song director to convert.</param>
        /// <returns><see cref="SongDirectorUseCaseModel"/>.</returns>
        public static SongDirectorUseCaseModel ReadOnly(SongDirector songDirector)
        {
            ValidateId(songDirector);

            return(new(
                       songDirector.Id !,
                       songDirector.FullName,
                       songDirector.EmailAddress,
                       songDirector.PhoneNumber,
                       songDirector.IsActive,
                       rank : null,
                       isDeletable : false,
                       isEditable : false));
        }
Exemple #8
0
        /// <summary>
        /// Converts a song director to a model.
        /// </summary>
        /// <param name="songDirector">The song director to convert.</param>
        /// <param name="requesterId">Requester id.</param>
        /// <param name="requesterRank">Requester rank.</param>
        /// <returns><see cref="SongDirectorUseCaseModel"/>.</returns>
        public static SongDirectorUseCaseModel ConvertToUseCaseModel(
            this SongDirector songDirector, string?requesterId, Rank?requesterRank)
        {
            if (songDirector.Id == requesterId)
            {
                return(SongDirectorUseCaseModel.Self(songDirector, requesterRank));
            }

            if (requesterRank == Rank.Grandmaster)
            {
                return(SongDirectorUseCaseModel.GrandmasterView(songDirector));
            }

            return(SongDirectorUseCaseModel.ReadOnly(songDirector));
        }
        /// <summary>
        /// Creates a song director model representing the requester.
        /// </summary>
        /// <param name="songDirector">The song director to convert.</param>
        /// <param name="rank">Rank.</param>
        /// <returns><see cref="SongDirectorUseCaseModel"/>.</returns>
        public static SongDirectorUseCaseModel Self(SongDirector songDirector, Rank?rank)
        {
            ValidateId(songDirector);

            bool isGrandmaster = rank == Domain.SongDirectorAggregate.Rank.Grandmaster;

            return(new(
                       songDirector.Id !,
                       songDirector.FullName,
                       songDirector.EmailAddress,
                       songDirector.PhoneNumber,
                       songDirector.IsActive,
                       rank : isGrandmaster?songDirector.Rank?.Name : null,
                       isDeletable : false,
                       isEditable : true));
        }
Exemple #10
0
        public static void TryCreate_Multiple_ReturnsExpectedIsSuccess(
            string?fullName,
            string?emailAddress,
            string?phoneNumber,
            string?rankName,
            bool isActive,
            bool expectedIsSuccess)
        {
            // Act

            Result <SongDirector> songDirectorCreateResult = SongDirector.TryCreate(
                fullName, emailAddress, phoneNumber, rankName, isActive);

            // Assert

            Assert.Equal(expectedIsSuccess, songDirectorCreateResult.IsSuccess);
        }