Exemplo n.º 1
0
        public void ShouldKnowHowToDeleteAModelByItsIdWhenItExists()
        {
            var persistedModel = new StaticPage { Title = "Nandos Rocks", Id = 1337, Content = "Nandos makes chicken. You're going to love it." };
            var documentSession = new Mock<IDocumentSession>();
            documentSession.Setup(session => session.Load<StaticPage>(persistedModel.Id)).Returns(persistedModel);
            var repository = new BookWorm.Repository.Repository(documentSession.Object);

            repository.Delete<StaticPage>(persistedModel.Id);
            documentSession.Verify(session => session.Delete(persistedModel), Times.Once());
        }
Exemplo n.º 2
0
        public void EditingNonExistentDocumentShouldRethrowInvalidOperationException()
        {
            var persistedModel = new StaticPage { Title = "Nandos Rocks", Id = 1337, Content = "Nandos makes veggie burger. You're going to love it." };
            var documentSession = new Mock<IDocumentSession>();
            documentSession.Setup(session => session.Load<StaticPage>(persistedModel.Id)).Returns(persistedModel);
            documentSession.Setup(session => session.Store(persistedModel))
                           .Throws(new System.InvalidOperationException());

            var repository = new BookWorm.Repository.Repository(documentSession.Object);
            repository.Edit<StaticPage>(persistedModel);
        }
Exemplo n.º 3
0
        public void ListShouldReturnAllPersistedDocumentsOfTheSpecifiedType()
        {
            var books = CreateTenBooks();

            using (var session = _documentStore.OpenSession())
            {
                var repo = new BookWorm.Repository.Repository(session);
                var retrievedBooks = repo.List<Book>();

                Assert.AreEqual(books.Count, retrievedBooks.Count);
            }
        }
Exemplo n.º 4
0
        public void ShouldKnowHowToGetModelFromTheirId()
        {
            var persistedModel = new StaticPage {Title = "Nandos Rocks", Id = 1337, Content = "Nandos makes chicken. You're going to love it."};
            var documentSession = new Mock<IDocumentSession>();

            documentSession.Setup(session => session.Load<StaticPage>(persistedModel.Id)).Returns(persistedModel);
            var repository = new BookWorm.Repository.Repository(documentSession.Object);
            var retrievedModel = repository.Get<StaticPage>(persistedModel.Id);

            documentSession.Verify(session=>session.Load<StaticPage>(persistedModel.Id), Times.Once());
            Assert.AreEqual(persistedModel.Id , retrievedModel.Id);
        }
Exemplo n.º 5
0
        public void ShouldKnowThatCreatedModelIsAssignedAnId()
        {
            var testModel = new StaticPage();
            var documentSession = new Mock<IDocumentSession>();

            documentSession.Setup(session => session.Store(testModel)).Callback<object>(arg => testModel.Id = 1);

            var repository = new BookWorm.Repository.Repository(documentSession.Object);
            repository.Create(testModel);

            documentSession.Verify(session => session.Store(testModel), Times.Once());
            Assert.AreNotEqual(0, testModel.Id);
        }
Exemplo n.º 6
0
        public void ShouldRethrowRavenNonUniqueObjectException()
        {
            var testModel = new StaticPage();
            var documentSession = new Mock<IDocumentSession>();

            documentSession.Setup(session => session.Store(testModel))
                           .Throws(new Raven.Client.Exceptions.NonUniqueObjectException());

            var repository = new BookWorm.Repository.Repository(documentSession.Object);
            repository.Create(testModel);
        }
Exemplo n.º 7
0
        public void ShouldKnowToTalkToSessionToSaveChanges()
        {
            var documentSession = new Mock<IDocumentSession>();
            var documentStore = new Mock<IDocumentStore>();
            documentStore.Setup(store => store.OpenSession()).Returns(documentSession.Object);

            var repo = new BookWorm.Repository.Repository(documentSession.Object);

            repo.SaveChanges();

            documentSession.Verify(session => session.SaveChanges(), Times.Once());
        }