Exemple #1
0
        public void Setup_fake_dbset_returns_expected()
        {
            // Arrange
            var entities = new BookStoreEntities();
            var book     = new Book {
                Title = "title"
            };

            // Act
            entities.SetupFakeDbSet(x => x.Books).Add(book);

            // Assert
            Assert.That(entities.Books.Count(), Is.EqualTo(1));
            Assert.That(entities.Books.First().Title, Is.EqualTo("title"));
        }
Exemple #2
0
        public void Setup_fake_dbset_with_add_many_returns_expected()
        {
            // Arrange
            var entities = new BookStoreEntities();
            var book1    = new Book {
                Title = "title 1"
            };
            var book2 = new Book {
                Title = "title 2"
            };

            // Act
            entities.SetupFakeDbSet(x => x.Books).Add(book1, book2);

            // Assert
            Assert.That(entities.Books.Count(), Is.EqualTo(2));
            Assert.That(entities.Books.First().Title, Is.EqualTo("title 1"));
            Assert.That(entities.Books.Last().Title, Is.EqualTo("title 2"));
        }
Exemple #3
0
        public async Task Setup_fake_dbset_async_returns_expected()
        {
            // Arrange
            var entities = new BookStoreEntities();

            var books = new[]
            {
                new Book {
                    Title = "title 1"
                },
                new Book {
                    Title = "title 2"
                }
            };

            // Act
            entities.SetupFakeDbSet(x => x.Books).AddRange(books);

            // Assert
            Assert.That(await entities.Books.CountAsync(), Is.EqualTo(2));
            Assert.That((await entities.Books.FirstAsync()).Title, Is.EqualTo("title 1"));
            Assert.That(await entities.Books.ToListAsync(), Is.EquivalentTo(books));
        }