コード例 #1
0
        public void AddCharacterWithDuplicateNameTest()
        {
            var dbHelper = DbHelperCollection.Take();

            var books = new List <Book>
            {
                new Book {
                    Path = @"c:\test.txt"
                },
                new Book {
                    Path = @"c:\test2.txt"
                }
            };

            var characters = new List <Character>
            {
                new Character {
                    Book = books[0], Name = @"test name1"
                },
                new Character {
                    Book = books[0], Name = @"test name1"
                }
            };

            dbHelper.Db.Books.AddRange(books);
            dbHelper.Db.Characters.AddRange(characters);

            Assert.ThrowsAsync <DbUpdateException>(async() => await dbHelper.Db.SaveChangesAsync());

            Cleanup(dbHelper);
        }
コード例 #2
0
        public void AddTagDuplicateTest()
        {
            var dbHelper = DbHelperCollection.Take();
            var db       = dbHelper.Db;

            var book = new Book()
            {
                Path = @"c:\test.txt"
            };

            List <Tag> Tags = new List <Tag>()
            {
                new Tag()
                {
                    Name = "My Tag", Book = book
                },
                new Tag()
                {
                    Name = "My Tag", Book = book
                }
            };

            db.Books.Add(book);
            db.Tags.AddRange(Tags);

            Assert.ThrowsAsync <DbUpdateException>(async() => await dbHelper.Db.SaveChangesAsync());

            Cleanup(dbHelper);
        }
コード例 #3
0
        public async Task AddSameCharacterTwoBooksTest()
        {
            var dbHelper = DbHelperCollection.Take();

            var books = new Book[] { new Book()
                                     {
                                         Name = "My Book", Path = @"c:\myFile.txt"
                                     },
                                     new Book()
                                     {
                                         Name = "My Book Again", Path = @"c:\myFile2.txt"
                                     } };

            var characters = new Character[] { new Character()
                                               {
                                                   Book = books[0], Name = "George Washington"
                                               },
                                               new Character()
                                               {
                                                   Book = books[1], Name = "George Washington"
                                               } };

            dbHelper.Db.Books.AddRange(books);
            dbHelper.Db.Characters.AddRange(characters);

            await dbHelper.Db.SaveChangesAsync();

            Cleanup(dbHelper);
        }
コード例 #4
0
        public void AddInvalidBookTest()
        {
            var dbHelper = DbHelperCollection.Take();
            var db       = dbHelper.Db;

            var book = new Book();

            db.Books.Add(book);
            Assert.Throws <DbEntityValidationException>(() => db.SaveChangesAsync());

            Cleanup(dbHelper);
        }
コード例 #5
0
        //[Test]
        public async Task AddBookTest()
        {
            var dbHelper    = DbHelperCollection.Take();
            var db          = dbHelper.Db;
            var dataService = new DataService(new Func <ComicReaderDbContext>(() => db), new FileService(), new ZipService(), new ParserService());

            var path = Path.Combine(Assembly.GetExecutingAssembly().Location, "..", "Data", "TestBook.zip");

            Assert.IsTrue(File.Exists(path));
            await dataService.AddBooksAsync(new string[] { path });

            var books = await dataService.GetAllBooksAsync();

            Cleanup(dbHelper);
        }
コード例 #6
0
        public void AddTagWithoutBookTest()
        {
            var dbHelper = DbHelperCollection.Take();
            var db       = dbHelper.Db;

            var Tag = new Tag()
            {
                Name = "My Tag"
            };

            db.Tags.Add(Tag);

            Assert.ThrowsAsync <DbUpdateException>(async() => await dbHelper.Db.SaveChangesAsync());

            Cleanup(dbHelper);
        }
コード例 #7
0
        public void AddSerieWithoutBookTest()
        {
            var dbHelper = DbHelperCollection.Take();
            var db       = dbHelper.Db;

            var serie = new Serie()
            {
                Name = "My serie"
            };

            db.Series.Add(serie);

            Assert.ThrowsAsync <DbUpdateException>(async() => await dbHelper.Db.SaveChangesAsync());

            Cleanup(dbHelper);
        }
コード例 #8
0
        public void InvalidAddCharacterMissingPathTest()
        {
            var dbHelper = DbHelperCollection.Take();

            dbHelper.Db.Books.Add(new Book()
            {
                Name = "John Smith"
            });

            Assert.ThrowsAsync <DbEntityValidationException>(async() =>
            {
                await dbHelper.Db.SaveChangesAsync();
            });

            Cleanup(dbHelper);
        }
コード例 #9
0
        public async Task AddCharacterTest()
        {
            var dbHelper = DbHelperCollection.Take();

            dbHelper.Db.Books.Add(new Book()
            {
                Name = "My Book", Path = @"c:\myFile.txt"
            });
            dbHelper.Db.Characters.Add(new Character()
            {
                BookId = 0, Name = "George Washington"
            });

            await dbHelper.Db.SaveChangesAsync();

            Cleanup(dbHelper);
        }
コード例 #10
0
        public async Task AddBookTest()
        {
            var dbHelper = DbHelperCollection.Take();
            var db       = dbHelper.Db;

            var book = new Book()
            {
                Path = @"c:\testFile.txt"
            };

            db.Books.Add(book);
            await db.SaveChangesAsync();

            var books = db.Books.ToList();

            Assert.IsNotNull(books);
            CollectionAssert.IsNotEmpty(books);
            Assert.AreEqual(book.Path, books[0].Path);

            Cleanup(dbHelper);
        }
コード例 #11
0
        public async Task AddTagTest()
        {
            var dbHelper = DbHelperCollection.Take();
            var db       = dbHelper.Db;

            var book = new Book()
            {
                Path = @"c:\test.txt"
            };
            var book2 = new Book()
            {
                Path = @"c:\test2.txt"
            };

            List <Tag> Tags = new List <Tag>()
            {
                new Tag()
                {
                    Name = "My Tag", Book = book
                },
                new Tag()
                {
                    Name = "My Tag2", Book = book
                },
                new Tag()
                {
                    Name = "My Tag", Book = book2
                }
            };

            db.Books.Add(book);
            db.Books.Add(book2);
            db.Tags.AddRange(Tags);

            await dbHelper.Db.SaveChangesAsync();

            Cleanup(dbHelper);
        }
コード例 #12
0
        public async Task AddSerieTest()
        {
            var dbHelper = DbHelperCollection.Take();
            var db       = dbHelper.Db;

            var book = new Book()
            {
                Path = @"c:\test.txt"
            };
            var book2 = new Book()
            {
                Path = @"c:\test2.txt"
            };

            List <Serie> series = new List <Serie>()
            {
                new Serie()
                {
                    Name = "My serie", Book = book
                },
                new Serie()
                {
                    Name = "My serie2", Book = book
                },
                new Serie()
                {
                    Name = "My serie", Book = book2
                }
            };

            db.Books.Add(book);
            db.Books.Add(book2);
            db.Series.AddRange(series);

            await dbHelper.Db.SaveChangesAsync();

            Cleanup(dbHelper);
        }