public void AddReviewWithExistingReviewer()
    {
        int    rating  = 1;
        string content = "Review content";

        ReviewerGateway reviewerGateway =
            new ReviewerGateway(Connection);
        long reviewerId = reviewerGateway.Insert(recordingDataSet, reviewerName);

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

        RecordingDataSet.Review review = Catalog.AddReview(recordingDataSet, reviewerName, content, rating, Recording.Id);
        Assert.IsNotNull(review);

        RecordingDataSet loadedFromDBDataSet = new RecordingDataSet();

        RecordingDataSet.Recording loadedFromDBRecording = Catalog.FindByRecordingId(loadedFromDBDataSet, Recording.Id);
        Assert.AreEqual(1, loadedFromDBRecording.GetReviews().Length);

        RecordingDataSet.Review loadedFromDBReview =
            loadedFromDBRecording.GetReviews()[0];

        ReviewGateway reviewGateway = new ReviewGateway(Connection);

        reviewGateway.Delete(loadedFromDBDataSet, loadedFromDBReview.Id);
        reviewerGateway.Delete(recordingDataSet, reviewerId);
    }
        public RecordingDataSet.Reviewer FindByName(string reviewerName,
                                                    RecordingDataSet recordingDataSet)
        {
            SqlCommand command =
                new SqlCommand("select id, name from reviewer where name = @name",
                               connection);

            command.Parameters.Add("@name", SqlDbType.VarChar);
            SqlDataAdapter adapter = new SqlDataAdapter(command);

            command.Parameters["@name"].Value = reviewerName;

            adapter.Fill(recordingDataSet, recordingDataSet.Reviewers.TableName);

            string selectString =
                String.Format("name='{0}'", reviewerName);

            DataRow[] rows =
                recordingDataSet.Reviewers.Select(selectString);
            if (rows.Length < 1)
            {
                return(null);
            }

            RecordingDataSet.Reviewer reviewer = (RecordingDataSet.Reviewer)rows[0];
            return(reviewer);
        }
    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 RetrieveReviewerFromDatabase()
        {
            RecordingDataSet loadedFromDB = new RecordingDataSet();

            RecordingDataSet.Reviewer loadedReviewer = gateway.FindById(reviewerId, loadedFromDB);

            Assert.AreEqual(reviewerId, loadedReviewer.Id);
            Assert.AreEqual(reviewerName, loadedReviewer.Name);
        }
Пример #5
0
        public static RecordingDataSet.Review AddReview(RecordingDataSet dataSet,
                                                        string name, string content, int rating, long recordingId)
        {
            SqlConnection connection = null;

            RecordingDataSet.Review review = null;

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

                RecordingDataSet.Recording recording =
                    FindByRecordingId(dataSet, recordingId);

                ReviewerGateway reviewerGateway =
                    new ReviewerGateway(connection);

                RecordingDataSet.Reviewer reviewer =
                    reviewerGateway.FindByName(name, dataSet);

                if (reviewer == null)
                {
                    long reviewerId = reviewerGateway.Insert(dataSet, name);
                    reviewer = reviewerGateway.FindById(reviewerId, dataSet);
                }

                foreach (RecordingDataSet.Review existingReview in
                         recording.GetReviews())
                {
                    if (existingReview.Reviewer.Name.Equals(name))
                    {
                        throw new ExistingReviewException(existingReview.Id);
                    }
                }

                ReviewGateway reviewGateway = new ReviewGateway(connection);
                long          reviewId      = reviewGateway.Insert(dataSet, rating, content);

                review            = reviewGateway.FindById(reviewId, dataSet);
                review.ReviewerId = reviewer.Id;
                review.Recording  = recording;
                reviewGateway.Update(dataSet);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(review);
        }
        public void DeleteReviewerFromDatabase()
        {
            RecordingDataSet emptyDataSet      = new RecordingDataSet();
            long             deletedReviewerId = gateway.Insert(emptyDataSet, "Deleted Reviewer");

            gateway.Delete(emptyDataSet, deletedReviewerId);

            RecordingDataSet.Reviewer deleletedReviewer =
                gateway.FindById(deletedReviewerId, emptyDataSet);
            Assert.IsNull(deleletedReviewer);
        }
        public RecordingDataSet.Reviewer FindById(long reviewerId, RecordingDataSet recordingDataSet)
        {
            command.Parameters["@id"].Value = reviewerId;
            adapter.Fill(recordingDataSet, recordingDataSet.Reviewers.TableName);
            DataRow[] rows = recordingDataSet.Reviewers.Select(String.Format("id={0}", reviewerId));
            if (rows.Length < 1)
            {
                return(null);
            }

            RecordingDataSet.Reviewer reviewer = (RecordingDataSet.Reviewer)rows[0];
            return(reviewer);
        }
        public long Insert(RecordingDataSet recordingDataSet, string reviewerName)
        {
            long reviewerId = IdGenerator.GetNextId(recordingDataSet.Reviewers.TableName, connection);

            RecordingDataSet.Reviewer reviewerRow = recordingDataSet.Reviewers.NewReviewer();
            reviewerRow.Id   = reviewerId;
            reviewerRow.Name = reviewerName;
            recordingDataSet.Reviewers.AddReviewer(reviewerRow);

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

            return(reviewerId);
        }
            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);
                }
            }
        public void UpdateReviewerFieldInReviewer()
        {
            string modifiedName = "Modified Name";

            RecordingDataSet.Reviewer reviewer = recordingDataSet.Reviewers[0];
            reviewer.Name = modifiedName;
            gateway.Update(recordingDataSet);

            RecordingDataSet updatedDataSet = new RecordingDataSet();

            RecordingDataSet.Reviewer updatedReviewer =
                gateway.FindById(reviewerId, updatedDataSet);
            Assert.AreEqual(modifiedName, updatedReviewer.Name);
        }
        public void MakeReview()
        {
            RecordingDataSet recordingDataSet = new RecordingDataSet();

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

            review = recordingDataSet.Reviews.NewReview();
            review.Id = 1;
            review.Content = "Review Content";
            review.Rating = 2;
            review.Reviewer = reviewer;
            recordingDataSet.Reviews.AddReview(review);

            reviewDto = RecordingAssembler.WriteReview(review);
        }
Пример #12
0
        public void MakeReview()
        {
            RecordingDataSet recordingDataSet = new RecordingDataSet();

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

            review          = recordingDataSet.Reviews.NewReview();
            review.Id       = 1;
            review.Content  = "Review Content";
            review.Rating   = 2;
            review.Reviewer = reviewer;
            recordingDataSet.Reviews.AddReview(review);

            reviewDto = RecordingAssembler.WriteReview(review);
        }
Пример #13
0
    public void AddTwoReviewsWithExistingReviewer()
    {
        int    rating  = 1;
        string content = "Review content";

        ReviewerGateway reviewerGateway =
            new ReviewerGateway(Connection);
        long reviewerId =
            reviewerGateway.Insert(recordingDataSet, reviewerName);

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

        RecordingDataSet.Review reviewOne =
            Catalog.AddReview(recordingDataSet, reviewerName,
                              content, rating, Recording.Id);

        try
        {
            RecordingDataSet.Review reviewTwo =
                Catalog.AddReview(recordingDataSet,
                                  reviewerName, content, rating, Recording.Id);
            Assert.Fail("Expected an ExistingReviewException");
        }
        catch (ExistingReviewException exception)
        {
            Assert.AreEqual(reviewOne.Id, exception.ExistingId);
        }
        finally
        {
            RecordingDataSet           dbDataSet   = new RecordingDataSet();
            RecordingDataSet.Recording dbRecording =
                Catalog.FindByRecordingId(dbDataSet, Recording.Id);
            RecordingDataSet.Review[] reviews =
                dbRecording.GetReviews();

            ReviewGateway reviewGateway = new ReviewGateway(Connection);
            foreach (RecordingDataSet.Review existingReview in reviews)
            {
                reviewGateway.Delete(dbDataSet, existingReview.Id);
            }
            reviewerGateway.Delete(recordingDataSet, reviewerId);
        }
    }
    public void DeleteReview()
    {
        int    rating  = 1;
        string content = "Review content";

        ReviewerGateway reviewerGateway =
            new ReviewerGateway(Connection);
        long reviewerId = reviewerGateway.Insert(recordingDataSet, reviewerName);

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

        RecordingDataSet.Review review = Catalog.AddReview(recordingDataSet, reviewerName, content, rating, recordingId);
        Catalog.DeleteReview(review.Id);

        RecordingDataSet loadedFromDB = new RecordingDataSet();

        RecordingDataSet.Recording loadedFromDBRecording = Catalog.FindByRecordingId(loadedFromDB, recordingId);
        Assert.AreEqual(0, loadedFromDBRecording.GetReviews().Length);
    }
    public void AddTwoReviewsWithExistingReviewer()
    {
        int    rating  = 1;
        string content = "Review content";

        ReviewerGateway reviewerGateway = new ReviewerGateway(Connection);
        long            reviewerId      = reviewerGateway.Insert(recordingDataSet, reviewerName);

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

        RecordingDataSet.Review reviewOne = Catalog.AddReview(recordingDataSet, reviewerName, content, rating, recordingId);

        try
        {
            RecordingDataSet.Review reviewTwo = Catalog.AddReview(recordingDataSet, reviewerName, content, rating, recordingId);
            Assert.Fail("Expected an ExistingReviewException");
        }
        catch (ExistingReviewException exception)
        {
            Assert.AreEqual(reviewOne.Id, exception.ExistingId);
        }
    }
            public void Execute()
            {
                SqlConnection connection =
                    TransactionManager.Transaction().Connection;

                RecordingDataSet.Recording recording =
                    FindByRecordingId(dataSet, recordingId);

                ReviewerGateway reviewerGateway =
                    new ReviewerGateway(connection);

                RecordingDataSet.Reviewer reviewer =
                    reviewerGateway.FindByName(name, dataSet);

                if (reviewer == null)
                {
                    long reviewerId = reviewerGateway.Insert(dataSet, name);
                    reviewer = reviewerGateway.FindById(reviewerId, dataSet);
                }

                foreach (RecordingDataSet.Review existingReview in recording.GetReviews())
                {
                    if (existingReview.Reviewer.Name.Equals(name))
                    {
                        throw new ExistingReviewException(existingReview.Id);
                    }
                }

                ReviewGateway reviewGateway = new ReviewGateway(connection);
                long          reviewId      = reviewGateway.Insert(dataSet, rating, content);

                review = reviewGateway.FindById(reviewId, dataSet);

                review.ReviewerId = reviewer.Id;
                review.Recording  = recording;
                reviewGateway.Update(dataSet);
            }
Пример #17
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);
        }
Пример #18
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);
    }
 public void ReviewerOfTheReview()
 {
     RecordingDataSet.Reviewer loadedReviewer = loadedRecording.GetReviews()[0].Reviewer;
     Assert.AreEqual(reviewerId, loadedReviewer.Id);
 }
 public void Delete(RecordingDataSet recordingDataSet, long reviewerId)
 {
     RecordingDataSet.Reviewer loadedReviewer = FindById(reviewerId, recordingDataSet);
     loadedReviewer.Delete();
     adapter.Update(recordingDataSet, recordingDataSet.Reviewers.TableName);
 }