public void ShouldDeleteANote()
        {
            // Arrange
            const string id = "id";
            var note = new NoteWithCategories { Id = id, Message = "Message" };

            // Depedent-On Component
            var session = Substitute.For<IDocumentSession>();
            session.Load<NoteWithCategories>(id).Returns(note);

            // System under Test
            var repository = new RavenDbRepository(session);

            // Act
            repository.Delete(id);

            // Assert / Indirect Output
            session.Received().Delete(Arg.Is(note));
            session.Received().SaveChanges();
        }
        public void CreateACollectionWithSomeData()
        {
            CreateCollectionIfNecessary(database);

            MongoCollection<Note> notes = database.GetCollection<Note>(CollectionName);

            // Let's create a couple of documents!
            var note = new Note
                           {
                               Title = "MongoDB is fun for developers!",
                               Message = "With Mongo Documents, there is hardly any need for excessive OR Mapping, since documents resemble objects closer that relations do!"
                           };

            var note2 = new Note
                            {
                                Title = "Hello",
                                Message = "Welcome to MongoDB!"
                            };

            var noteWithCategories = new NoteWithCategories
                                         {
                                             Title = "RavenDb",
                                             Message = "RavenDb is also pretty cool, too!",
                                             Categories = new[] { new Category { Name = "Very Important" } }
                                         };

            // Insert
            notes.Insert(note);
            notes.Insert(note2);
            notes.Insert(noteWithCategories);

            // Let's find them
            List<Note> allNotes = notes.FindAllAs<Note>().ToList();
            Assert.That(allNotes.Count, Is.EqualTo(3));

            // You can also marshal them as the subclass, but for this example only one will have the cargories set!
            List<NoteWithCategories> allNotesWithcategories = notes.FindAllAs<NoteWithCategories>().ToList();
            Assert.That(allNotesWithcategories.Count, Is.EqualTo(3));
            Assert.That(allNotesWithcategories.Count(n => n.Categories != null && n.Categories.Any()), Is.EqualTo(1));
        }
        public void ShouldReadOne()
        {
            // Arrange
            const string id = "Id";
            var expectedNote = new NoteWithCategories { Id = id, Message = "Message" };

            // Depedent-On Component
            var session = Substitute.For<IDocumentSession>();

            // Indirect Input
            session.Load<NoteWithCategories>(Arg.Is(id)).Returns(expectedNote);

            // System under Test
            var repository = new RavenDbRepository(session);

            // Act
            NoteWithCategories note = repository.Read(id);

            // Assert
            Assert.That(note.Message, Is.EqualTo(note.Message));
        }
        public void ShouldReadAll()
        {
            // Arrange
            var note = new NoteWithCategories { Message = "Message" };
            var expectedNotes = new List<NoteWithCategories> { note };

            // Depedent-On Component
            var session = Substitute.For<IDocumentSession>();
            var query = Substitute.For<IRavenQueryable<NoteWithCategories>>();

            // Indirect Input
            session.Query<NoteWithCategories>().Returns(query);
            query.GetEnumerator().Returns(expectedNotes.GetEnumerator());

            // System under Test
            var repository = new RavenDbRepository(session);

            // Act
            IEnumerable<NoteWithCategories> notes = repository.ReadAll();

            // Assert
            Assert.That(notes, Is.EquivalentTo(expectedNotes));
            Assert.That(notes.First().Message, Is.EqualTo(note.Message));
        }