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 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 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() { }; }