Example #1
0
        public IEnumerable <SeriesDto> Build(int count)
        {
            var seriesList = new List <SeriesDto>();
            var fixture    = new Fixture();

            for (int i = 0; i < count; i++)
            {
                var author = fixture.Build <AuthorDto>()
                             .With(a => a.LibraryId, _libraryId)
                             .Without(a => a.ImageId)
                             .Create();

                _connection.AddAuthor(author);
                _authors.Add(author);

                FileDto seriesImage = null;
                if (_withImage)
                {
                    seriesImage = fixture.Build <FileDto>()
                                  .With(a => a.FilePath, Helpers.RandomData.BlobUrl)
                                  .With(a => a.IsPublic, true)
                                  .Create();
                    _connection.AddFile(seriesImage);

                    _files.Add(seriesImage);
                    _fileStorage.SetupFileContents(seriesImage.FilePath, Helpers.RandomData.Bytes);
                    _connection.AddFile(seriesImage);
                }

                var series = fixture.Build <SeriesDto>()
                             .With(a => a.Name, () => fixture.Create(_namePattern))
                             .With(s => s.LibraryId, _libraryId)
                             .With(a => a.ImageId, seriesImage?.Id)
                             .Create();

                _connection.AddSeries(series);
                seriesList.Add(series);

                var books = fixture.Build <BookDto>()
                            .With(b => b.LibraryId, _libraryId)
                            .With(b => b.Language, RandomData.Locale)
                            .Without(b => b.ImageId)
                            .With(b => b.SeriesId, series.Id)
                            .CreateMany(_bookCount);
                _books.AddRange(books);
                _connection.AddBooks(books);
                _connection.AddBooksAuthor(books.Select(b => b.Id), author.Id);
            }

            _series.AddRange(seriesList);
            return(seriesList);
        }
Example #2
0
        public IEnumerable <AuthorDto> Build(int count)
        {
            var fixture = new Fixture();

            var authors = new List <AuthorDto>();

            for (int i = 0; i < count; i++)
            {
                FileDto authorImage = null;
                if (_withImage)
                {
                    authorImage = fixture.Build <FileDto>()
                                  .With(a => a.FilePath, Helpers.RandomData.BlobUrl)
                                  .With(a => a.IsPublic, true)
                                  .Create();
                    _connection.AddFile(authorImage);

                    _files.Add(authorImage);
                    _fileStorage.SetupFileContents(authorImage.FilePath, Helpers.RandomData.Bytes);
                    _connection.AddFile(authorImage);
                }

                var author = fixture.Build <AuthorDto>()
                             .With(a => a.Name, () => fixture.Create(_namePattern))
                             //.With(a => a.Name, Random.Name)
                             .With(a => a.LibraryId, _libraryId)
                             .With(a => a.ImageId, authorImage?.Id)
                             .Create();

                _connection.AddAuthor(author);
                _authors.Add(author);

                var books = fixture.Build <BookDto>()
                            .With(b => b.LibraryId, _libraryId)
                            .With(b => b.Language, RandomData.Locale)
                            .With(b => b.Status, Domain.Models.BookStatuses.Published)
                            .Without(b => b.ImageId)
                            .Without(b => b.SeriesId)
                            .CreateMany(_bookCount);
                _connection.AddBooks(books);

                _connection.AddBooksAuthor(books.Select(b => b.Id), author.Id);

                _books.AddRange(books);

                authors.Add(author);
            }

            return(authors);
        }
Example #3
0
        public IEnumerable <CategoryDto> Build(int count)
        {
            var fixture = new Fixture();

            var cats = fixture.Build <CategoryDto>()
                       .With(c => c.LibraryId, _libraryId)
                       .CreateMany(count);

            _connection.AddCategories(cats);
            _categories.AddRange(cats);

            foreach (var cat in cats)
            {
                var author = fixture.Build <AuthorDto>()
                             .With(a => a.LibraryId, _libraryId)
                             .Without(a => a.ImageId)
                             .Create();

                _connection.AddAuthor(author);
                _authors.Add(author);

                var books = fixture.Build <BookDto>()
                            .With(b => b.LibraryId, _libraryId)
                            .With(b => b.Language, RandomData.Locale)
                            .Without(b => b.ImageId)
                            .Without(b => b.SeriesId)
                            .CreateMany(_bookCount);
                _connection.AddBooks(books);

                _connection.AddBooksAuthor(books.Select(b => b.Id), author.Id);

                _connection.AddBooksToCategory(books, cat);
            }

            return(cats);
        }