Beispiel #1
0
        public void AddAuthor_WhenCalledWithInvalidData_ShouldThrowException()
        {
            // Arrange
            var author = new AuthorDto
            {
                FirstName = "Only completed field"
            };

            // Act / Assert
            Assert.Throws <InvalidDataException>(
                () => _authorService.AddAuthor(author));
        }
Beispiel #2
0
        private void AddAuthorBtn_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;

            authorService.AddAuthor(name);
            textBox1.Clear();
        }
        public void AddAuthorEffort()
        {
            // Arrange
            var effortContext = new BookRankingDbContext(Effort.DbConnectionFactory.CreateTransient());
            var mockMapper    = new Mock <IMapper>();

            var authorToReturn = new Author
            {
                FirstName = "Zaio",
                LastName  = "Baio",
                Alias     = "NUPogodi"
            };

            mockMapper.Setup(x => x.Map <Author>(It.IsAny <AuthorDTO>())).Returns(authorToReturn);

            var service = new AuthorService(effortContext, mockMapper.Object);

            // Act
            var authorToAdd = new AuthorDTO("Zaio", "Baio", "NUPogodi");

            service.AddAuthor(authorToAdd);

            // Assert
            Assert.AreEqual(1, effortContext.Authors.Count());
        }
Beispiel #4
0
        public void AddAuthor_AddAuthorToEmptyList_CountNrOne()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MDLibrary_AddAuthor")
                          .Options;

            var context = new ApplicationDbContext(options);

            var testAuthorService = new AuthorService(context);

            var testAuthor = new Author()
            {
                ID   = 1,
                Name = "Test Testsson"
            };
            var expectedResult = 1;

            //Act
            testAuthorService.AddAuthor(testAuthor);

            //Assert
            var actualResult = context.Author.ToList().Count;

            //Arrange
            Assert.Equal(expectedResult, actualResult);
        }
        public IActionResult AddAuthor(AuthorInputModel author)
        {
            if (ModelState.IsValid)
            {
                _authorService.AddAuthor(author);
            }

            return(RedirectToAction("AddAuthor"));
        }
Beispiel #6
0
        public void Create(string models)
        {
            List <AuthorViewModel> authors = JsonConvert.DeserializeObject <List <AuthorViewModel> >(models);

            foreach (AuthorViewModel avm in authors)
            {
                _authorService.AddAuthor(new AuthorViewModel {
                    Name = avm.Name, Surname = avm.Surname
                });
            }
        }
Beispiel #7
0
        public ActionResult Create(AuthorViewModel authorViewModel)
        {
            try
            {
                _authorService.AddAuthor(authorViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #8
0
        private void AddAuthor_Btn_Click(object sender, EventArgs e)
        {
            var name = AddAuthorName_textbox.Text;

            if (CheckInput(name))
            {
                var author = new Author {
                    Name = name
                };
                _authorService.AddAuthor(author);
                AddAuthorName_textbox.Clear();
            }
        }
 public ActionResult AddAuthor(AuthorModel Author)
 {
     try
     {
         _authorService.AddAuthor(Author);
         _authorService.Save();
         ModelState.Clear();
         ViewData["Message"] = "1";
     }
     catch
     {
         ViewData["Message"] = "0";
     }
     return(RedirectToAction("CreateAuthor", "AdminAuthor"));
 }
 public ActionResult AddAuthor(AuthorModel Author)
 {
     try
     {
         _authorService.AddAuthor(Author);
         _authorService.Save();
         ModelState.Clear();
         ViewData["Message"] = "1";
     }
     catch
     {
         ViewData["Message"] = "0";
     }
     return(View());
 }
Beispiel #11
0
        private void msp_file_add_author_Click(object sender, EventArgs e)
        {
            AuthorForm form = new AuthorForm();

            try
            {
                if (DialogResult.OK == form.ShowDialog())
                {
                    authorService.AddAuthor(form.author);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #12
0
        public IActionResult AddAuthor(Author author)
        {
            if (author == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            authorService.AddAuthor(author);

            return(Ok(author));
        }
Beispiel #13
0
        private static void FillDbUsingJsonFiles(BookRankingDbContext context, AuthorService authorService, PublisherService publisherService, BookService bookService)
        {
            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    var settings = new JsonSerializerSettings();
                    settings.TypeNameHandling = TypeNameHandling.Auto;

                    var file       = File.ReadAllText("publishers.json");
                    var publishers = ((JArray)JsonConvert.DeserializeObject(file, settings)).ToObject <List <PublisherDTO> >();

                    foreach (var publisher in publishers)
                    {
                        publisherService.AddPublisher(publisher);
                    }

                    file = File.ReadAllText("authors.json");
                    var authors = ((JArray)JsonConvert.DeserializeObject(file, settings)).ToObject <List <AuthorDTO> >();

                    foreach (var author in authors)
                    {
                        authorService.AddAuthor(author);
                    }

                    file = File.ReadAllText("book.json");
                    var books = ((JArray)JsonConvert.DeserializeObject(file, settings)).ToObject <List <BookDTO> >();

                    foreach (var book in books)
                    {
                        bookService.AddBook(book);
                    }

                    context.SaveChanges();

                    dbContextTransaction.Commit();
                }
                catch (Exception e)
                {
                    dbContextTransaction.Rollback();
                }
            }
        }
Beispiel #14
0
        public async Task AddAuthor_ValidAuthor_ShouldAddNewAuthor()
        {
            using (var context = _factory.UseInMemory())
            {
                // Arrange
                var service = new AuthorService(context);

                // Act
                var author   = GetAuthor();
                var expected = await service.AddAuthor(author);

                var actual = author;

                // Assert
                Assert.Equal(expected.FirstName, actual.FirstName);
                Assert.Equal(expected.LastName, actual.LastName);
                Assert.Equal(expected.Id, actual.Id);
            }
        }
        public void AddAuthor()
        {
            // Arrange
            //var context = new BookRankingDbContext(DbConnectionFactory.CreateTransient());
            var context       = new Mock <IBookRankingDbContext>();
            var mockMapper    = new Mock <IMapper>();
            var authorDTOMock = new Mock <AuthorDTO>();
            var authorMock    = new Mock <Author>();

            mockMapper.Setup(m => m.Map <Author>(authorDTOMock.Object)).Returns(authorMock.Object);
            var authors = new FakeDbSet <Author>();

            context.Setup(c => c.Authors).Returns(authors);

            var service = new AuthorService(context.Object, mockMapper.Object);

            // Act
            service.AddAuthor(authorDTOMock.Object);

            // Assert
            Assert.IsTrue(context.Object.Authors.Contains(authorMock.Object));
        }
 public ResultModel Add([FromBody] Author request)
 {
     if (request != null)
     {
         try
         {
             ResultModel result = AuthorService.AddAuthor(request);
             return(result);
         }
         catch (Exception ex)
         {
             return(new ResultModel {
                 Data = null, Status = ResultStatus.ServerInternalError, Message = "Hata oluştu"
             });
         }
     }
     else
     {
         return new ResultModel {
                    Data = null, Status = ResultStatus.BadRequest, Message = "Geçersiz değer"
         }
     };
 }
Beispiel #17
0
        private void AddAuthorBtn_Click(object sender, EventArgs e)
        {
            string authorName = AuthorComboBox.SelectedItem.ToString();

            authorService.AddAuthor(authorName);
        }
 public ActionResult AddAuthor(AuthorViewModel authorViewModel)
 {
     _authorService.AddAuthor(authorViewModel);
     return(Json(authorViewModel));
 }
Beispiel #19
0
 public IActionResult AddAuthor([FromBody] AuthorViewModel author)
 {
     _authorService.AddAuthor(author);
     return(Created(nameof(author), author));
 }
 public IActionResult AddAuthor([FromBody] AuthorViewModel _author)
 {
     _authorService.AddAuthor(_author);
     return(Ok());
 }
Beispiel #21
0
 public IActionResult AddAuthor([FromBody] AuthorDTO authorDTO)
 {
     _authorService.AddAuthor(authorDTO);
     return(Ok());
 }
Beispiel #22
0
 public IActionResult AddBook([FromBody] AuthorVM author)
 {
     _authorService.AddAuthor(author);
     return(Ok());
 }
 public IActionResult AddAuthor(AuthorInputModel input)
 {
     authorService.AddAuthor(input);
     return(Ok());
 }