public void RetrieveArtistFromDatabase()
        {
            RecordingDataSet loadedFromDB = new RecordingDataSet();

            RecordingDataSet.Artist loadedArtist =
                gateway.FindById(artistId, loadedFromDB);

            Assert.AreEqual(artistId, loadedArtist.Id);
            Assert.AreEqual(artistName, loadedArtist.Name);
        }
    public override void Insert()
    {
        recordingDataSet = new RecordingDataSet();

        recordingGateway = new RecordingGateway(Connection);
        labelGateway     = new LabelGateway(Connection);
        artistGateway    = new ArtistGateway(Connection);

        artistId    = artistGateway.Insert(recordingDataSet, "Artist");
        labelId     = labelGateway.Insert(recordingDataSet, "Label");
        recordingId = recordingGateway.Insert(recordingDataSet,
                                              "Recording Title", new DateTime(1999, 1, 12), artistId, labelId);

        RecordingDataSet.Recording recording =
            recordingGateway.FindById(recordingId, recordingDataSet);


        RecordingDataSet.Label label =
            labelGateway.FindById(labelId, recordingDataSet);

        RecordingDataSet.Artist artist =
            artistGateway.FindById(artistId, recordingDataSet);

        recording.Artist = artist;
        recording.Label  = label;

        recordingGateway.Update(recordingDataSet);

        RecordingDataSet loadedDataSet = new RecordingDataSet();

        loadedRecording = Catalog.FindByRecordingId(loadedDataSet, recordingId);
    }
    public override void Insert()
    {
        recordingDataSet = new RecordingDataSet();

        recordingGateway = new RecordingGateway(Connection);
        trackGateway     = new TrackGateway(Connection);
        reviewGateway    = new ReviewGateway(Connection);
        reviewerGateway  = new ReviewerGateway(Connection);
        labelGateway     = new LabelGateway(Connection);
        artistGateway    = new ArtistGateway(Connection);
        genreGateway     = new GenreGateway(Connection);

        artistId    = artistGateway.Insert(recordingDataSet, "Artist");
        labelId     = labelGateway.Insert(recordingDataSet, "Label");
        genreId     = genreGateway.Insert(recordingDataSet, "Genre");
        reviewerId  = reviewerGateway.Insert(recordingDataSet, "Reviewer");
        recordingId = recordingGateway.Insert(recordingDataSet,
                                              "Recording Title", new DateTime(1999, 1, 12), artistId, labelId);
        reviewId = reviewGateway.Insert(recordingDataSet, 1, "Review");
        trackId  = trackGateway.Insert(recordingDataSet, "Track Title", 120);

        RecordingDataSet.Recording recording =
            recordingGateway.FindById(recordingId, recordingDataSet);

        RecordingDataSet.Review review =
            reviewGateway.FindById(reviewId, recordingDataSet);

        RecordingDataSet.Track track =
            trackGateway.FindById(trackId, recordingDataSet);

        RecordingDataSet.Label label =
            labelGateway.FindById(labelId, recordingDataSet);

        RecordingDataSet.Genre genre =
            genreGateway.FindById(genreId, recordingDataSet);

        RecordingDataSet.Artist artist =
            artistGateway.FindById(artistId, recordingDataSet);

        RecordingDataSet.Reviewer reviewer =
            reviewerGateway.FindById(reviewerId, recordingDataSet);

        // setup the relationships
        recording.Artist = artist;
        recording.Label  = label;
        track.Recording  = recording;
        track.Artist     = artist;
        track.Genre      = genre;
        review.Recording = recording;
        review.Reviewer  = reviewer;

        recordingGateway.Update(recordingDataSet);
        trackGateway.Update(recordingDataSet);
        reviewGateway.Update(recordingDataSet);

        RecordingDataSet loadedDataSet = new RecordingDataSet();

        loadedRecording = Catalog.FindByRecordingId(loadedDataSet, recordingId);
    }
    public static RecordingDataSet.Recording FindByRecordingId(
        RecordingDataSet recordingDataSet, long recordingId)
    {
        SqlConnection connection = null;

        RecordingDataSet.Recording recording = null;

        try
        {
            connection = new SqlConnection(
                ConfigurationSettings.AppSettings.Get("Catalog.Connection"));
            connection.Open();

            RecordingGateway recordingGateway = new RecordingGateway(connection);
            recording = recordingGateway.FindById(recordingId, recordingDataSet);
            if (recording != null)
            {
                long                    artistId      = recording.ArtistId;
                ArtistGateway           artistGateway = new ArtistGateway(connection);
                RecordingDataSet.Artist artist        =
                    artistGateway.FindById(artistId, recordingDataSet);

                long                   labelId      = recording.LabelId;
                LabelGateway           labelGateway = new LabelGateway(connection);
                RecordingDataSet.Label label        =
                    labelGateway.FindById(labelId, recordingDataSet);

                GenreGateway genreGateway = new GenreGateway(connection);
                TrackGateway trackGateway = new TrackGateway(connection);
                foreach (RecordingDataSet.Track track in
                         trackGateway.FindByRecordingId(recordingId, recordingDataSet))
                {
                    artistId = track.ArtistId;
                    long genreId = track.GenreId;
                    artist = artistGateway.FindById(artistId, recordingDataSet);
                    RecordingDataSet.Genre genre =
                        genreGateway.FindById(genreId, recordingDataSet);
                }

                ReviewGateway   reviewGateway   = new ReviewGateway(connection);
                ReviewerGateway reviewerGateway = new ReviewerGateway(connection);
                foreach (RecordingDataSet.Review review in
                         reviewGateway.FindByRecordingId(recordingId, recordingDataSet))
                {
                    long reviewerId = review.ReviewerId;

                    RecordingDataSet.Reviewer reviewer =
                        reviewerGateway.FindById(reviewerId, recordingDataSet);
                }
            }
        }
        finally
        {
            if (connection != null)
            {
                connection.Close();
            }
        }

        return(recording);
    }