public void Should_add_new_author()
        {
            var newAuthor = new Author
            {
                Id   = 2,
                Name = "Jens Lapidus"
            };

            _authorRepository.Create(newAuthor);
            var author = _authorRepository.Find(newAuthor.Id);

            Assert.That(author, Is.EqualTo(author));
        }
Esempio n. 2
0
        public IActionResult Register(User user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }
            try
            {
                if (user.isAuthor)
                {
                    Author author = new Author();
                    author.Name     = user.Name;
                    author.Login    = user.Login;
                    author.Password = user.Password;
                    authorRepository.Create(author);
                }
                else
                {
                    Subscriber subscriber = new Subscriber();
                    subscriber.Name     = user.Name;
                    subscriber.Login    = user.Login;
                    subscriber.Password = user.Password;
                    subscriberRepository.Create(subscriber);
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(View(user));
            }
        }
Esempio n. 3
0
        public void TestIEntityBeanRepository_GetByProperty_ShouldReturnCorrectItems()
        {
            // Arrange
            List <Author> authors = GetAuthors(3, 5);

            AuthorRepository.Create(authors);

            // Act
            List <BookInfo> bookInfoCollection = BookInfoRepository.GetByProperty("Author", Enums.RestrictionTypes.EqualTo, authors[0].FirstName);

            // Assert
            Assert.IsTrue(bookInfoCollection.Count == 5);

            Assert.AreEqual(bookInfoCollection[0].Author, authors[0].FirstName);
            Assert.AreEqual(bookInfoCollection[1].Author, authors[0].FirstName);
            Assert.AreEqual(bookInfoCollection[2].Author, authors[0].FirstName);
            Assert.AreEqual(bookInfoCollection[3].Author, authors[0].FirstName);
            Assert.AreEqual(bookInfoCollection[4].Author, authors[0].FirstName);

            Assert.AreEqual(bookInfoCollection[0].Title, authors[0].Books[0].Title);
            Assert.AreEqual(bookInfoCollection[1].Title, authors[0].Books[1].Title);
            Assert.AreEqual(bookInfoCollection[2].Title, authors[0].Books[2].Title);
            Assert.AreEqual(bookInfoCollection[3].Title, authors[0].Books[3].Title);
            Assert.AreEqual(bookInfoCollection[4].Title, authors[0].Books[4].Title);
        }
Esempio n. 4
0
        private void addAuthorLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            AddAuthorForm addAuthorForm = new AddAuthorForm();
            DialogResult  dialogResult  = addAuthorForm.ShowDialog(this);

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }

            string   name       = addAuthorForm.nameTextBox.Text;
            string   surname    = addAuthorForm.surnameTextBox.Text;
            string   patronymic = addAuthorForm.patronymicTextBox.Text;
            DateTime DoB        = addAuthorForm.dateTimePicker.Value;

            Author author = new Author
            {
                Name        = name,
                Surname     = surname,
                Patronymic  = patronymic,
                DateOfBirth = DoB
            };

            AuthorRepository readerRepository = new AuthorRepository();

            readerRepository.Create(author);

            _db.SaveChanges();
            takeData();
        }
Esempio n. 5
0
        public void TestIEntityBeanRepository_GetAll_ShouldReturnCorrectItems()
        {
            // Arrange
            Author author = GetAuthors(1, 5)[0];

            AuthorRepository.Create(author);

            // Act
            List <BookInfo> bookInfoCollection = BookInfoRepository.GetAll();

            // Assert
            Assert.IsTrue(bookInfoCollection.Count == 5);

            Assert.AreEqual(bookInfoCollection[0].Author, author.FirstName);
            Assert.AreEqual(bookInfoCollection[1].Author, author.FirstName);
            Assert.AreEqual(bookInfoCollection[2].Author, author.FirstName);
            Assert.AreEqual(bookInfoCollection[3].Author, author.FirstName);
            Assert.AreEqual(bookInfoCollection[4].Author, author.FirstName);

            Assert.AreEqual(bookInfoCollection[0].Title, author.Books[0].Title);
            Assert.AreEqual(bookInfoCollection[1].Title, author.Books[1].Title);
            Assert.AreEqual(bookInfoCollection[2].Title, author.Books[2].Title);
            Assert.AreEqual(bookInfoCollection[3].Title, author.Books[3].Title);
            Assert.AreEqual(bookInfoCollection[4].Title, author.Books[4].Title);
        }
Esempio n. 6
0
        public async Task <int> Create(CreateAuthorViewModel item)
        {
            var createdItem   = Mapper.Map <CreateAuthorViewModel, Author>(item);
            int createdItemId = await _authorRepository.Create(createdItem);

            var books = Mapper.Map <ICollection <BookCreateAuthorViewModelItem>, List <Book> >(item.Books);
            await _authorInBookRepository.AddBooksByAuthorId(createdItemId, books);

            return(createdItemId);
        }
Esempio n. 7
0
        public ActionResult Create([Bind(Include = "Id,Name,Gender,Birthdate,IsDeleted")] Author author)
        {
            if (ModelState.IsValid)
            {
                _authorRepo.Create(Mapper.Map <AuthorBusiness>(author));
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
Esempio n. 8
0
        public void AddAuthor(AuthorViewModel avm)
        {
            Author author = new Author
            {
                Name    = avm.Name,
                Surname = avm.Surname
            };

            _authorRepository.Create(author);
        }
Esempio n. 9
0
        public async void CreateReadDelete()
        {
            var testAuthor = new AuthorDto
            {
                Author = DateTime.Now.Ticks.ToString()
            };

            var createTest = await Sut.Create(new[] { testAuthor });

            Assert.Equal(1, createTest);

            var test = await Sut.Read(new[] { testAuthor.Author });

            Assert.NotNull(test);
            Assert.IsAssignableFrom <IEnumerable <AuthorDto> >(test);

            var deleteTest = await Sut.Delete(new[] { test.FirstOrDefault().Id ?? 0 });

            Assert.Equal(1, deleteTest);
        }
Esempio n. 10
0
        public ActionResult Create(Author author)
        {
            if (ModelState.IsValid)
            {
                authorRepository.Create(author);
                return(RedirectToAction("Index"));
            }


            return(View(author));
        }
        public ActionResult Create(CreateAuthorViewModel model)
        {
            Author author = new Author
            {
                Name = model.Name
            };

            authorRepository.Create(author);

            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Gender,Birthdate")] Author author)
        {
            if (ModelState.IsValid)
            {
                author.isDeleted = false;
                _authorRepo.Create(MappingWeb.ConvertToBusinessEntity(author));
                //_authorRepo.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
        public void TestIRepository_GetByProperty_SingleParentEntity_RestrictionOnChildEntity_SingleRestriction_NoMatchExpected()
        {
            // Arrange
            Author author = GetAuthors(1, 5)[0];

            //Act
            AuthorRepository.Create(author);
            List <Book> bookReadResult = BookRepository.GetByProperty("Title", Enums.RestrictionTypes.EqualTo, "Something that doesn't exist");

            // Assert
            Assert.IsTrue(bookReadResult.Count == 0);
        }
        public void TestIRepository_GetByProperty_SingleParentEntity_RestrictionOnParentEntity_SingleRestriction_MatchExpected()
        {
            // Arrange
            Author author = GetAuthors(1, 2, 3)[0];

            //Act
            AuthorRepository.Create(author);
            Author authorReadResult = AuthorRepository.GetByProperty("FirstName", Enums.RestrictionTypes.EqualTo, author.FirstName)[0];

            // Assert
            Assert.IsTrue(AuthorsAreEqual(authorReadResult, author));
        }
        public void TestIRepository_GetByProperty_SingleParentEntity_RestrictionOnChildEntity_SingleRestriction_MatchExpected()
        {
            // Arrange
            Author author = GetAuthors(1, 5)[0];

            //Act
            AuthorRepository.Create(author);
            List <Book> bookReadResult = BookRepository.GetByProperty("Title", Enums.RestrictionTypes.EqualTo, author.Books[0].Title);

            // Assert
            Assert.IsTrue(bookReadResult.Count == 1);
            Assert.IsTrue(BooksAreEqual(bookReadResult[0], author.Books[0]));
        }
Esempio n. 16
0
        public void Create(AuthorViewModel authorViewModel)
        {
            authorViewModel.Id = Guid.NewGuid();
            Author author = new Author
            {
                Id          = authorViewModel.Id,
                FirstName   = authorViewModel.FirstName,
                LastName    = authorViewModel.LastName,
                Patronymic  = authorViewModel.Patronymic,
                Abbreviated = GenerateAbbreviated(authorViewModel)
            };

            _authorRepository.Create(author);
        }
Esempio n. 17
0
        private void btnInsertar_Click(object sender, EventArgs e)
        {
            Author author = new Author()
            {
                au_fname = "Juan",
                au_lname = "Perez",
                au_id    = "22-1242-323",
                phone    = "415-444-2122",
                contract = true
            };

            int result = AuthorRepository.Create(author);

            MostrarAuthors();
        }
Esempio n. 18
0
        public ActionResult Create(AuthorModels author)
        {
            try
            {
                using (var repo = new AuthorRepository())
                {
                    repo.Create(author);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 19
0
        public async Task CreateAuthor_ReturnsCreatedAuthor()
        {
            // Arrange
            var databaseName = Guid.NewGuid().ToString();
            var context      = BuildContext(databaseName);

            var newAuthor = CreateFakeAuthor("John", "Testman1");

            // Act
            var repo   = new AuthorRepository(context);
            var author = await repo.Create(newAuthor);

            // Assert
            Assert.NotNull(author);
            Assert.IsType <Author>(author);
            Assert.Equal("Testman1", author.LastName);
        }
        public void TestIRepository_Create_SingleParentEntity()
        {
            // Arrange
            int authorsToInsert = 1;
            int booksPerAuthor  = 20;
            int reviewsPerBook  = 2;

            List <Author> authors = new List <Author>(GetAuthors(authorsToInsert, booksPerAuthor, reviewsPerBook));

            // Act
            AuthorRepository.Create(authors);
            List <Author> createdAuthors = AuthorRepository.GetAll();
            List <Book>   createdBooks   = BookRepository.GetAll();
            List <Review> createdReviews = ReviewRepository.GetAll();

            // Assert
            Assert.AreEqual(authorsToInsert, createdAuthors.Count);
            Assert.AreEqual(authorsToInsert * booksPerAuthor, createdBooks.Count);
            Assert.AreEqual(authorsToInsert * booksPerAuthor * reviewsPerBook, createdReviews.Count);
        }
        public void Create_WhenCalled_ShouldAddAuthorToDatabase()
        {
            // Arrange
            var author = new Author
            {
                Books       = new List <Book>(),
                DateOfBirth = new DateTimeOffset(),
                FirstName   = "John",
                LastName    = "Smith",
                Genre       = "Adventure"
            };
            var numberOfAuthorsBeforeChanges = _context.Authors.Count();

            // Act
            var id = _authorRepository.Create(author);

            _unitOfWork.Complete();

            // Assert
            var result = _context.Authors.ToList();

            Assert.That(result, Has.Count.EqualTo(numberOfAuthorsBeforeChanges + 1));
            Assert.AreNotEqual(new Guid(), id);
        }
Esempio n. 22
0
 public void Create(AuthorDTO dto)
 {
     repository.Create(mapper.Map <Author>(dto));
 }
Esempio n. 23
0
 // POST api/<controller>
 public int Post([FromBody] Author value)
 {
     authorRepository.Create(value);
     return(value.Id);
 }
Esempio n. 24
0
        public void Create(AuthorViewModel authorViewModel)
        {
            var author = Mapper.Map <AuthorViewModel, Author>(authorViewModel);

            _authorRepository.Create(author);
        }
Esempio n. 25
0
 public void CreateAuthor(Author author)
 {
     _authorRepository.Create(author);
 }
        public /*async*/ void Create(GetAuthorView authorView)
        {
            var authors = Mapper.Map <GetAuthorView, Author>(authorView);

            /*await*/ authorsRepository.Create(authors);
        }