public ILoan GetLoanByBook(IBook book) { if (book == null) throw new ArgumentException("Error: book can\'t be null."); return _loans.FirstOrDefault(loan => loan.Book.Equals(book)); }
public static IStock Create(IBook book, bool isAvailable) { if (book == null) throw new ArgumentNullException(); return new Stock() {Book = book, IsAvailable = isAvailable}; }
public void receiveBook(IBook book) { _book = book; _book.completed.AddOnce(image => { _aspectRatioResolved.Dispatch((float)image.texture.width / image.texture.height); }); }
public void CreateLoan_IncorrectDueDate_ThrowsAnException(IMember borrower, IBook book) { // Arrange. // Act var loan = _loanDao.Invoking(x => x.CreateLoan(borrower, book, DateTime.Today, DateTime.Today.AddDays(-1))) .ShouldThrow<ArgumentException>(); }
public ILoan CreateLoan(IMember borrower, IBook book, DateTime borrowDate, DateTime dueDate) { if(borrower == null) throw new ArgumentException("A Member must be provided to create a loan"); if(book == null) throw new ArgumentException("A Book must be provided to create a loan"); var loan = _helper.MakeLoan(book, borrower, borrowDate, dueDate); return loan; }
public void CreateLoan_WithValidParams_CreatesANewLoan(IMember borrower, IBook book) { // Arrange. // Act var loan = _loanDao.CreateLoan(borrower, book, DateTime.Today, DateTime.Today.AddDays(1)); loan.Should().NotBeNull(); }
public void UpdateBook(IBook book) { var client = new RestClient("http://rest.test.com/services"); var request = new RestRequest("books", Method.PUT); request.RequestFormat = DataFormat.Json; request.AddBody(book); var response = client.Execute(request); Console.WriteLine(response.Content); }
public void receiveBook(IBook book) { Debug.Log("START LOADING IMAGES"); enabled = true; _book = book; reset(); SendStartProgress(); _book.completed.AddListener(LoadCompleted); LoadNext(); }
public async void AddBook(IBook book) { using (var client = new HttpClient { BaseAddress = new Uri("http://rest.test.com") }) { var content = new StringContent(JsonConvert.SerializeObject(book), new UTF8Encoding(), "application/json"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PostAsync("services/books", content); var responseString = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseString); } }
public static IBookOrderLine Add(this IBookOrder order, IBook book, int quantity) { var session = EntityHelper.GetSession(order); var line = session.NewEntity<IBookOrderLine>(); line.Order = order; line.Book = book; line.Quantity = quantity; line.Price = book.Price; order.Lines.Add(line); return line; }
public void EdgeCase_CantMoveFromPendingToOverdue(ILoanDAO loanDao, IMember borrower, IBook book) { // Create and commit to the loan. var loan = loanDao.CreateLoan(borrower, book, _today, _dueDate); loan.State.Should().Be(LoanState.PENDING); // Return the book should be prevented. loan.Invoking(x => x.CheckOverDue(_overdueDate)) .ShouldThrow<ApplicationException>(); loan.State.Should().Be(LoanState.PENDING); }
public void Setup() { bookDict = new Dictionary<int, IBook>(); mockHelper = new Mock<IBookHelper>(); mhelper = (IBookHelper)mockHelper.Object; mockBook1 = new Mock<IBook>(); mbook1 = (IBook)mockBook1.Object; mockBook2 = new Mock<IBook>(); mbook2 = (IBook)mockBook2.Object; dao = new BookDAO(mhelper); }
public ILoan CreateLoan(IMember borrower, IBook book, DateTime borrowDate, DateTime dueDate) { if (DateTime.Compare(borrowDate, dueDate) > 0) throw new ArgumentException("Error borrowing date cannot be after dueDate."); Debug.Assert(borrower != null); // Todo: XXX Borrower null? if (book == null || borrower == null) throw new ArgumentException("Error null parameters found."); return _loanHelper.MakeLoan(book, borrower, borrowDate, dueDate); }
public decimal GetDiscount(IBook book) { // 20% discount for books released more than year before if (book.ReleaseDate < DateTime.UtcNow.AddYears(-1)) return book.Price * 0.8m; // 10% discount for books released more than 6 months before if (book.ReleaseDate < DateTime.UtcNow.AddMonths(-6)) return book.Price * 0.9m; return book.Price; }
/// <summary> /// Creates a new instance of the Loan object. /// </summary> /// <param name="book">The IBook object being loaned.</param> /// <param name="borrower">The IMember who is initiating the loan.</param> /// <param name="borrowDate">The date and time that the book is being borrowed.</param> /// <param name="dueDate">The date ad time that the book is due.</param> /// <param name="loanId">The Id of the loan object.</param> public Loan(IBook book, IMember borrower, DateTime borrowDate, DateTime dueDate, int loanId) { // Validate the book parameter if (book == null) { throw new ArgumentNullException("book", "The 'book' parameter cannot be null."); } // Validate the member parameter if (borrower == null) { throw new ArgumentNullException("borrower", "The 'borrower' parameter cannot be null."); } // Ensure the borrowDate is valid if (borrowDate == DateTime.MinValue) { throw new ArgumentOutOfRangeException("borrowDate", "The borrowDate cannot be the default DateTime value."); } // Ensure the borrowDate is valid if (dueDate == DateTime.MinValue) { throw new ArgumentOutOfRangeException("dueDate", "The dueDate cannot be the default DateTime value."); } // Ensure the due date is not < borrowDate if (dueDate < borrowDate) { throw new ArgumentOutOfRangeException("dueDate", "The dueDate value cannot be less than the borrowDate."); } // Ensure the loanId is a positive integer if (loanId <= 0) { throw new ArgumentOutOfRangeException("loanId", "The 'loanId' parameter must be a positive integer value."); } // Set the fields of the Loan class this._book = book; this._borrower = borrower; this._id = loanId; // Use the Date property to get the midnight value for the current date this._borrowDate = borrowDate.Date; // Add 1 day to the Date property, and then subtract 1 second to get 23:59:59 on the due date this._dueDate = dueDate.Date.AddDays(1).AddSeconds(-1); // Set the initial state for the loan object this._loanState = LoanConstants.LoanState.PENDING; }
public Loan(IBook book, IMember borrower, DateTime borrowDate, DateTime dueDate, int id) { if (!sane(book, borrower, borrowDate, dueDate, id)) { throw new ArgumentException("Loan: constructor : bad parameters"); } this.book = book; this.borrower = borrower; this.borrowDate = borrowDate; this.dueDate = dueDate; this.id = id; this.state = LoanConstants.LoanState.PENDING; }
public static List<BookReview> GetLatestReviews(IBook book, int take = 10) { var session = EntityHelper.GetSession(book); var rvSet = session.EntitySet<IBookReview>(); var query = from rv in rvSet where rv.Book == book orderby rv.CreatedOn descending select new BookReview() {Id = rv.Id, BookId = rv.Book.Id, Caption = rv.Caption, CreatedOn = rv.CreatedOn, Rating = rv.Rating, Review = rv.Review, UserName = rv.User.DisplayName}; var reviews = query.Take(take).ToList(); return reviews; }
public Loan(IBook book, IMember borrower, DateTime borrowDate, DateTime dueDate) { if (book == null || borrower == null || DateTime.Compare(borrowDate, dueDate) >= 0) throw new ArgumentException("Error: in constructor parameter list."); _id = 0; _state = LoanState.PENDING; _book = book; _borrower = borrower; _borrowDate = borrowDate; _dueDate = dueDate; }
public void BookScanned(int bookID) { if (bookID <= 0) { throw new ArgumentException(String.Format("BorrowCTL : bookScanned : bookID cannot be <= 0.")); } if (state != BorrowCTLConstants.State.BORROWING) { throw new ApplicationException( String.Format("BorrowCTL : cardScanned : illegal operation in state: {0}", state)); } book = bookDAO.GetBookByID(bookID); if (book == null) { throw new ApplicationException(String.Format("BorrowCTL : bookScanned : bookID not found")); } if (book.State != BookConstants.BookState.AVAILABLE) { throw new ApplicationException(String.Format("BorrowCTL : bookScanned : illegal BookState: %s", book.State)); } if (bookList.Contains(book)) { throw new ApplicationException(String.Format("BorrowCTL : bookScanned : book %d already scanned: ", book.ID)); } DateTime borrowDate = DateTime.Now; TimeSpan loanPeriod = new TimeSpan(LoanConstants.LOAN_PERIOD, 0, 0, 0); DateTime dueDate = borrowDate.Add(loanPeriod); loanDAO.CreatePendingLoan(member, book, borrowDate, dueDate); bookList.Add(book); pendingLoanCount++; atLoanLimit = ((existingLoanCount + pendingLoanCount) >= MemberConstants.LOAN_LIMIT); further_borrowing_allowed = !(overdue || atLoanLimit || overFineLimit); ui.DisplayBook(book); pendingList = loanDAO.GetPendingList(member); ui.DisplayPendingList(pendingList); if (atLoanLimit) { state = BorrowCTLConstants.State.COMPLETED; ui.SetState(state); pendingList = loanDAO.GetPendingList(member); ui.DisplayCompletedList(pendingList); } }
public bool IsOverDue = > this.State == LoanState.OVERDUE; // Return true if LoanState is Overdue. #endregion Fields #region Constructors public Loan(IBook book, IMember member, DateTime borrowDate, DateTime dueDate) { if(book == null) throw new ArgumentException("Book needs to be provided"); if(member == null) throw new ArgumentException("Member needs to be provided"); if(borrowDate == DateTime.MinValue) throw new ArgumentException("Borrow date needs to be provided"); if(dueDate == DateTime.MinValue) throw new ArgumentException("Due date needs to be provided"); if(dueDate < borrowDate) throw new ArgumentException("Due date cannot be before Borrow date"); this.Book = book; this.Borrower = member; this.DueDate = dueDate; this.BorrowDate = borrowDate; this.ID = 0; }
public ILoan CreateLoan(IMember borrower, IBook book, DateTime borrowDate, DateTime dueDate) { if (borrower == null || book == null || borrowDate == null || dueDate == null) { throw new ArgumentException( String.Format("LoanMapDAO : CreatePendingLoan : parameters cannot be null.")); } if (DateTime.Compare(borrowDate, dueDate) > 0) { throw new ArgumentException( String.Format("LoanDAO : createPendingLoan : borrowDate cannot be after dueDate.")); } int id = NextID; ILoan loan = helper.MakeLoan(book, borrower, borrowDate, dueDate, id); return loan; }
private void LoadCompleted( BookImage bookImage) { if (_index >= _length) { _book.completed.RemoveListener(LoadCompleted); SendComplete(); _index = 0; _current = null; _length = 0; _book = null; enabled = false; } else { SendResolved(_index-1); LoadNext(); } }
public void OverDueCase_UserBorrowsAndReturnsBookAfterDue(ILoanDAO loanDao, IMember borrower, IBook book) { // Create and commit to the loan. var loan = loanDao.CreateLoan(borrower, book, _today, _dueDate); loan.State.Should().Be(LoanState.PENDING); // Commit the loan. loan.Commit(200); loan.State.Should().Be(LoanState.CURRENT); // The book is now overdue. loan.CheckOverDue(_overdueDate); loan.State.Should().Be(LoanState.OVERDUE); loan.IsOverDue.Should().BeTrue(); // Return the book loan.Complete(); loan.State.Should().Be(LoanState.COMPLETE); loan.IsOverDue.Should().BeFalse(); }
public void HappyCase_UserBorrowsAndReturnsBookBeforeDue(ILoanDAO loanDao, IMember borrower, IBook book) { // Create and commit to the loan. var loan = loanDao.CreateLoan(borrower, book, _today, _dueDate); loan.State.Should().Be(LoanState.PENDING); // Commit the loan. loan.Commit(200); loan.State.Should().Be(LoanState.CURRENT); // Check if the book is overdue. loan.CheckOverDue(_notYetDueDate); loan.State.Should().Be(LoanState.CURRENT); // Return the book loan.Complete(); loan.State.Should().Be(LoanState.COMPLETE); loan.IsOverDue.Should().BeFalse(); }
public void Book(IBook rent) { // nosso amigo, o banco falso FakeDB faker = new FakeDB(); List<IBook> booksToSave; // adicionando a nova reserva. Se for a primeira cria do zero. IBook[] books = GetReservations(); if (books == null) booksToSave = new List<IBook>(); else booksToSave = books.ToList(); // impedindo duplicidade e escrevendo em disco if (!booksToSave.Any(x => x.BookReference == rent.BookReference)) { booksToSave.Add(rent); faker.Save(booksToSave); } }
/// <summary> /// Initializes a new instance of the <see cref="BookFormatExtensionTitle"/> class /// </summary> /// <param name="book">Extendable object</param> public BookFormatExtensionTitle(IBook book) : base(book) { }
public void StockTooExpensiveTest(Store store, IActor seller, float price, uint count, IBook book, IDescription description) { float capital = store.Money; Assert.False(store.Stock(seller, price, count, book, description)); Assert.Equal(capital, store.Money); // Check event logging var events = store.GetEvents(); Assert.Empty(events); // Check catalog var books = store.GetBooks(); Assert.Empty(books); Assert.Null(store.GetBookListing(book)); // Check inventory Assert.Equal((uint)0, store.GetBookAvailability(book)); }
private static async Task RenameBookAsync(IBook book) { book.Title = await RenameDialog.ShowAsync(book.Title); await book.SaveChangesAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="BookFormatExtensionPublishingHouse"/> class /// </summary> /// <param name="book">Extendable object</param> public BookFormatExtensionPublishingHouse(IBook book) : base(book) { }
/// <summary> /// Initializes a new instance of the <see cref="BookFormatExtensionAuthor"/> class /// </summary> /// <param name="book">Extendable object</param> public BookFormatExtensionAuthor(IBook book) : base(book) { }
public BookController(IBook book) { _book = book; }
public void RemoveBook(IBook book) { _books.Remove(book); }
public LibraryController(IBook books) { _books = books; }
public async Task <int> AddBook(IBook book) { _dbContext.Books.Add(ConvertToDbBook(book)); return(await _dbContext.SaveChangesAsync()); }
public void AddTakenBook(IBook takenBook) { _books.Add(takenBook); }
/// <summary> /// Initializes a new instance of the <see cref="BookFormatExtensionPublishingHouse"/> class /// </summary> /// <param name="book">Extendable object</param> public BookFormatExtensionYear(IBook book) : base(book) { }
private void Actor_OnDoWork(object sender, DoWorkArgs args, EventType eventType, IBook book) { new Thread(() => { lock (locker) { using (var writer = GetWriter()) { OnLog(sender, new OnLogArgs <IBook>() { Args = args, EventType = eventType, Output = writer, Sender = book }); // Console.WriteLine(Thread.CurrentThread.ManagedThreadId); } } }) { IsBackground = true }.Start(); }
/// <summary> /// Подписываемся на логируемые события /// </summary> /// <param name="book">Книга, работу над которой логируем</param> public void Subscribe(IBook book) { book.Writer.OnDoWork += (sender, args) => Actor_OnDoWork(sender, args, EventType.WriterWorks, book); book.Illustrator.OnDoWork += (sender, args) => Actor_OnDoWork(sender, args, EventType.IllustratorWorks, book); book.Publisher.OnDoWork += (sender, args) => Actor_OnDoWork(sender, args, EventType.PublisherWorks, book); }
public BooksController(IBook book) { this.book = book; }
/// <summary> /// Initializes a new instance of the <see cref="BookFormatExtensionPublishingHouse"/> class /// </summary> /// <param name="book">Extendable object</param> public BookFormatExtensionIsbn(IBook book) : base(book) { }
public HomeController(IBook bookRepository) { _bookRepository = bookRepository; }
public ILoan MakeLoan(IBook book, IMember borrower, DateTime borrowDate, DateTime dueDate) { return new Loan(book, borrower, borrowDate, dueDate); }
public void Add(IBook book) { _books.Add(book); }
public void FindLoansByBorrower_WithBookNotOnLoan_ReturnsNull(IList<IMember> borrowers, IList<IBook> books, IBook bookNotOnLoan) { // Arrange. AddLoans(borrowers, books); // Act. var loanFound = _loanDao.GetLoanByBook(bookNotOnLoan); // Assert. loanFound.Should().BeNull(); }
public RealBookParser(IBook book) { _book = book; }
private void deleteAuthorButton_Click(object sender, RoutedEventArgs e) { IBook book = DataContext as IBook; book.Authors.Remove(peopleListBox.SelectedItem as IPerson); }
public IEntryItem GetEntryItemCombined(IBook book, IAccountPredicate predicate, IAsset asset) { return(GetEntryItemsCombined(book, predicate).SingleOrDefault(x => x.Asset.Equals(asset))); }
public CorrectEbookReader(IBook book) { this.book = book; }
public void RemoveTakenBook(IBook takenBook) { _books.Remove(takenBook); }
public EditBookDialog(BookRepository repos, IBook book) { InitializeComponent(); this._repos = repos; DataContext = book; }
private void Copy(IBook other) { if (this == other) { return; } Author = other.Author; Chapters = other.Chapters; Cover = other.Cover; Identifier = other.Identifier; Language = other.Language; Legal = other.Legal; PublicationDate = other.PublicationDate; Publisher = other.Publisher; Title = other.Title; }
public BookController(IBook book, IAuthor author, UserManager <ApplicationUser> userManager) { _book = book; _author = author; _userManager = userManager; }
// Static method validating Book entity public static void ValidateBook(IBook book) { var session = EntityHelper.GetSession(book); session.ValidateEntity(book, book.Price >= 0.0m, "PriceNegative", "Price", book.Price, "Price may not be negative"); }
public async Task <int> RemoveTakenBook(IBook takenBook) { _dbContext.Books.Remove(ConvertToDbBook(takenBook)); return(await _dbContext.SaveChangesAsync()); }
public BookAPIController(IBook book) { this._book = book; }
public abstract void MakeBook(IBook book);
private static void Main() { const DesignPatterns designPatterns = DesignPatterns.装饰模式; switch (designPatterns) { case DesignPatterns.单例模式: Singleton singleton = Singleton.GetInstance(); Console.WriteLine(singleton.Say()); break; case DesignPatterns.工厂模式: //简单工厂 BookFactory bookFactory = new BookFactory(); IBook chineseBook1 = bookFactory.CreateBook("语文"); IBook mathBook1 = bookFactory.CreateBook("数学"); chineseBook1.Info(); mathBook1.Info(); //工厂方法 ChineseBookFactory chineseBookFactory = new ChineseBookFactory(); MathBookFactory mathBookFactory = new MathBookFactory(); IBook chineseBook2 = chineseBookFactory.CreateBook(); IBook mathBook2 = mathBookFactory.CreateBook(); chineseBook2.Info(); mathBook2.Info(); //抽象工厂 FirstGradeBookFactory firstGradeBookFactory = new FirstGradeBookFactory(); SecondGradeFactory secondGradeFactory = new SecondGradeFactory(); IBook chineseBook3 = firstGradeBookFactory.CreateChineseBook(); IBook mathBook3 = firstGradeBookFactory.CreateMathBook(); chineseBook3.Info(); mathBook3.Info(); IBook chineseBook4 = secondGradeFactory.CreateChineseBook(); IBook mathBook4 = secondGradeFactory.CreateMathBook(); chineseBook4.Info(); mathBook4.Info(); break; case DesignPatterns.装饰模式: Zhangsan zhangsan = new Zhangsan(); ZhangsanSayA zhangsanSayA = new ZhangsanSayA(); ZhangsanSayB zhangsanSayB = new ZhangsanSayB(); zhangsanSayA.Tell(zhangsan); zhangsanSayB.Tell(zhangsanSayA); zhangsanSayB.Say(); break; case DesignPatterns.外观模式: Lisi lisi = new Lisi(); lisi.OneDay(); break; case DesignPatterns.代理模式: MathProxy proxy = new MathProxy(); Console.WriteLine("8 + 2 = " + proxy.Add(8, 2)); Console.WriteLine("8 - 2 = " + proxy.Sub(8, 2)); Console.WriteLine("8 * 2 = " + proxy.Mul(8, 2)); Console.WriteLine("8 / 2 = " + proxy.Div(8, 2)); break; case DesignPatterns.观察者模式: //被观察者 Hero hero = new Hero(); //添加观察者 hero.AttachObserver(new Monster()); hero.AttachObserver(new Trap()); hero.AttachObserver(new Treasure()); //通知观察者 hero.Move(); break; } }
public DustCover(IBook <T> book) { Book = book; }
public BookController(IBook <Books> book, IErrorLogger logger) { _book = book; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="BookFormatExtensionPublishingHouse"/> class /// </summary> /// <param name="book">Extendable object</param> public BookFormatExtensionPages(IBook book) : base(book) { }