Exemplo n.º 1
0
        public void GetPosts_WithNewPostAndEagerLoadedTag_ReturnsPostWithTheSameTag(
            Post post,
            Tag tag,
            string databaseName)
        {
            // Given
            post.Tags.Add(tag);
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();
            var result = sut.Get<Post>("Tags").SingleOrDefault();

            // Then
            Assert.True(post.Tags.SequenceEqual(result.Tags));
            sut.Database.Delete();
            sut.Dispose();
        }
Exemplo n.º 2
0
        public void RegisterModified_WithModifiedPost_PersistsPost(
            string databaseName,
            Post post,
            string modifiedValue)
        {
            // Given
            var sut = new DataContext(databaseName);
            sut.RegisterAdded(post);
            sut.Commit();

            // When
            post.Title = modifiedValue;
            sut.RegisterModified(post);
            sut.Commit();
            var result = sut.Get<Post>().FirstOrDefault();

            // Then
            Assert.Equal(post, result);
            sut.Database.Delete();
            sut.Dispose();
        }
Exemplo n.º 3
0
        public void RegisterDeleted_WithPost_RemovesPost(
            string databaseName,
            Post post)
        {
            // Given
            var sut = new DataContext(databaseName);
            sut.RegisterAdded(post);
            sut.Commit();

            // When
            sut.RegisterDeleted(post);
            sut.Commit();
            var result = sut.Get<Post>().Any();

            // Then
            Assert.False(result);
            sut.Database.Delete();
            sut.Dispose();
        }
Exemplo n.º 4
0
        public void RegisterAdded_WithNullPost_ThrowsArgumentNullException(string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // Then
            Assert.Throws<ArgumentNullException>(() => sut.RegisterAdded<Post>(null));
            sut.Database.Delete();
            sut.Dispose();
        }
Exemplo n.º 5
0
        public void GetPosts_WithNewPost_ReturnsCollectionWithOneElement(
            Post post,
            string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();
            var result = sut.Get<Post>();

            // Then
            Assert.Equal(1, result.Count());
            sut.Database.Delete();
            sut.Dispose();
        }
Exemplo n.º 6
0
        public void GetPosts_WithNewPostAndNonExistentEagerLoadedProperty_Throws(
            Post post,
            string propertyName,
            string databaseName)
        {
            // Given
            var sut = new DataContext(databaseName);

            // When
            sut.RegisterAdded(post);
            sut.SaveChanges();

            // Then
            Assert.Throws<InvalidOperationException>(() => sut.Get<Post>(propertyName).Any());
            sut.Database.Delete();
            sut.Dispose();
        }