public void AddNewBookSuccess(string isbn, string name, double price)
        {
            var newBook = new Book {
                ISBN = isbn, Name = name
            };

            // Mock the validators
            var mockValidator = new Mock <IValidationService>();

            mockValidator.Setup(x => x.isValidBook(newBook)).Returns(true);
            mockValidator.Setup(x => x.IsValidQuantity(1)).Returns(true);
            mockValidator.Setup(x => x.IsValidPrice(price)).Returns(true);
            var dependencyService = new DependencyService();

            dependencyService.Register <IValidationService>(mockValidator.Object);
            var availableBooks = new List <BookProductInfo>();
            var library        = new LibraryRepository(availableBooks, dependencyService);

            var addResult = library.AddNewBook(newBook, price);

            Assert.True(addResult);
            var addedBook = Assert.Single(library.AvailableBooks);

            Assert.NotNull(addedBook);

            Assert.Equal(isbn, addedBook.Book.ISBN);
            Assert.Equal(name, addedBook.Book.Name);
            Assert.Equal(price, addedBook.BorrowPrice);
        }
        public TagRepositoryTests()
        {
            var libraryRepository = new LibraryRepository();
            var libId             = libraryRepository.CreateLibrary(new CreateLibraryDto("test"));

            library = libraryRepository.GetLibrary(libId);
        }
Example #3
0
        public static List <EPart> SelRootChildList(EPart _param)
        {
            List <EPart> lSelRootChildList = DaoFactory.GetList <EPart>("EBom.SelRootChildList", new EPart {
                Type = EBomConstant.TYPE_PART, FromOID = _param.FromOID
            });

            lSelRootChildList.ForEach(obj =>
            {
                obj.BPolicy = BPolicyRepository.SelBPolicy(new BPolicy {
                    Type = obj.Type, OID = obj.BPolicyOID
                }).First();
                if (obj.Oem_Lib_OID != null)
                {
                    obj.Oem_Lib_NM = LibraryRepository.SelLibraryObject(new Library {
                        OID = obj.Oem_Lib_OID
                    }).KorNm;
                }
                if (obj.Car_Lib_OID != null)
                {
                    obj.Car_Lib_Nm = LibraryRepository.SelLibraryObject(new Library {
                        OID = obj.Car_Lib_OID
                    }).KorNm;
                }
            });

            //var ll = (from l in lSelRootChildList select l).GroupBy(x => x.OID).Select(y => y.First());

            List <EPart> RootChildList = lSelRootChildList.GroupBy(x => x.OID).Select(y => y.First()).ToList();

            //var LinqRootChildList = (from List in lSelRootChildList
            //                         select List).GroupBy(x => x.OID).Select(y => y.First());
            //LinqRootChildList = LinqRootChildList.ToList<EPart>();

            return(RootChildList);
        }
        public void AddNewBookAlreadyExisting(string isbn, string name, double price)
        {
            var newBook = new Book {
                ISBN = isbn, Name = name
            };

            // Mock the validators
            var mockValidator = new Mock <IValidationService>();

            mockValidator.Setup(x => x.isValidBook(newBook)).Returns(true);
            mockValidator.Setup(x => x.IsValidQuantity(1)).Returns(true);
            mockValidator.Setup(x => x.IsValidPrice(price)).Returns(true);
            var dependencyService = new DependencyService();

            dependencyService.Register <IValidationService>(mockValidator.Object);
            var availableBooks = new List <BookProductInfo> {
                new BookProductInfo {
                    Book = newBook
                }
            };
            var library = new LibraryRepository(availableBooks, dependencyService);

            var addResult = library.AddNewBook(newBook, price);

            Assert.False(addResult);

            var addedBook = library.AvailableBooks.FirstOrDefault(item => item.Book.ISBN == isbn);

            Assert.Equal(1, addedBook.Quantity);
        }
        public void RefreshCatalogMethod()
        {
            LibraryRepository repository = new LibraryRepository();

            models = CatalogModel.GetCatalogs();
            this.RaisePropertyChanged(() => this.CatalogsList);
        }
Example #6
0
        public IActionResult DeleteBookForAuthor(Guid authorId, Guid id)
        {
            if (LibraryRepository.AuthorNotExists(authorId))
            {
                return(NotFound());
            }

            var book = LibraryRepository.GetBookForAuthor(authorId, id);

            if (book == null)
            {
                return(NotFound());
            }

            LibraryRepository.DeleteBook(book);

            if (LibraryRepository.NotSave())
            {
                throw new Exception($"Deleting book {id} for author {authorId} failed on save.");
            }

            Logger.LogInformation(100, $"Book {id} for author {authorId} was deleted.");

            return(NoContent());
        }
        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 void BorrowBookModifiesLendList(string isbn, string cnp)
        {
            var mockValidator = new Mock <IValidationService>();

            mockValidator.Setup(x => x.IsValidCNP(cnp)).Returns(true);
            var dependencyService = new DependencyService();

            dependencyService.Register <IValidationService>(mockValidator.Object);
            var availableBooks = new List <BookProductInfo> {
                new BookProductInfo {
                    Book = new Book {
                        ISBN = isbn
                    }, Quantity = 1
                }
            };
            var library = new LibraryRepository(availableBooks, dependencyService);

            var borrowResult = library.Borrow(isbn, cnp);

            Assert.True(borrowResult);
            var borrowedBook = Assert.Single(library.BorrowedBooks);

            Assert.NotNull(borrowedBook);

            Assert.Equal(isbn, borrowedBook.ISBN);
            Assert.False(borrowedBook.HasBeenReturned);
            // timestamps
        }
        public void AddExistingBookWithQuantityInvalidNotModifyingQuantity(string isbn, string name, int quantity)
        {
            var mockValidator = new Mock <IValidationService>();

            mockValidator.Setup(x => x.IsValidQuantity(quantity)).Returns(false);
            var dependencyService = new DependencyService();

            dependencyService.Register <IValidationService>(mockValidator.Object);
            var availableBooks = new List <BookProductInfo> {
                new BookProductInfo {
                    Book = new Book {
                        ISBN = isbn, Name = name
                    }, Quantity = 1
                }
            };
            var library = new LibraryRepository(availableBooks, dependencyService);

            var addResult = library.AddExistingBook(isbn, quantity);

            Assert.False(addResult);
            var addedBook = Assert.Single(library.AvailableBooks);

            Assert.NotNull(addedBook);
            Assert.Equal(1, addedBook.Quantity);
        }
        public void ReturnBookSuccessUpdatesReturnedStatus(string isbn, string cnp)
        {
            var mockValidator = new Mock <IValidationService>();

            mockValidator.Setup(x => x.IsValidQuantity(1)).Returns(true);
            var dependencyService = new DependencyService();

            dependencyService.Register <IValidationService>(mockValidator.Object);
            var availableBooks = new List <BookProductInfo> {
                new BookProductInfo {
                    Book = new Book {
                        ISBN = isbn
                    }
                }
            };
            var lendBooks = new List <Borrowing> {
                new Borrowing {
                    CNP = cnp, ISBN = isbn
                }
            };
            var library = new LibraryRepository(availableBooks, lendBooks, dependencyService);

            var returnResult = library.ReturnBook(isbn, cnp);

            Assert.True(returnResult);
            Assert.True(Assert.Single(library.BorrowedBooks).HasBeenReturned);
        }
        public ActionResult CreateDocument()
        {
            Library oemKey = LibraryRepository.SelLibraryObject(new Library {
                Name = "OEM"
            });
            List <Library> oemList = LibraryRepository.SelLibrary(new Library {
                FromOID = oemKey.OID
            });                                                                                        //OEM 목록

            ViewBag.oemList = oemList;

            Library tdocKey = LibraryRepository.SelLibraryObject(new Library {
                Name = "TDOC"
            });
            List <Library> tdocList = LibraryRepository.SelLibrary(new Library {
                FromOID = tdocKey.OID
            });                                                                                           //TDOC 목록

            ViewBag.tdocList = tdocList;

            Library pdocKey = LibraryRepository.SelLibraryObject(new Library {
                Name = "PDOC"
            });
            List <Library> pdocList = LibraryRepository.SelLibrary(new Library {
                FromOID = pdocKey.OID
            });                                                                                           //PDOC 목록

            ViewBag.pdocList = pdocList;

            return(View());
        }
        public ActionResult InfoDocument(int OID)
        {
            Doc docDetail = DocRepository.SelDocObject(new Doc {
                OID = OID
            });

            if (docDetail.Doc_Lib_Lev1_OID != null)
            {
                docDetail.Doc_Lib_Lev1_KorNm = LibraryRepository.SelLibraryObject(new Library {
                    OID = docDetail.Doc_Lib_Lev1_OID
                }).KorNm;
            }
            if (docDetail.Doc_Lib_Lev2_OID != null)
            {
                docDetail.Doc_Lib_Lev2_KorNm = LibraryRepository.SelLibraryObject(new Library {
                    OID = docDetail.Doc_Lib_Lev2_OID
                }).KorNm;
            }
            if (docDetail.Doc_Lib_Lev3_OID != null)
            {
                docDetail.Doc_Lib_Lev3_KorNm = LibraryRepository.SelLibraryObject(new Library {
                    OID = docDetail.Doc_Lib_Lev3_OID
                }).KorNm;
            }
            ViewBag.docDetail = docDetail;
            ViewBag.Status    = BPolicyRepository.SelBPolicy(new BPolicy {
                Type = DocumentContant.TYPE_DOCUMENT
            });
            return(View());
        }
Example #13
0
        public void SaveCatalogMethod()
        {
            LibraryRepository repository = new LibraryRepository();

            Task.Run(() => repository.AddCatalog(Title, Author));
            Messenger.Default.Send <NotificationMessage>(new NotificationMessage("CloseAddCatalog"));
            Messenger.Default.Send <NotificationMessage>(new NotificationMessage("RefreshCatalog"));
        }
Example #14
0
        public async Task AddTagAsync(Tag tag)
        {
            var library = (CurrentlyOpenedElement as Library);

            library.Tags.Add(tag);
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentlyOpenedElement"));
            await LibraryRepository.UpdateAsync(library);
        }
Example #15
0
 public async Task GetBooksForAuthorAsync_WithEmptyGuid_Test()
 {
     using (var context = new LibraryContext(Utilities.TestDbContextOptions()))
         using (ILibraryRepository repository = new LibraryRepository(context))
         {
             await Assert.ThrowsAsync <ArgumentException>(() => repository.GetBooksForAuthorAsync(Guid.Empty));
         }
 }
        public void GetJKRowlingsBooks_ExpectMoreThan15Results()
        {
            var lib = new LibraryRepository();

            var books = lib.GetBooksByAuthor("J. K. Rowling", 20);

            Assert.IsTrue(books.Count > 15);
        }
        public void GetHarryPotterBooks_ExpectMoreThan15Results()
        {
            var lib = new LibraryRepository();

            var books = lib.GetBooks("Harry Potter", 20);

            Assert.IsTrue(books.Count > 15);
        }
        public void GetBooksDefault_ExpectMax10Result()
        {
            var lib = new LibraryRepository();

            var books = lib.GetBooks();

            Assert.IsTrue(books.Count <= 10);
        }
Example #19
0
        public void GetHarryPotterBooksCount_ExpectMoreThan15Results()
        {
            var lib = new LibraryRepository();

            var bookCount = lib.GetBookCount("Harry Potter");

            Assert.IsTrue(bookCount > 15);
        }
        public void Get20Books_Expect20Result()
        {
            var lib = new LibraryRepository();

            var books = lib.GetBooks("",20);

            Assert.IsTrue(books.Count == 20);
        }
Example #21
0
        public void GetAllBooksCount_ExpectMoreThan700Results()
        {
            var lib = new LibraryRepository();

            var bookCount = lib.GetBookCount();

            Assert.IsTrue(bookCount > 700);
        }
        public void GetAllBooksCount_ExpectMoreThan700Results()
        {
            var lib = new LibraryRepository();

            var bookCount = lib.GetBookCount();

            Assert.IsTrue( bookCount > 700 );
        }
Example #23
0
        public void Get20Books_Expect20Result()
        {
            var lib = new LibraryRepository();

            var books = lib.GetBooks("", 20);


            Assert.IsTrue(books.Count == 20);
        }
Example #24
0
 public UnitOfWork(AppDbContext db)
 {
     _db         = db;
     Users       = new UserRepository(db);
     Books       = new BookRepository(db);
     Libraries   = new LibraryRepository(db);
     Bookshelves = new BookshelfRepository(db);
     MyList      = new ListRepository(db);
 }
Example #25
0
        public void GetJKRowlingsBooks_ExpectMoreThan15Results()
        {
            var lib = new LibraryRepository();

            var books = lib.GetBooksByAuthor("J. K. Rowling", 20);


            Assert.IsTrue(books.Count > 15);
        }
Example #26
0
        public void GetBooksDefault_ExpectMax10Result()
        {
            var lib = new LibraryRepository();

            var books = lib.GetBooks();


            Assert.IsTrue(books.Count <= 10);
        }
Example #27
0
        public WhenGetBooksCalled()
        {
            _contextMock    = new Mock <IContext>();
            _booksDbSetMock = new Mock <IDbSet <Book> >();

            _contextMock.Setup(x => x.Books).Returns(_booksDbSetMock.Object);

            _libraryRepository = new LibraryRepository(_contextMock.Object);
        }
 public void RemoveCatalogMethod()
 {
     if (SelectedCatalog != null)
     {
         LibraryRepository repository = new LibraryRepository();
         Task.Run(() => repository.RemoveCatalog(SelectedCatalog.Id));
         Messenger.Default.Send <NotificationMessage>(new NotificationMessage("RefreshCatalog"));
     }
 }
Example #29
0
        public IActionResult BlockAuthorCreation(Guid id)
        {
            if (LibraryRepository.AuthorExists(id))
            {
                return(StatusCode(409));
            }

            return(NotFound());
        }
 public void RemoveStateMethod()
 {
     if (SelectedState != null)
     {
         LibraryRepository repository = new LibraryRepository();
         Task.Run(() => repository.RemoveState(SelectedState.Id));
         Messenger.Default.Send <NotificationMessage>(new NotificationMessage("RefreshState"));
     }
 }
        public ManipulationViewModel(CompositionContainer container)
        {
            this.Container = container;
            libraryRepository = this.Container.GetExportedValue<LibraryRepository>();

            AddRegularExpressionCommand = new DelegateCommand(AddRegularExpressionCommandHandler);
            UpdateRegularExpressionCommand = new DelegateCommand(UpdateRegularExpressionCommandHandler);
            CancelCommand = new DelegateCommand(CancelCommandHandler);
        }
Example #32
0
        public async Task GetAuthorsAsync_WithIdsAugument_Test()
        {
            using (var context = new LibraryContext(Utilities.TestDbContextOptions()))
                using (ILibraryRepository repository = new LibraryRepository(context))
                {
                    // Arrange
                    context.Authors.Add(new Author()
                    {
                        Id          = new Guid("a1da1d8e-1988-4634-b538-a01709477b77"),
                        FirstName   = "Jens",
                        LastName    = "Lapidus",
                        Genre       = "Thriller",
                        DateOfBirth = new DateTimeOffset(new DateTime(1974, 5, 24)),
                        Books       = new List <Book>()
                        {
                            new Book()
                            {
                                Id          = new Guid("1325360c-8253-473a-a20f-55c269c20407"),
                                Title       = "Easy Money",
                                Description = "Easy Money or Snabba cash is a novel from 2006 by Jens Lapidus."
                            }
                        }
                    });
                    context.Authors.Add(new Author()
                    {
                        Id          = new Guid("f74d6899-9ed2-4137-9876-66b070553f8f"),
                        FirstName   = "Douglas",
                        LastName    = "Adams",
                        Genre       = "Science fiction",
                        DateOfBirth = new DateTimeOffset(new DateTime(1952, 3, 11)),
                        Books       = new List <Book>()
                        {
                            new Book()
                            {
                                Id          = new Guid("e57b605f-8b3c-4089-b672-6ce9e6d6c23f"),
                                Title       = "The Hitchhiker's Guide to the Galaxy",
                                Description = "The Hitchhiker's Guide to the Galaxy"
                            }
                        }
                    });
                    context.SaveChanges();

                    // Act
                    var ids     = new Guid[] { Guid.Parse("a1da1d8e-1988-4634-b538-a01709477b77"), Guid.Parse("f74d6899-9ed2-4137-9876-66b070553f8f") };
                    var authors = await repository.GetAuthorsAsync(ids);

                    // Assert
                    Assert.IsAssignableFrom <IEnumerable <Author> >(authors);
                    Assert.True(authors.Count() == 2);
                    Assert.Collection(
                        authors,
                        item => Assert.Equal(Guid.Parse("f74d6899-9ed2-4137-9876-66b070553f8f"), item.Id),
                        item => Assert.Equal(Guid.Parse("a1da1d8e-1988-4634-b538-a01709477b77"), item.Id)
                        );
                }
        }
 public BaseController(IConfiguration config)
 {
     _libraryRepository  = new LibraryRepository(config.GetConnectionString("DefaultConnection"));
     _userRepository     = new UserRepository(config.GetConnectionString("DefaultConnection"));
     _analyticRepository = new AnalyticRepository(config.GetConnectionString("DefaultConnection"));
     _authService        = new AuthService(_userRepository, config);
     _mailService        = new MailService(
         config.GetValue <string>("Email"),
         config.GetValue <string>("SMTPProvider"));
 }
Example #34
0
        public void GetAuthor()
        {
            using (var context = new LibraryContext(options))
            {
                var service = new LibraryRepository(context);

                Assert.IsNull(service.GetAuthor(0));
                Assert.IsNotNull(service.GetAuthor(1));
            }
        }
 protected override void InitializeShell()
 {
     base.InitializeShell();
     var eventAggregator = Container.GetExportedValue<IEventAggregator>();
     libraryRepository = new LibraryRepository(eventAggregator);
     libraryRepository.InitializeRepository();
     Container.ComposeExportedValue(libraryRepository);
     Application.Current.MainWindow = (Window)this.Shell;
     Application.Current.MainWindow.Show();
 }
        public WhenFindBookCalled()
        {
            var contextMock = new Mock <IContext>();

            _booksDbSetMock = new Mock <IDbSet <Book> >();

            contextMock.Setup(x => x.Books).Returns(_booksDbSetMock.Object);

            _libraryRepository = new LibraryRepository(contextMock.Object);
        }
Example #37
0
        public void AuthorExists()
        {
            using (var context = new LibraryContext(options))
            {
                var service = new LibraryRepository(context);

                Assert.IsTrue(service.AuthorExists(1));
                Assert.IsFalse(service.AuthorExists(0));
            }
        }
        public void TestAggregation_ExpectNonZeroResult()
        {
            var lib = new LibraryRepository();

            var refinements = new List<string>();
            refinements.Add("author");
            refinements.Add("genre");

            var result = lib.SearchBookWithAggregation("potter", "", refinements, 20);

            Assert.IsTrue(result.Aggregations.Count > 0 );
        }
        public AnalyzerViewModel(CompositionContainer container, IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;
            this.Container = container;
            InputFlowDocument = new FlowDocument();
            ValidateRegex = new DelegateCommand(OnValidateRegex, CanExecuteValidateRegex);
            OpenLibrary = new DelegateCommand(OnOpenLibrary);
            AddRegularExpressionCommand = new DelegateCommand(AddRegularExpressionCommandHandler);

            libraryRepository = container.GetExportedValue<LibraryRepository>();
            RegularExpressions = libraryRepository.RegularExpressions;
            this.eventAggregator.GetEvent<UpdateRegularExpressionCollectionEvent>().Subscribe(UpdateRegularExpressionCollectionEventHandler);
            eventAggregator.GetEvent<SelectedRegularExpressionEvent>().Subscribe(SelectedRegularExpressionEventHandler);
        }
Example #40
0
 public LibraryViewModel(CompositionContainer container, IRegionManager regionManager, IEventAggregator eventAggregator)
 {
     this.Container = container;
     this.regionManager = regionManager;
     this.eventAggregator = eventAggregator;
     libraryRepository = container.GetExportedValue<LibraryRepository>();
     RegularExpressions = libraryRepository.RegularExpressions;
     this.eventAggregator.GetEvent<UpdateRegularExpressionCollectionEvent>().Subscribe(UpdateRegularExpressionCollectionEventHandler);
     this.ConfirmationRequest = new InteractionRequest<IConfirmation>();
     AddRegularExpressionCommand = new DelegateCommand(AddRegularExpressionCommandHandler);
     EditRegularExpressionCommand = new DelegateCommand<RegularExpression>(EditRegularExpressionCommandHandler);
     DeleteRegularExpressionCommand = new DelegateCommand<RegularExpression>(DeleteRegularExpressionCommandHandler);
     CopyRegularExpressionCommand = new DelegateCommand<RegularExpression>(CopyRegularExpressionCommandHandler);
     SelectedRegularExpressionCommand = new DelegateCommand(SelectedRegularExpressionCommandHandler, CanExecuteSelectedRegularExpressionCommand);
     CancelCommand = new DelegateCommand(CancelCommandHandler);
 }
Example #41
0
 private TreeNode CreateNewTreeNode(string folder, int? parentId, int libraryId, BXCModelEntities context)
 {
     var nodeRepo = new TreeNodeRepository(context);
         var libraryRepo = new LibraryRepository(context);
         var newNode = new TreeNode
                           {
                               Name = folder,
                               TreeNode1 =
                                   parentId == null
                                       ? null
                                       : nodeRepo.GetByID(parentId.Value),
                               Library = libraryRepo.GetByID(libraryId)
                           };
         nodeRepo.AddTreeNode(newNode);
         return newNode;
 }
Example #42
0
 public Library AddContentLibrary(string libraryName, BXCModelEntities context = null)
 {
     context = context ?? new BXCModelEntities();
         var libraryRepo = new LibraryRepository(context);
         return libraryRepo.AddLibrary(libraryName);
 }
Example #43
0
 public Library GetContentLibrary(string libraryName, string ownerId, BXCModelEntities context = null)
 {
     context = context ?? new BXCModelEntities();
         var libraryRepo = new LibraryRepository(context);
         return libraryRepo.GetByNameAndOwner(libraryName, ownerId);
 }