Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            BookType type = obj as BookType;

            if (type == null)
            {
                return(false);
            }
            return(String.Compare(type.Title, this.Title) == 0 && type.Id == this.Id);
        }
        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 AddBookTypeNullCategoryTest()
        {
            NMock.Actions.InvokeAction save = new NMock.Actions.InvokeAction(ThrowNull);
            var book = new BookType()
            {
                Authors = "",
                Category = null,
                Image = image,
                Price = 0,
                QuantityMap = quantityMap,
                Title = ""

            };
            storehouseManagementDaoMock.Expects.Any.
                MethodWith(x => x.SaveBookType(book)).
                Will(save);

            sms.AddBookType("", "", 0, 0, null, "");
        }
        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 SaveBookType(BookType bookType)
 {
     StorehouseManagementDao.SaveBookType(bookType);
 }
        public void TestMarkSoldEnough()
        {
            bool marked = false;
            sms.SaveBookType(testBook);

            NMock.Actions.InvokeAction addQuantityAction = new NMock.Actions.InvokeAction(new Action(() => testGetBook.QuantityMap = testBook.QuantityMap));
            storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.UpdateQuantity(testBook)).Will(addQuantityAction);

            marked = (sms.MarkSold(testBook.Id, testBook.QuantityMap.Quantity));
            testGetBook = bis.GetBookTypeById(testGetBook.Id);
            Assert.IsTrue(testGetBook.QuantityMap.Quantity == 0) ;
        }
        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 AddQuantity()
        {
            NMock.Actions.InvokeAction addQuantityAction = new NMock.Actions.InvokeAction(new Action(() => testGetBook.QuantityMap = testBook.QuantityMap));

            storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.UpdateQuantity(testBook)).Will(addQuantityAction);
            booksInformationDaoMock.Expects.One.MethodWith<BookType>(x => x.GetBookTypeById(testGetBook.Id)).WillReturn(testGetBook);
            booksInformationDaoMock.Expects.One.MethodWith<BookType>(x => x.GetBookTypeById(testBook.Id)).WillReturn(testBook);

            bool added = false;
            sms.SaveBookType(testBook);
            added = (sms.AddQuantity(testBook.Id, TEST_ADD_QUANTITY));
            testGetBook = bis.GetBookTypeById(testBook.Id);
            Assert.IsTrue(added && testGetBook.QuantityMap.Quantity == testBook.QuantityMap.Quantity);
        }
Exemplo n.º 11
0
        public void Initialize()
        {
            var mockBookInformationService = _factory.CreateMock<IBooksInformationService>();
            BookType book = new BookType();
            List<BookType> bookList = new List<BookType>();
            for (int i = 0; i < 10; i++)
            {
                BookType tempBook = new BookType();
                tempBook.Id = i;
                bookList.Add(tempBook);
            }
            nonEmptyList = bookList;
            mockBookInformationService.Expects.Any.Method(_ => _.GetAllBooks()).WillReturn(bookList);
            mockBookInformationService.Expects.Any.Method(_ => _.GetBooksByCategoryId(0)).WithAnyArguments().WillReturn(bookList);
            mockBookInformationService.Expects.Any.Method(_ => _.GetBookTypeById(0)).WithAnyArguments().WillReturn(book);

            suggestionService = new SuggestionService();
            orderInformationServiceMock = _factory.CreateMock<IOrderInformationsService>();
            booksInformationServiceMock = _factory.CreateMock<IBooksInformationService>();

            suggestionService.OrderInformationService = orderInformationServiceMock.MockObject;
            suggestionService.BooksInformationService = booksInformationServiceMock.MockObject;
            //TODO!!
            //AplicationScope.GlobalSuggestionCache = null
        }
Exemplo n.º 12
0
        public void WrongCategoryIdParameterTest()
        {
            List<BookType> bookList = new List<BookType>();
            for (long i = 0; i < 10; i++)
            {
                BookType bookd = new BookType() { Id = i };
                bookList.Add(bookd);
                booksInformationServiceMock.
                    Expects.
                    Any.
                    MethodWith(x => x.GetBookTypeById(i)).WillReturn(bookd);
            }

            long wrongCategoryId = -1;

            booksInformationServiceMock.Expects.One.
                MethodWith(x => x.GetBooksByCategoryId(wrongCategoryId)).
                WillReturn(new List<BookType>());

            booksInformationServiceMock.Expects.One.
                MethodWith(x => x.GetAllBooks()).
                WillReturn(bookList);

            IEnumerable<BookType> result = suggestionService.GetSuggestionsForGuest(wrongCategoryId);
            Assert.AreEqual(result.Count(), 5);
        }
Exemplo n.º 13
0
        public void RightCategoryIdParameterTest()
        {
            List<BookType> bookList = new List<BookType>();
            var rightCatlist = new List<BookType>();
            for (long i = 0; i < 10; i++)
            {
                BookType bookd = new BookType() { Id = i, Category = new Category() { Id = i } };
                bookList.Add(bookd);
                booksInformationServiceMock.
                    Expects.
                    Any.
                    MethodWith(x => x.GetBookTypeById(i)).WillReturn(bookd);
                if (i % 2 == 0) rightCatlist.Add(bookd);
            }

            long rightCategoryId = 1;

            booksInformationServiceMock.Expects.One.
                MethodWith(x => x.GetBooksByCategoryId(rightCategoryId)).
                WillReturn(rightCatlist);

            booksInformationServiceMock.Expects.One.
                MethodWith(x => x.GetAllBooks()).
                WillReturn(bookList);

            IEnumerable<BookType> result = suggestionService.GetSuggestionsForGuest(rightCategoryId);
            Assert.AreEqual(result.Count(), rightCatlist.Count);
            foreach (var item in result)
            {
                Assert.IsTrue(rightCatlist.Contains(item));
            }
        }
Exemplo n.º 14
0
 public void UpdateQuantity(BookType bookType)
 {
     this.Session.Update(bookType);
 }
Exemplo n.º 15
0
 public void SaveBookType(BookType bookType)
 {
     this.Session.Save(bookType);
 }
        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;
        }