Beispiel #1
0
        public void AverageRatingZero()
        {
            RecordingDataSet dataSet = new RecordingDataSet();

            RecordingDataSet.Recording recording =
                dataSet.Recordings.NewRecording();
            recording.Id          = 1;
            recording.Title       = "Title";
            recording.ReleaseDate = DateTime.Today;

            RecordingDataSet.Label label = dataSet.Labels.NewLabel();
            label.Id   = 1;
            label.Name = "Label";
            dataSet.Labels.AddLabel(label);

            RecordingDataSet.Artist artist = dataSet.Artists.NewArtist();
            artist.Id   = 1;
            artist.Name = "Artist";
            dataSet.Artists.AddArtist(artist);

            recording.Label  = label;
            recording.Artist = artist;
            dataSet.Recordings.AddRecording(recording);

            RecordingDto dto = RecordingAssembler.WriteDto(recording);

            Assert.AreEqual(0, dto.averageRating);
        }
    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 void RetrieveLabelFromDatabase()
        {
            RecordingDataSet loadedFromDB = new RecordingDataSet();

            RecordingDataSet.Label loadedLabel = gateway.FindById(labelId, loadedFromDB);
            Assert.AreEqual(labelId, loadedLabel.Id);
            Assert.AreEqual(labelName, loadedLabel.Name);
        }
        public void DeleteLabelFromDatabase()
        {
            RecordingDataSet emptyDataSet   = new RecordingDataSet();
            long             deletedLabelId = gateway.Insert(emptyDataSet, "Deleted Label");

            gateway.Delete(emptyDataSet, deletedLabelId);

            RecordingDataSet.Label deleletedLabel = gateway.FindById(deletedLabelId, emptyDataSet);
            Assert.IsNull(deleletedLabel);
        }
        public void UpdateLableNameInDatabase()
        {
            RecordingDataSet.Label label = recordingDataSet.Labels[0];
            label.Name = "Modified Name";
            gateway.Update(recordingDataSet);

            RecordingDataSet updatedDataSet = new RecordingDataSet();

            RecordingDataSet.Label updatedLabel = gateway.FindById(labelId, updatedDataSet);
            Assert.AreEqual("Modified Name", updatedLabel.Name);
        }
    public RecordingDataSet.Label FindById(long labelId, RecordingDataSet recordingDataSet)
    {
        command.Parameters["@id"].Value = labelId;
        adapter.Fill(recordingDataSet, recordingDataSet.Labels.TableName);
        DataRow[] rows = recordingDataSet.Labels.Select(String.Format("id={0}", labelId));
        if (rows.Length < 1)
        {
            return(null);
        }

        RecordingDataSet.Label label = (RecordingDataSet.Label)rows[0];
        return(label);
    }
    public long Insert(RecordingDataSet recordingDataSet, string labelName)
    {
        long labelId = IdGenerator.GetNextId(recordingDataSet.Labels.TableName, connection);

        RecordingDataSet.Label labelRow = recordingDataSet.Labels.NewLabel();
        labelRow.Id   = labelId;
        labelRow.Name = labelName;
        recordingDataSet.Labels.AddLabel(labelRow);

        adapter.Update(recordingDataSet, recordingDataSet.Labels.TableName);

        return(labelId);
    }
            public void Execute()
            {
                SqlConnection connection =
                    TransactionManager.Transaction().Connection;
                RecordingGateway recordingGateway =
                    new RecordingGateway(connection);

                recording = recordingGateway.FindById(recordingId, dataSet);

                if (recording == null)
                {
                    return;
                }
                long          artistId      = recording.ArtistId;
                ArtistGateway artistGateway = new ArtistGateway(connection);

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

                long         labelId      = recording.LabelId;
                LabelGateway labelGateway = new LabelGateway(connection);

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

                GenreGateway genreGateway = new GenreGateway(connection);

                TrackGateway trackGateway = new TrackGateway(connection);

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

                ReviewGateway   reviewGateway   = new ReviewGateway(connection);
                ReviewerGateway reviewerGateway = new ReviewerGateway(connection);

                foreach (RecordingDataSet.Review review in
                         reviewGateway.FindByRecordingId(recordingId, dataSet))
                {
                    long reviewerId = review.ReviewerId;

                    RecordingDataSet.Reviewer reviewer =
                        reviewerGateway.FindById(reviewerId, dataSet);
                }
            }
Beispiel #10
0
        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);
        }
 public void LabelOfTheRecording()
 {
     RecordingDataSet.Label loadedLabel = loadedRecording.Label;
     Assert.AreEqual(labelId, loadedLabel.Id);
 }
 public void Delete(RecordingDataSet recordingDataSet, long labelId)
 {
     RecordingDataSet.Label loadedLabel = FindById(labelId, recordingDataSet);
     loadedLabel.Delete();
     adapter.Update(recordingDataSet, recordingDataSet.Labels.TableName);
 }
Beispiel #13
0
    public static RecordingDataSet.Recording Make()
    {
        RecordingDataSet dataSet = new RecordingDataSet();

        RecordingDataSet.Recording recording =
            dataSet.Recordings.NewRecording();
        recording.Id          = 1;
        recording.Title       = "Title";
        recording.ReleaseDate = DateTime.Today;

        RecordingDataSet.Label label = dataSet.Labels.NewLabel();
        label.Id   = 1;
        label.Name = "Label";
        dataSet.Labels.AddLabel(label);

        RecordingDataSet.Artist artist = dataSet.Artists.NewArtist();
        artist.Id   = 1;
        artist.Name = "Artist";
        dataSet.Artists.AddArtist(artist);

        recording.Label  = label;
        recording.Artist = artist;
        dataSet.Recordings.AddRecording(recording);

        RecordingDataSet.Genre genre = dataSet.Genres.NewGenre();
        genre.Id   = 1;
        genre.Name = "Genre";
        dataSet.Genres.AddGenre(genre);

        int       trackCount = 2;
        ArrayList tracks     = new ArrayList(trackCount);

        for (int i = 0; i < trackCount; i++)
        {
            RecordingDataSet.Track track = dataSet.Tracks.NewTrack();
            track.Recording = recording;
            track.Id        = i + 1;
            track.Title     = "Track Title";
            track.Duration  = 100;
            track.Genre     = genre;
            track.Artist    = artist;
            dataSet.Tracks.AddTrack(track);
            tracks.Add(track);
        }

        RecordingDataSet.Reviewer reviewer =
            dataSet.Reviewers.NewReviewer();
        reviewer.Id   = 1;
        reviewer.Name = "Reviewer";
        dataSet.Reviewers.AddReviewer(reviewer);

        int       reviewCount = 3;
        ArrayList reviews     = new ArrayList(reviewCount);

        for (int j = 0; j < reviewCount; j++)
        {
            RecordingDataSet.Review review = dataSet.Reviews.NewReview();
            review.Id        = j + 1;
            review.Content   = "Review Content";
            review.Rating    = j + 1;
            review.Reviewer  = reviewer;
            review.Recording = recording;
            dataSet.Reviews.AddReview(review);
            reviews.Add(review);
        }

        return(recording);
    }