private void InitData()
        {
            if (!publishers.IsInit)
            {
                publishers.Create(new Publisher()
                {
                    Name = "publisher1"
                });
                publishers.Create(new Publisher()
                {
                    Name = "publisher2"
                });
                publishers.IsInit = true;
            }
            if (!authors.IsInit)
            {
                authors.Create(new Author()
                {
                    Name        = "author1",
                    DateOfBirth = new DateTime(1966, 08, 15),
                    DateOfDeath = null
                });
                authors.Create(new Author()
                {
                    Name        = "author2",
                    DateOfBirth = new DateTime(1947, 11, 21),
                    DateOfDeath = new DateTime(2006, 10, 5)
                });
                authors.IsInit = true;
            }

            if (!books.IsInit)
            {
                books.Create(new Book()
                {
                    Name      = "Book1",
                    Publisher = publishers.Get(1),
                    Author    = new List <Author>()
                    {
                        authors.Get(1)
                    },
                    PublishDate = new DateTime(2010, 10, 1),
                    PageCount   = 187,
                    ISBN        = "ISBN 5-02-013850-9"
                });
                books.Create(new Book()
                {
                    Name      = "Book2",
                    Publisher = publishers.Get(1),
                    Author    = new List <Author>()
                    {
                        authors.Get(1), authors.Get(2)
                    },
                    PublishDate = new DateTime(2011, 05, 20),
                    PageCount   = 256,
                    ISBN        = "ISBN 4-13-019790-7"
                });
                books.IsInit = true;
            }
        }
 public ActionResult Edit(int?id)
 {
     if (id != null)
     {
         ViewBag.page = "Edit";
         return(View("Edit", publishers.Get((int)id)));
     }
     return(RedirectToAction("List"));
 }
Exemplo n.º 3
0
        public void Verify_Get_ByKey_Should_ReturnTheCorrectPublisher()
        {
            // Arrange
            Mock <IDbSet <Publisher> > mockSetPublishers;
            var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
            var repository  = new PublishersRepository(mockContext.Object);
            // Act
            var publishers = repository.Get("KING-STEPHEN");

            // Assert
            Assert.Equal("/TEST/KING-STEPHEN", publishers.ApiDetailUrl);
        }
 public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity()
 {
     // Arrange
     Mock<IDbSet<Publisher>> mockSetPublishers;
     var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
     var repository = new PublishersRepository(mockContext.Object);
     var publishers = repository.Get(1);
     // Act
     repository.Deactivate(publishers);
     // Assert
     Assert.Equal(false, publishers.Active);
 }
Exemplo n.º 5
0
        public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity()
        {
            // Arrange
            Mock <IDbSet <Publisher> > mockSetPublishers;
            var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
            var repository  = new PublishersRepository(mockContext.Object);
            var publishers  = repository.Get(1);

            // Act
            repository.Deactivate(publishers);
            // Assert
            Assert.Equal(false, publishers.Active);
        }
Exemplo n.º 6
0
        public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
        {
            // Arrange
            Mock <IDbSet <Publisher> > mockSetPublishers;
            var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
            var repository  = new PublishersRepository(mockContext.Object);
            var publishers  = repository.Get(1);

            // Act
            repository.Remove(publishers);
            // Assert
            mockSetPublishers.Verify(x => x.Remove((Publisher)publishers), Times.Once);
        }
Exemplo n.º 7
0
        public void Verify_Update_Should_SetTheEntityStateToModified()
        {
            // Arrange
            Mock <IDbSet <Publisher> > mockSetPublishers;
            var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
            var repository  = new PublishersRepository(mockContext.Object);
            var publishers  = repository.Get(1);

            publishers.ApiDetailUrl = "/TEST";
            // Act
            repository.Update(publishers);
            // Assert
            mockContext.Verify(x => x.SetModified(It.IsAny <object>()), Times.Once);
        }
 public void Verify_Get_ByID_Should_ReturnTheCorrectPublisher()
 {
     // Arrange
     Mock<IDbSet<Publisher>> mockSetPublishers;
     var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
     var repository = new PublishersRepository(mockContext.Object);
     // Act
     var publishers = repository.Get(1);
     // Assert
                 Assert.Equal("/TEST/KING-STEPHEN", publishers.ApiDetailUrl);
 }
 public void Verify_Update_Should_SetTheEntityStateToModified()
 {
     // Arrange
     Mock<IDbSet<Publisher>> mockSetPublishers;
     var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
     var repository = new PublishersRepository(mockContext.Object);
     var publishers = repository.Get(1);
     publishers.ApiDetailUrl = "/TEST";
     // Act
     repository.Update(publishers);
     // Assert
     mockContext.Verify(x => x.SetModified(It.IsAny<object>()), Times.Once);
 }
 public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
 {
     // Arrange
     Mock<IDbSet<Publisher>> mockSetPublishers;
     var mockContext = PublishersMockingSetup.DoMockingSetupForContext(true, out mockSetPublishers);
     var repository = new PublishersRepository(mockContext.Object);
     var publishers = repository.Get(1);
     // Act
     repository.Remove(publishers);
     // Assert
     mockSetPublishers.Verify(x => x.Remove((Publisher)publishers), Times.Once);
 }