Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to parse the provided command as a line number
        /// and if successful, calls the appropriate user input method
        /// for the selected comic book property.
        /// </summary>
        /// <param name="command">The line number command.</param>
        /// <param name="comicBook">The comic book to update.</param>
        /// <returns>Returns "true" if the comic book property was successfully updated, otherwise "false".</returns>
        private static bool AttemptUpdateComicBookProperty(
            string command, ComicBook comicBook)
        {
            _seriesRepository = new SeriesRepository(context);
            var successful = false;

            // Attempt to parse the command to a line number.
            int lineNumber = 0;

            int.TryParse(command, out lineNumber);

            // If the number is within range then get that comic book ID.
            if (lineNumber > 0 && lineNumber <= EditableProperties.Count)
            {
                // Retrieve the property name for the provided line number.
                string propertyName = EditableProperties[lineNumber - 1];

                // Switch on the provided property name and call the
                // associated user input method for that property name.
                switch (propertyName)
                {
                case "SeriesId":
                    comicBook.SeriesId = GetSeriesId();
                    comicBook.Series   = _seriesRepository.Get(comicBook.SeriesId);
                    break;

                case "IssueNumber":
                    comicBook.IssueNumber = GetIssueNumber();
                    break;

                case "Description":
                    comicBook.Description = GetDescription();
                    break;

                case "PublishedOn":
                    comicBook.PublishedOn = GetPublishedOnDate();
                    break;

                case "AverageRating":
                    comicBook.AverageRating = GetAverageRating();
                    break;

                case "Artists":
                    ChooseAddArtist(comicBook);
                    break;

                default:
                    break;
                }

                successful = true;
            }


            context.Dispose();
            return(successful);
        }
Ejemplo n.º 2
0
        public ActionResult Detail(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var series = _seriesRepository.Get((int)id);

            if (series == null)
            {
                return(HttpNotFound());
            }

            // Sort the comic books.
            series.ComicBooks = series.ComicBooks
                                .OrderByDescending(cb => cb.IssueNumber)
                                .ToList();

            return(View(series));
        }
Ejemplo n.º 3
0
        public void Verify_Get_ByKey_Should_ReturnTheCorrectSeries()
        {
            // Arrange
            Mock <IDbSet <Series> > mockSetSeries;
            var mockContext = SeriesMockingSetup.DoMockingSetupForContext(true, out mockSetSeries);
            var repository  = new SeriesRepository(mockContext.Object);
            // Act
            var series = repository.Get("KING-STEPHEN");

            // Assert
            Assert.Equal("/TEST/KING-STEPHEN", series.ApiDetailUrl);
        }
 public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity()
 {
     // Arrange
     Mock<IDbSet<Series>> mockSetSeries;
     var mockContext = SeriesMockingSetup.DoMockingSetupForContext(true, out mockSetSeries);
     var repository = new SeriesRepository(mockContext.Object);
     var series = repository.Get(1);
     // Act
     repository.Deactivate(series);
     // Assert
     Assert.Equal(false, series.Active);
 }
Ejemplo n.º 5
0
        public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity()
        {
            // Arrange
            Mock <IDbSet <Series> > mockSetSeries;
            var mockContext = SeriesMockingSetup.DoMockingSetupForContext(true, out mockSetSeries);
            var repository  = new SeriesRepository(mockContext.Object);
            var series      = repository.Get(1);

            // Act
            repository.Deactivate(series);
            // Assert
            Assert.Equal(false, series.Active);
        }
Ejemplo n.º 6
0
        public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
        {
            // Arrange
            Mock <IDbSet <Series> > mockSetSeries;
            var mockContext = SeriesMockingSetup.DoMockingSetupForContext(true, out mockSetSeries);
            var repository  = new SeriesRepository(mockContext.Object);
            var series      = repository.Get(1);

            // Act
            repository.Remove(series);
            // Assert
            mockSetSeries.Verify(x => x.Remove((Series)series), Times.Once);
        }
Ejemplo n.º 7
0
        public void Verify_Update_Should_SetTheEntityStateToModified()
        {
            // Arrange
            Mock <IDbSet <Series> > mockSetSeries;
            var mockContext = SeriesMockingSetup.DoMockingSetupForContext(true, out mockSetSeries);
            var repository  = new SeriesRepository(mockContext.Object);
            var series      = repository.Get(1);

            series.ApiDetailUrl = "/TEST";
            // Act
            repository.Update(series);
            // Assert
            mockContext.Verify(x => x.SetModified(It.IsAny <object>()), Times.Once);
        }
Ejemplo n.º 8
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var series = SeriesRepository.Get((int)id, includeRelatedEntities: false);

            if (series == null)
            {
                return(HttpNotFound());
            }

            return(View(series));
        }
Ejemplo n.º 9
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var series = SeriesRepository.Get((int)id);

            if (series == null)
            {
                return(HttpNotFound());
            }

            return(View(series));
        }
 public void Verify_Get_ByID_Should_ReturnTheCorrectSeries()
 {
     // Arrange
     Mock<IDbSet<Series>> mockSetSeries;
     var mockContext = SeriesMockingSetup.DoMockingSetupForContext(true, out mockSetSeries);
     var repository = new SeriesRepository(mockContext.Object);
     // Act
     var series = repository.Get(1);
     // Assert
                 Assert.Equal("/TEST/KING-STEPHEN", series.ApiDetailUrl);
 }
 public void Verify_Update_Should_SetTheEntityStateToModified()
 {
     // Arrange
     Mock<IDbSet<Series>> mockSetSeries;
     var mockContext = SeriesMockingSetup.DoMockingSetupForContext(true, out mockSetSeries);
     var repository = new SeriesRepository(mockContext.Object);
     var series = repository.Get(1);
     series.ApiDetailUrl = "/TEST";
     // Act
     repository.Update(series);
     // Assert
     mockContext.Verify(x => x.SetModified(It.IsAny<object>()), Times.Once);
 }
 public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
 {
     // Arrange
     Mock<IDbSet<Series>> mockSetSeries;
     var mockContext = SeriesMockingSetup.DoMockingSetupForContext(true, out mockSetSeries);
     var repository = new SeriesRepository(mockContext.Object);
     var series = repository.Get(1);
     // Act
     repository.Remove(series);
     // Assert
     mockSetSeries.Verify(x => x.Remove((Series)series), Times.Once);
 }