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 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 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);
        }
Beispiel #4
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 ReviewerId()
        {
            RecordingDataSet recordingDataSet = new RecordingDataSet();

            ReviewGateway reviewGateway = new ReviewGateway(Connection);
            long          reviewId      =
                reviewGateway.Insert(recordingDataSet, 1, "Review Content");

            ReviewerGateway reviewerGateway =
                new ReviewerGateway(Connection);
            long reviewerId =
                reviewerGateway.Insert(recordingDataSet, "Reviewer Name");

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

            review.ReviewerId = reviewerId;
            reviewGateway.Update(recordingDataSet);

            Assert.AreEqual(reviewerId, review.Reviewer.Id);

            reviewGateway.Delete(recordingDataSet, reviewId);
            reviewerGateway.Delete(recordingDataSet, reviewerId);
        }
 public override void Insert()
 {
     recordingDataSet = new RecordingDataSet();
     gateway          = new ReviewerGateway(Connection);
     reviewerId       = gateway.Insert(recordingDataSet, reviewerName);
 }