public void AddOrderEntry(Order order, long selectedBookTypeId, int amount) { BookType bookType = BooksInformationService.GetBookTypeById(selectedBookTypeId); OrderEntry orderEntry = new OrderEntry() { BookType = bookType, Price = bookType.Price, Amount = amount }; order.OrderEntries.Add(orderEntry); }
public void ResultQuantityTest() { IList<Order> orders = new List<Order>(); IList<BookType> books = new List<BookType>(); Category cat = new Category(); cat.Id = 5; cat.Name = "Kategoria"; for (long i = 1; i < 8; i++) { BookType bookd = new BookType(); Order order = new Order(); OrderEntry entry = new OrderEntry(); order.OrderEntries = new List<OrderEntry>(); order.SentDate = DateTime.Now; order.Id = 10; order.User = null; entry.Id = i; entry.BookType = bookd; order.OrderEntries.Add(entry); bookd.Title = "Title" + i; bookd.Authors = "Auotr"; bookd.Id = i; bookd.Category = cat; booksInformationServiceMock.Expects.Any.MethodWith(x => x.GetBookTypeById(i)).WillReturn(bookd); booksInformationServiceMock.Expects.Any.MethodWith(x => x.GetBooksByCategoryId(5)).WillReturn(books); orders.Add(order); books.Add(bookd); } booksInformationServiceMock.Expects.Any.Method(x => x.GetAllBooks()).WillReturn(books); orderInformationServiceMock.Expects.Any.MethodWith(x => x.GetOrdersByUserId(1)).WillReturn(orders); IEnumerable<BookType> result = suggestionService.GetSuggestionsForUser(1); Int32 counter = 0; foreach (BookType book in result) { Assert.IsNotNull(book); counter++; } Assert.AreEqual(counter, 5); }
public void DistinctBookTest() { IEnumerable<BookType> result = null; IList<Order> orders = new List<Order>(); IList<BookType> books = new List<BookType>(); Category cat = new Category(); cat.Id = 5; cat.Name = "Kategoria"; for (long i = 1; i < 8; i++) { BookType bookd = new BookType(); Order order = new Order(); OrderEntry entry = new OrderEntry(); order.OrderEntries = new List<OrderEntry>(); order.SentDate = DateTime.Now; order.Id = 10; order.User = null; entry.Id = i; entry.BookType = bookd; order.OrderEntries.Add(entry); bookd.Title = "Title" + i; bookd.Authors = "Auotr"; bookd.Id = i; bookd.Category = cat; booksInformationServiceMock.Expects.Any.MethodWith(x => x.GetBookTypeById(i)).WillReturn(bookd); booksInformationServiceMock.Expects.Any.MethodWith(x => x.GetBooksByCategoryId(5)).WillReturn(books); orders.Add(order); books.Add(bookd); } booksInformationServiceMock.Expects.Any.Method(x => x.GetAllBooks()).WillReturn(books); orderInformationServiceMock.Expects.Any.MethodWith(x => x.GetOrdersByUserId(1)).WillReturn(orders); orderInformationServiceMock.Expects.Any.Method(x => x.GetUndeliveredOrders()).WillReturn(orders.Where(x => x.Status != Order.OrderState.DELIVERED)); result = suggestionService.GetSuggestionsForGuest(); Assert.AreEqual(result.Count(), result.Distinct().Count()); }
private List<OrderEntry> GenerateOrderEntries(List<BookType> bookTypes, Order order, int dataIndex) { List<OrderEntry> orderEntries = new List<OrderEntry>(); for (int i = 0; i < numberOfEntries[dataIndex]; i++) { OrderEntry entry = new OrderEntry() { Amount = amountsOfBooks[dataIndex], BookType = bookTypes.ElementAt(random.Next(bookTypes.Count)), }; entry.Price = entry.BookType.Price; orderEntries.Add(entry); } return orderEntries; }
public void TestGetOrderEntriesByOrderId() { OrderEntry tmpOrderEntry = new OrderEntry(); order.OrderEntries.Add(tmpOrderEntry); orders = new List<Order>(); NMock.Actions.InvokeAction createOrder = new NMock.Actions.InvokeAction(() => orders.Add(order)); orderManagementDaoMock.Expects.One.MethodWith(x => x.SaveOrUpdate(order)).Will(createOrder); oms.CreateNewOrder(order); orderInformationsDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(orders.FirstOrDefault(x => x.Id == order.Id)); bool isEntryThere = false; foreach (var item in sps.GetOrderEntriesByOrderId(order.Id)) { if (item.Id == tmpOrderEntry.Id) isEntryThere = true; } Assert.IsTrue(isEntryThere); }