public async Task UpdateBookById_OK()
        {
            //Arrange

            var entity = Create <BookEntity>(x =>
            {
                x.BookId     = 101;
                x.BookAuthor = "Priya";
                x.BookName   = "DC";
                x.BookType   = "2";
            });

            var book = new BookDomain()
            {
                BookId = 101,
            };

            //Act
            using (var _context = new LibraryContextMemory(_configuration))
            {
                var libraryRepository = new LibraryRepository(_context);
                var result            = await libraryRepository.UpdateBookById(book);

                // Assert
                result.Should().NotBeNull("Must contain a result");
                result.BookId.Equals(101);
            }
        }
        public async Task GetAllBook_OK()
        {
            //Arrange

            //Act
            using (var _context = new LibraryContextMemory(_configuration))
            {
                var libraryRepository = new LibraryRepository(_context);
                var result            = await libraryRepository.GetBookList();

                // Assert
                result.Should().NotBeNull("Must contain a result");
            }
        }
        public async Task DeleteBookById_OK()
        {
            //Arrange
            var entity = Create <BookEntity>(x =>
            {
                x.BookId = Math.Abs(Guid.NewGuid().GetHashCode());
            });

            //Act
            using (var _context = new LibraryContextMemory(_configuration))
            {
                var libraryRepository = new LibraryRepository(_context);
                var result            = await libraryRepository.DeleteBookById(entity.BookId);

                // Assert
                result.Should().NotBeNull("Must contain a result");
                result.BookId.Equals(110);
            }
        }
示例#4
0
        protected T Create <T>(T obj) where T : class, new()
        {
            using (var context = new LibraryContextMemory(_configuration))
            {
                context.Add <T>(obj);
                context.SaveChanges();
            }

            if (CreatedEntities.ContainsKey(typeof(T).Name))
            {
                var value = CreatedEntities[typeof(T).Name];
                value.Add(obj);
            }
            else
            {
                CreatedEntities.Add(typeof(T).Name, new List <object> {
                    obj
                });
            }
            return(obj);
        }
        public async Task AddNewBook_OK()
        {
            //Arrange
            BookDomain books = new BookDomain();

            var entity = Create <BookDomain>(new BookDomain
            {
                BookId     = 101,
                BookAuthor = "Rahul",
                BookName   = "c#",
                BookType   = "1",
            });

            //Act
            using (var _context = new LibraryContextMemory(_configuration))
            {
                var libraryRepository = new LibraryRepository(_context);
                var result            = await libraryRepository.AddNewBook(entity);

                // Assert
                result.Should().NotBeNull("Must contain a result");
            }
        }
示例#6
0
        protected virtual T Create <T>(Action <T> predicate = null) where T : class, new()
        {
            var obj = new T();

            predicate?.Invoke(obj);
            using (LibraryContextMemory context = new LibraryContextMemory(_configuration))
            {
                context.Add <T>(obj);
                context.SaveChanges();
            }

            if (CreatedEntities.ContainsKey(typeof(T).Name))
            {
                var value = CreatedEntities[typeof(T).Name];
                value.Add(obj);
            }
            else
            {
                CreatedEntities.Add(typeof(T).Name, new List <object> {
                    obj
                });
            }
            return(obj);
        }