public void Initialize() { CATEGORY_NAME = "Przygodowa"; BOOK_TITLE = "Robinson"; BOOK_AUTHORS = "A I B"; price = 100; quantityMap = new QuantityMap(); quantity = 10; quantityMap.Quantity = quantity; quantityMap.Id = 1; category = new Category(); category.Name = CATEGORY_NAME; bookType = new BookType(); bookType.Category = category; bookType.Title = BOOK_TITLE; bookType.Image = null; bookType.Price = price; bookType.Id = 1; bookType.Authors = BOOK_AUTHORS; bookTypeList = new List<BookType>(); categoryList = new List<Category>(); var bookInformationMock = _factory.CreateMock<IBooksInformationDao>(); bis.BooksInformationDao = bookInformationMock.MockObject; bookInformationMock.Expects.One.MethodWith<BookType>(x => x.GetBookTypeById(-1)).WillReturn(null); bookInformationMock.Expects.One.MethodWith<BookType>(x => x.GetBookTypeById(bookType.Id)).WillReturn(bookType); bookInformationMock.Expects.One.MethodWith<IEnumerable<BookType>>(x => x.GetAllBooks()) .WillReturn(bookTypeList); bookInformationMock.Expects.One.MethodWith<IList<Category>>(x => x.GetAllCategories()) .WillReturn(categoryList); bookInformationMock.Expects.One.MethodWith<IEnumerable<BookType>>(x => x.GetBooksByCategoryId(category.Id)) .WillReturn(bookTypeList); bookInformationMock.Expects.One.MethodWith<IEnumerable<BookType>>(x => x.GetBooksByCategoryId(-1)) .WillReturn(null); var storehouseManagementMock = _factory.CreateMock<IStorehouseManagementDao>(); sms.StorehouseManagementDao = storehouseManagementMock.MockObject; NMock.Actions.InvokeAction saveBookTypeAction = new NMock.Actions.InvokeAction( new Action(() => bookTypeList.Add(bookType))); storehouseManagementMock.Expects.Any.MethodWith(x => x.SaveBookType(bookType)).Will(saveBookTypeAction); NMock.Actions.InvokeAction saveCategoryAction = new NMock.Actions.InvokeAction( new Action(() => categoryList.Add(category))); storehouseManagementMock.Expects.Any.MethodWith(x => x.SaveCategory(category)).Will(saveCategoryAction); }
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()); }
public void AddBookType(string title, string authors, decimal price, int quantity, Category category, string imageURL) { QuantityMap quantityMap = new QuantityMap() { Quantity = quantity }; BookImage image = new BookImage() { URL = imageURL }; BookType newBookType = new BookType() { Title = title, Authors = authors, Price = price, QuantityMap = quantityMap, Category = category, Image = image }; StorehouseManagementDao.SaveBookType(newBookType); }
public void SaveCategory(Category category) { StorehouseManagementDao.SaveCategory(category); }
public void AddCategory(String name) { Category category = new Category() { Name = name }; StorehouseManagementDao.SaveCategory(category); }
public void Initialize() { TEST_QUANTITY = 5; TEST_ADD_QUANTITY = 4; TEST_CAT_NAME = "testowa kategoria"; testCategory = new Category(); testCategory.Name = TEST_CAT_NAME; testBook = new BookType(); testGetBook = new BookType(); testBook.Id = 47123; testBook.Title = "Książka testowa"; testBook.Authors = "Autor testowy"; testBook.Category = testCategory; testBook.QuantityMap = new QuantityMap(); testBook.QuantityMap.Quantity = TEST_QUANTITY; testBook.Price = 40; categoryList = new List<Category>(); bookTypeList = new List<BookType>(); booksInformationDaoMock = _factory.CreateMock<IBooksInformationDao>(); bis.BooksInformationDao = booksInformationDaoMock.MockObject; sms.BooksInformationDao = booksInformationDaoMock.MockObject; booksInformationDaoMock.Expects.One.MethodWith<IEnumerable<BookType>>(x => x.GetAllBooks()).WillReturn(bookTypeList); booksInformationDaoMock.Expects.One.MethodWith<IList<Category>>(x => x.GetAllCategories()).WillReturn(categoryList); booksInformationDaoMock.Expects.One.MethodWith<BookType>(x => x.GetBookTypeById(testBook.Id)).WillReturn(testBook); booksInformationDaoMock.Expects.One.MethodWith<BookType>(x => x.GetBookTypeById(testGetBook.Id)).WillReturn(testGetBook); storehouseManagementDaoMock = _factory.CreateMock<IStorehouseManagementDao>(); sms.StorehouseManagementDao = storehouseManagementDaoMock.MockObject; NMock.Actions.InvokeAction markSold = new NMock.Actions.InvokeAction(new Action(() => changeQuantity())); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.MarkSold(testBook.Id, testBook.QuantityMap.Quantity)).Will(markSold); storehouseManagementDaoMock.Expects.One.MethodWith<bool>(x => x.MarkSold(-1, 5)).WillReturn(false); NMock.Actions.InvokeAction saveCategory = new NMock.Actions.InvokeAction(new Action(() => categoryList.Add(testCategory))); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveCategory(testCategory)).Will(saveCategory); NMock.Actions.InvokeAction saveBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook))); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveBookType(testBook)).Will(saveBookType); NMock.Actions.InvokeAction addCategory = new NMock.Actions.InvokeAction(new Action(() => categoryList.Add(testCategory))); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.AddCategory(TEST_CAT_NAME)).Will(addCategory); NMock.Actions.InvokeAction addBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook))); storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.AddBookType(testBook.Title, testBook.Authors, testBook.Price, TEST_QUANTITY, testBook.Category)).Will(addBookType); // NMock.Actions.InvokeAction addQuantity = new NMock.Actions.InvokeAction(new Action(() => quantityMap = new QuantityMap() { Quantity = 0 }; image = new BookImage() { URL = "" }; category = new Category() { }; }
public void SaveCategory(Category category) { this.Session.Save(category); }
public void AddBookType(string title, string authors, decimal price, int quantity, Category category) { throw new NotImplementedException(); }
public void Initialize() { _factory = new MockFactory(); order = new Order(); order.OrderEntries = null; order.SentDate = DateTime.Now; order.User = null; getOrder = new Order(); testBook = new BookType(); Category testCategory = new Category(); testBook.Id = 47123; testBook.Title = "Książka testowa"; testBook.Authors = "Autor testowy"; testBook.Category = testCategory; testBook.Price = 40; TEST_AMOUNT = 5; orderManagementDaoMock = _factory.CreateMock<IOrderManagementDao>(); oms.OrderManagementDao = orderManagementDaoMock.MockObject; orderInformationDaoMock = _factory.CreateMock<IOrderInformationsDao>(); ois.OrderInformationDao = orderInformationDaoMock.MockObject; oms.OrderInformationDao = orderInformationDaoMock.MockObject; storehouseManagementDaoMock = _factory.CreateMock<IStorehouseManagementDao>(); sms.StorehouseManagementDao = storehouseManagementDaoMock.MockObject; booksInformationServiceMock = _factory.CreateMock<IBooksInformationService>(); sms.BooksInformationService = booksInformationServiceMock.MockObject; oms.BooksInformationService = booksInformationServiceMock.MockObject; }