public void EditUserPersonalData()
        {
            IList<UserAccount> accounts = new List<UserAccount>();
            NMock.Actions.InvokeAction saveUser = new NMock.Actions.InvokeAction(new Action(() => accounts.Add(userAccount)));
            accountAdministrationDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);
            accountAdministrationServiceMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);

            userInformationServiceMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);
            userInformationDaoMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);

            PersonalData testPersonalData = new PersonalData();
            testPersonalData.FirstName = AuthorizationTestData.EDIT_FIRST_NAME;
            testPersonalData.LastName = AuthorizationTestData.EDIT_LAST_NAME;
            testPersonalData.PESEL = AuthorizationTestData.EDIT_PESEL;
            testPersonalData.PhoneNumber = AuthorizationTestData.EDIT_PHONE_NUMBER;
            testPersonalData.Address = new Address();
            testPersonalData.Address.Street = AuthorizationTestData.EDIT_ADDRESS_STREET;
            testPersonalData.Address.PostalCode = AuthorizationTestData.EDIT_ADDRESS_POSTAL_CODE;
            testPersonalData.Address.City = AuthorizationTestData.EDIT_ADDRESS_CITY;
            testPersonalData.Address.Country = AuthorizationTestData.EDIT_ADDRESS_COUNTRY;

            managementService.EditUserPersonalData(userAccountId, testPersonalData);

            UserAccount userAccount2 = userInformationService.GetUserAccountById(userAccountId);
            PersonalData personalData = userAccount2.PersonalData;

            Assert.AreEqual(personalData.FirstName, testPersonalData.FirstName);
            Assert.AreEqual(personalData.LastName, testPersonalData.LastName);
            Assert.AreEqual(personalData.PESEL, testPersonalData.PESEL);
            Assert.AreEqual(personalData.PhoneNumber, testPersonalData.PhoneNumber);
            Assert.AreEqual(personalData.Address.Street, testPersonalData.Address.Street);
            Assert.AreEqual(personalData.Address.PostalCode, testPersonalData.Address.PostalCode);
            Assert.AreEqual(personalData.Address.City, testPersonalData.Address.City);
            Assert.AreEqual(personalData.Address.Country, testPersonalData.Address.Country);
        }
Пример #2
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()
            {
            };
        }
Пример #3
0
        public void TestGetDeliveredOrdersByUserId()
        {
            Order order2 = new Order();

            order2.User         = userAcc;
            order2.Status       = Order.OrderState.DELIVERED;
            order2.OrderEntries = null;
            order2.SentDate     = DateTime.Now;
            order2.Id           = 10;
            userAcc.Id          = 5;
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders.Add(order2)));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order2)).Will(saveOrder);

            oms.SaveOrder(order2);

            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetDeliveredOrdersByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.Status == Order.OrderState.DELIVERED && x.User.Id == userAcc.Id));

            bool isOrderThere = false;

            foreach (var item in ois.GetDeliveredOrdersByUserId(userAcc.Id))
            {
                Assert.AreEqual(item.User.Id, userAcc.Id);
                if (item.Id == order.Id)
                {
                    isOrderThere = true;
                }
            }
            Assert.IsTrue(isOrderThere);
        }
        public void TestIdentityCardNumber()
        {
            UserAccount  userAcc      = new UserAccount();
            PersonalData personalData = new PersonalData();

            personalData.PESEL              = PESEL;
            personalData.Sex                = SEX;
            personalData.FirstName          = firstName;
            personalData.LastName           = lastName;
            personalData.IdentityCardNumber = IDCN;
            personalData.PhoneNumber        = PHONE;
            userAcc.PersonalData            = personalData;

            List <UserAccount> userAccounts = new List <UserAccount>();

            NMock.Actions.InvokeAction addUserAccounts = new NMock.Actions.InvokeAction(() => userAccounts.Add(userAcc));
            accountAdministrationDao.Expects.One.MethodWith(x => x.SaveOrUpdateUser(userAcc)).Will(addUserAccounts);

            aas.SaveOrUpdateUser(userAcc);
            userInformationService.Expects.One.MethodWith(x => x.GetUserAccountById(userAcc.Id)).WillReturn(userAcc);
            PersonalData returnedPD = sps.GetUserPersonalDataById(userAcc.Id);

            Assert.AreEqual(PESEL, returnedPD.PESEL);
            Assert.AreEqual(SEX, returnedPD.Sex);
            Assert.AreEqual(firstName, returnedPD.FirstName);
            Assert.AreEqual(lastName, returnedPD.LastName);
            Assert.AreEqual(IDCN, returnedPD.IdentityCardNumber);
            Assert.AreEqual(PHONE, returnedPD.PhoneNumber);
        }
        public void AddOrderEntryTest()
        {
            List<Order> orders = new List<Order>();
            List<BookType> bookTypeList = new List<BookType>();
            NMock.Actions.InvokeAction saveOrUpdateAction = new NMock.Actions.InvokeAction(() => orders.Add(order));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrUpdateAction);

            bool isInList = false;
            order.OrderEntries = new List<OrderEntry>();
            oms.CreateNewOrder(order);
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(orders.First(x => x.Id == order.Id));

            getOrder = ois.GetOrderById(order.Id);

            NMock.Actions.InvokeAction saveBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook)));
            storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveBookType(testBook)).Will(saveBookType);

            sms.SaveBookType(testBook);
            booksInformationServiceMock.Expects.Any.MethodWith(x => x.GetBookTypeById(testBook.Id)).WillReturn(bookTypeList.FirstOrDefault(x => x.Id == testBook.Id));

            oms.AddOrderEntry(order, testBook.Id, TEST_AMOUNT);

            foreach (var item in order.OrderEntries)
            {
                if (item.Amount.Equals(TEST_AMOUNT) &&
                    item.BookType.Equals(testBook) &&
                    item.Price.Equals(testBook.Price)) isInList = true;
            };

            Assert.IsTrue(isInList);
        }
Пример #6
0
        public void SaveBookTypeNullTest()
        {
            NMock.Actions.InvokeAction save = new NMock.Actions.InvokeAction(ThrowNull);

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

            sms.SaveBookType(null);
        }
Пример #7
0
        public void CreateNewOrderTestOrdered()
        {
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(
                new Action(() => getOrder = order));

            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(getOrder);
            oms.CreateNewOrder(order);
            getOrder = ois.GetOrderById(order.Id);
            Assert.IsNotNull(getOrder.Status.Equals(Order.OrderState.ORDERED));
        }
 public void TestCompleteOrder()
 {
     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.First(x => x.Id == order.Id));
     orderManagementDaoMock.Expects.One.MethodWith(x => x.SaveOrUpdate(order)).Will(createOrder);
     sps.CompleteOrder(order.Id);
     Order testedOrder = ois.GetOrderById(order.Id);
     Assert.AreEqual(Order.OrderState.DELIVERED, testedOrder.Status);
 }
Пример #9
0
        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 TestMarkOrderAsInProgress()
        {
            orders = new List <Order>();
            NMock.Actions.InvokeAction saveOrUpdateAction = new NMock.Actions.InvokeAction(() => orders.Add(order));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrUpdateAction);
            oms.CreateNewOrder(order);
            orderInformationsDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(orders.First(x => x.Id == order.Id));

            sps.MarkOrderAsInProgress(order.Id);
            Order testedOrder = ois.GetOrderById(order.Id);

            Assert.AreEqual(Order.OrderState.SENT, testedOrder.Status);
        }
Пример #11
0
        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 TestCompleteOrder()
        {
            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.First(x => x.Id == order.Id));
            orderManagementDaoMock.Expects.One.MethodWith(x => x.SaveOrUpdate(order)).Will(createOrder);
            sps.CompleteOrder(order.Id);
            Order testedOrder = ois.GetOrderById(order.Id);

            Assert.AreEqual(Order.OrderState.DELIVERED, testedOrder.Status);
        }
Пример #13
0
        public void AddCategoryNullNameTest()
        {
            NMock.Actions.InvokeAction saveCategory = new NMock.Actions.InvokeAction(ThrowNull);

            storehouseManagementDaoMock.Expects.Any.
            MethodWith(x => x.SaveCategory(new Category()
            {
                Name = null
            })).
            Will(saveCategory);

            sms.AddCategory(null);
        }
Пример #14
0
        public void TestGetOrderById()
        {
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders = new List <Order>()
            {
                order
            }));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            oms.CreateNewOrder(order);
            Order testedOrder = ois.GetOrderById(order.Id);

            Assert.AreEqual(testedOrder.Id, order.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);
        }
Пример #16
0
        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);
        }
Пример #17
0
        public void MarkOrderSendTest()
        {
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(
                new Action(() => getOrder = order));

            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(getOrder);
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(getOrder);

            oms.CreateNewOrder(order);
            orderManagementDaoMock.Expects.One.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            oms.MarkOrderSent(order.Id);
            getOrder = ois.GetOrderById(order.Id);
            Assert.IsTrue(getOrder.Status.Equals(Order.OrderState.SENT));
        }
        public void CompleteOrderTest()
        {
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(
              new Action(() => getOrder = order));

            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(getOrder);
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(getOrder);

            oms.CreateNewOrder(order);
            oms.CompleteOrder(order.Id);
            orderManagementDaoMock.Expects.One.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            getOrder = ois.GetOrderById(order.Id);
            Assert.IsTrue(getOrder.Status.Equals(Order.OrderState.DELIVERED));
        }
Пример #19
0
        public void RemoveUser()
        {
            IList <UserAccount> accounts = new List <UserAccount>();

            NMock.Actions.InvokeAction saveUser = new NMock.Actions.InvokeAction(new Action(() => accounts.Add(userAccount)));
            accountAdministrationDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);
            accountAdministrationServiceMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);

            userInformationServiceMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);
            userInformationDaoMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);
            accounts.Add(userAccount);
            managementService.RemoveUser(userAccountId);
            UserAccount userAccount2 = userInformationService.GetUserAccountById(userAccountId);

            Assert.AreEqual(userAccount2.AccountStatus, SpringMvc.Models.POCO.UserAccount.Status.REMOVED);
        }
        public void ChangePassword()
        {
            IList<UserAccount> accounts = new List<UserAccount>();
            NMock.Actions.InvokeAction saveUser = new NMock.Actions.InvokeAction(new Action(() => accounts.Add(userAccount)));
            accountAdministrationDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);
            accountAdministrationServiceMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);

            userInformationServiceMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);
            userInformationDaoMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);

            authorizationServiceMock.Expects.Any.MethodWith(x => x.EncryptPassword(oldPassword)).WillReturn(oldPassword);
            authorizationServiceMock.Expects.Any.MethodWith(x => x.EncryptPassword(newPassword)).WillReturn(newPassword);

            managementService.ChangePassword(userAccountId, oldPassword, newPassword);
            UserAccount userAccount2 = userInformationService.GetUserAccountById(userAccountId);
            Assert.AreEqual(userAccount2.Password, newPassword);
        }
Пример #21
0
        public void AddBookTypeWrongQuantityTest()
        {
            NMock.Actions.InvokeAction save = new NMock.Actions.InvokeAction(ThrowNull);
            var book = new BookType()
            {
                Authors     = "",
                Category    = category,
                Image       = image,
                Price       = 0,
                QuantityMap = quantityMap,
                Title       = ""
            };

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

            sms.AddBookType("", "", 0, -1, category, "");
        }
        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, "");
        }
Пример #23
0
        public void ChangePassword()
        {
            IList <UserAccount> accounts = new List <UserAccount>();

            NMock.Actions.InvokeAction saveUser = new NMock.Actions.InvokeAction(new Action(() => accounts.Add(userAccount)));
            accountAdministrationDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);
            accountAdministrationServiceMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);

            userInformationServiceMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);
            userInformationDaoMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);

            authorizationServiceMock.Expects.Any.MethodWith(x => x.EncryptPassword(oldPassword)).WillReturn(oldPassword);
            authorizationServiceMock.Expects.Any.MethodWith(x => x.EncryptPassword(newPassword)).WillReturn(newPassword);

            managementService.ChangePassword(userAccountId, oldPassword, newPassword);
            UserAccount userAccount2 = userInformationService.GetUserAccountById(userAccountId);

            Assert.AreEqual(userAccount2.Password, newPassword);
        }
Пример #24
0
        public void TestGetUndeliveredOrders()
        {
            order.Status = Order.OrderState.ORDERED;
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders.Add(order)));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            oms.CreateNewOrder(order);

            orderInformationDaoMock.Expects.Any.Method(x => x.GetUndeliveredOrders()).WillReturn(orders.Where(x => x.Status != Order.OrderState.DELIVERED));

            bool isOrderThere = false;

            foreach (var item in ois.GetUndeliveredOrders())
            {
                if (item.Status != Order.OrderState.DELIVERED)
                {
                    isOrderThere = true;
                }
            }
            Assert.IsTrue(isOrderThere);
        }
Пример #25
0
        public void CheckedLoggedAccount()
        {
            authorizationService.AuthorizationDao = authorizationDaoMock.MockObject;
            authorizationService.LogEventsDao     = logInOutEventDaoMock.MockObject;

            UserAccount user1 = new UserAccount();

            user1.Password = password;
            user1.Login    = login;
            Assert.IsNotNull(user1);
            UserAccount user2 = new UserAccount();

            user2.Password = password2;
            user2.Login    = login2;
            Assert.IsNotNull(user2);

            user1.Password = Encrypt(user1.Password);
            user2.Password = Encrypt(user2.Password);

            List <UserAccount> loggedUsers = new List <UserAccount>();

            NMock.Actions.InvokeAction akcja2 = new NMock.Actions.InvokeAction(new Action(() => loggedUsers.Add(user2)));
            NMock.Actions.InvokeAction akcja  = new NMock.Actions.InvokeAction(new Action(() => loggedUsers.Add(user1)));

            logInOutEventDaoMock.Expects.Any.Method(x => x.SaveFailedLogInEventForUser(new UserAccount(), "localhost"));
            authorizationDaoMock.Expects.Any.MethodWith(x => x.LoginUser(login, password)).Will(akcja, new NMock.Actions.ReturnAction <UserAccount>(user1)); // WillReturn(user1);

            logInOutEventDaoMock.Expects.Any.Method(x => x.SaveFailedLogInEventForUser(new UserAccount(), "localhost"));
            authorizationDaoMock.Expects.Any.MethodWith(x => x.LoginUser(login2, password2)).Will(akcja2, new NMock.Actions.ReturnAction <UserAccount>(user2)); // WillReturn(user2);

            authorizationService.LoginUser(login, password);
            authorizationService.LoginUser(login2, password2);

            authorizationDaoMock.Expects.Any.Method(x => x.GetLoggedUsers()).WillReturn(loggedUsers);

            IEnumerable <UserAccount> LoggedAccounts = authorizationService.AllLoggedUserAccounts;

            Assert.AreEqual((new LinkedList <UserAccount>(LoggedAccounts)).Count, 2);
        }
Пример #26
0
        public void TestGetOrdersByUserId()
        {
            orders     = new List <Order>();
            order.User = userAcc;
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders.Add(order)));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            oms.CreateNewOrder(order);

            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrdersByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.User.Id == userAcc.Id));

            bool isOrderThere = false;

            foreach (var item in ois.GetOrdersByUserId(userAcc.Id))
            {
                if (item.Id == order.Id)
                {
                    isOrderThere = true;
                }
            }
            Assert.IsTrue(isOrderThere);
        }
        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);
        }
Пример #28
0
        public void TestAddBookType()
        {
            testBook.Id = 0;
            NMock.Actions.InvokeAction saveBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook)));
            storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveBookType(testBook)).Will(saveBookType);
            booksInformationDaoMock.Expects.One.MethodWith <IEnumerable <BookType> >(x => x.GetAllBooks())
            .WillReturn(bookTypeList);

            sms.AddBookType(testBook.Title, testBook.Authors, testBook.Price, TEST_QUANTITY, testBook.Category, null);
            IEnumerable <BookType> list = bis.GetAllBooks();
            bool isInList = false;

            foreach (var item in list)
            {
                if (item.Title.Equals(testBook.Title) &&
                    item.Authors.Equals(testBook.Authors) &&
                    item.Category.Name.Equals(testBook.Category.Name))
                {
                    isInList = true;
                }
            }
            Assert.IsTrue(isInList);
        }
Пример #29
0
        public void AddOrderEntryTest()
        {
            List <Order>    orders       = new List <Order>();
            List <BookType> bookTypeList = new List <BookType>();

            NMock.Actions.InvokeAction saveOrUpdateAction = new NMock.Actions.InvokeAction(() => orders.Add(order));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrUpdateAction);

            bool isInList = false;

            order.OrderEntries = new List <OrderEntry>();
            oms.CreateNewOrder(order);
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(orders.First(x => x.Id == order.Id));

            getOrder = ois.GetOrderById(order.Id);

            NMock.Actions.InvokeAction saveBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook)));
            storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveBookType(testBook)).Will(saveBookType);

            sms.SaveBookType(testBook);
            booksInformationServiceMock.Expects.Any.MethodWith(x => x.GetBookTypeById(testBook.Id)).WillReturn(bookTypeList.FirstOrDefault(x => x.Id == testBook.Id));

            oms.AddOrderEntry(order, testBook.Id, TEST_AMOUNT);

            foreach (var item in order.OrderEntries)
            {
                if (item.Amount.Equals(TEST_AMOUNT) &&
                    item.BookType.Equals(testBook) &&
                    item.Price.Equals(testBook.Price))
                {
                    isInList = true;
                }
            }
            ;

            Assert.IsTrue(isInList);
        }
Пример #30
0
        public void EditUserPersonalData()
        {
            IList <UserAccount> accounts = new List <UserAccount>();

            NMock.Actions.InvokeAction saveUser = new NMock.Actions.InvokeAction(new Action(() => accounts.Add(userAccount)));
            accountAdministrationDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);
            accountAdministrationServiceMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);

            userInformationServiceMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);
            userInformationDaoMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);

            PersonalData testPersonalData = new PersonalData();

            testPersonalData.FirstName          = AuthorizationTestData.EDIT_FIRST_NAME;
            testPersonalData.LastName           = AuthorizationTestData.EDIT_LAST_NAME;
            testPersonalData.PESEL              = AuthorizationTestData.EDIT_PESEL;
            testPersonalData.PhoneNumber        = AuthorizationTestData.EDIT_PHONE_NUMBER;
            testPersonalData.Address            = new Address();
            testPersonalData.Address.Street     = AuthorizationTestData.EDIT_ADDRESS_STREET;
            testPersonalData.Address.PostalCode = AuthorizationTestData.EDIT_ADDRESS_POSTAL_CODE;
            testPersonalData.Address.City       = AuthorizationTestData.EDIT_ADDRESS_CITY;
            testPersonalData.Address.Country    = AuthorizationTestData.EDIT_ADDRESS_COUNTRY;

            managementService.EditUserPersonalData(userAccountId, testPersonalData);

            UserAccount  userAccount2 = userInformationService.GetUserAccountById(userAccountId);
            PersonalData personalData = userAccount2.PersonalData;

            Assert.AreEqual(personalData.FirstName, testPersonalData.FirstName);
            Assert.AreEqual(personalData.LastName, testPersonalData.LastName);
            Assert.AreEqual(personalData.PESEL, testPersonalData.PESEL);
            Assert.AreEqual(personalData.PhoneNumber, testPersonalData.PhoneNumber);
            Assert.AreEqual(personalData.Address.Street, testPersonalData.Address.Street);
            Assert.AreEqual(personalData.Address.PostalCode, testPersonalData.Address.PostalCode);
            Assert.AreEqual(personalData.Address.City, testPersonalData.Address.City);
            Assert.AreEqual(personalData.Address.Country, testPersonalData.Address.Country);
        }
Пример #31
0
        public void CheckedLoggedAccount()
        {
            authorizationService.AuthorizationDao = authorizationDaoMock.MockObject;
            authorizationService.LogEventsDao = logInOutEventDaoMock.MockObject;

            UserAccount user1 = new UserAccount();
            user1.Password = password;
            user1.Login = login;
            Assert.IsNotNull(user1);
            UserAccount user2 = new UserAccount();
            user2.Password = password2;
            user2.Login = login2;
            Assert.IsNotNull(user2);

            user1.Password = Encrypt(user1.Password);
            user2.Password = Encrypt(user2.Password);

            List<UserAccount> loggedUsers = new List<UserAccount>();

            NMock.Actions.InvokeAction akcja2 = new NMock.Actions.InvokeAction( new Action( () => loggedUsers.Add(user2)));
            NMock.Actions.InvokeAction akcja = new NMock.Actions.InvokeAction(new Action(() => loggedUsers.Add(user1)));

            logInOutEventDaoMock.Expects.Any.Method(x => x.SaveFailedLogInEventForUser(new UserAccount(), "localhost"));
            authorizationDaoMock.Expects.Any.MethodWith(x => x.LoginUser(login, password)).Will(akcja, new NMock.Actions.ReturnAction<UserAccount>(user1)); // WillReturn(user1);

            logInOutEventDaoMock.Expects.Any.Method(x => x.SaveFailedLogInEventForUser(new UserAccount(), "localhost"));
            authorizationDaoMock.Expects.Any.MethodWith(x => x.LoginUser(login2, password2)).Will(akcja2, new NMock.Actions.ReturnAction<UserAccount>(user2)); // WillReturn(user2);

            authorizationService.LoginUser(login, password);
            authorizationService.LoginUser(login2, password2);

            authorizationDaoMock.Expects.Any.Method(x => x.GetLoggedUsers()).WillReturn(loggedUsers);

            IEnumerable<UserAccount> LoggedAccounts = authorizationService.AllLoggedUserAccounts;
            Assert.AreEqual((new LinkedList<UserAccount>(LoggedAccounts)).Count, 2);
        }
        public void TestGetDeliveredOrdersByUserId()
        {
            Order order2 = new Order();
            order2.User = userAcc;
            order2.Status = Order.OrderState.DELIVERED;
            order2.OrderEntries = null;
            order2.SentDate = DateTime.Now;
            order2.Id = 10;
            userAcc.Id = 5;
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders.Add(order2)));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order2)).Will(saveOrder);

            oms.SaveOrder(order2);

            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetDeliveredOrdersByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.Status == Order.OrderState.DELIVERED && x.User.Id == userAcc.Id));

            bool isOrderThere = false;
            foreach (var item in ois.GetDeliveredOrdersByUserId(userAcc.Id))
            {
                Assert.AreEqual(item.User.Id, userAcc.Id);
                if (item.Id == order.Id) isOrderThere = true;
            }
            Assert.IsTrue(isOrderThere);
        }
        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 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);
        }
        public void TestIdentityCardNumber()
        {
            UserAccount userAcc = new UserAccount();
            PersonalData personalData = new PersonalData();
            personalData.PESEL = PESEL;
            personalData.Sex = SEX;
            personalData.FirstName = firstName;
            personalData.LastName = lastName;
            personalData.IdentityCardNumber = IDCN;
            personalData.PhoneNumber = PHONE;
            userAcc.PersonalData = personalData;

            List<UserAccount> userAccounts = new List<UserAccount>();
            NMock.Actions.InvokeAction addUserAccounts = new NMock.Actions.InvokeAction(() => userAccounts.Add(userAcc));
            accountAdministrationDao.Expects.One.MethodWith(x => x.SaveOrUpdateUser(userAcc)).Will(addUserAccounts);

            aas.SaveOrUpdateUser(userAcc);
            userInformationService.Expects.One.MethodWith(x => x.GetUserAccountById(userAcc.Id)).WillReturn(userAcc);
            PersonalData returnedPD = sps.GetUserPersonalDataById(userAcc.Id);
            Assert.AreEqual(PESEL, returnedPD.PESEL);
            Assert.AreEqual(SEX, returnedPD.Sex);
            Assert.AreEqual(firstName, returnedPD.FirstName);
            Assert.AreEqual(lastName, returnedPD.LastName);
            Assert.AreEqual(IDCN, returnedPD.IdentityCardNumber);
            Assert.AreEqual(PHONE, returnedPD.PhoneNumber);
        }
        public void RemoveUser()
        {
            IList<UserAccount> accounts = new List<UserAccount>();
            NMock.Actions.InvokeAction saveUser = new NMock.Actions.InvokeAction(new Action(() => accounts.Add(userAccount)));
            accountAdministrationDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);
            accountAdministrationServiceMock.Expects.Any.MethodWith(x => x.SaveOrUpdateUser(userAccount)).Will(saveUser);

            userInformationServiceMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);
            userInformationDaoMock.Expects.Any.MethodWith(x => x.GetUserAccountById(userAccount.Id)).WillReturn(userAccount);
            accounts.Add(userAccount);
            managementService.RemoveUser(userAccountId);
            UserAccount userAccount2 = userInformationService.GetUserAccountById(userAccountId);
            Assert.AreEqual(userAccount2.AccountStatus, SpringMvc.Models.POCO.UserAccount.Status.REMOVED);
        }
        public void TestGetOrderById()
        {
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders = new List<Order>() { order }));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            oms.CreateNewOrder(order);
            Order testedOrder = ois.GetOrderById(order.Id);
            Assert.AreEqual(testedOrder.Id, order.Id);
        }
        public void TestGetUndeliveredOrdersByUserId()
        {
            order.User = userAcc;
            order.Status = Order.OrderState.ORDERED;
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders.Add(order)));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            oms.CreateNewOrder(order);

            orderInformationDaoMock.Expects.Any.Method(x => x.GetUndeliveredOrders()).WillReturn(orders.Where(x => x.Status != Order.OrderState.DELIVERED && x.User.Id == userAcc.Id));

            bool isOrderThere = false;
            foreach (var item in ois.GetUndeliveredOrdersByUserId(userAcc.Id))
            {
                Assert.AreEqual(item.User.Id, userAcc.Id);
                if (item.Id == order.Id) isOrderThere = true;
            }
            Assert.IsTrue(isOrderThere);
        }
        public void TestGetOrdersByUserId()
        {
            orders = new List<Order>();
            order.User = userAcc;
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(new Action(() => orders.Add(order)));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);

            oms.CreateNewOrder(order);

            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrdersByUserId(userAcc.Id)).WillReturn(orders.Where(x => x.User.Id == userAcc.Id));

            bool isOrderThere = false;
            foreach (var item in ois.GetOrdersByUserId(userAcc.Id))
            {
                if (item.Id == order.Id) isOrderThere = true;
            }
            Assert.IsTrue(isOrderThere);
        }
        public void TestMarkOrderAsInProgress()
        {
            orders = new List<Order>();
            NMock.Actions.InvokeAction saveOrUpdateAction = new NMock.Actions.InvokeAction(() => orders.Add(order));
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrUpdateAction);
            oms.CreateNewOrder(order);
            orderInformationsDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(orders.First(x => x.Id == order.Id));

            sps.MarkOrderAsInProgress(order.Id);
            Order testedOrder = ois.GetOrderById(order.Id);
            Assert.AreEqual(Order.OrderState.SENT, testedOrder.Status);
        }
        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 TestAddBookType()
        {
            testBook.Id = 0;
            NMock.Actions.InvokeAction saveBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook)));
            storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveBookType(testBook)).Will(saveBookType);
            booksInformationDaoMock.Expects.One.MethodWith<IEnumerable<BookType>>(x => x.GetAllBooks())
               .WillReturn(bookTypeList);

            sms.AddBookType(testBook.Title, testBook.Authors, testBook.Price, TEST_QUANTITY, testBook.Category, null);
            IEnumerable<BookType> list = bis.GetAllBooks();
            bool isInList = false;
            foreach (var item in list)
            {
                if (item.Title.Equals(testBook.Title) &&
                    item.Authors.Equals(testBook.Authors) &&
                    item.Category.Name.Equals(testBook.Category.Name)) isInList = true;
            }
            Assert.IsTrue(isInList);
        }
        public void SaveCategoryNullTest()
        {
            NMock.Actions.InvokeAction saveCategory = new NMock.Actions.InvokeAction(ThrowNull);

            storehouseManagementDaoMock.Expects.Any.
                MethodWith(x => x.SaveCategory(null)).
                Will(saveCategory);

            sms.SaveCategory(null);
        }
        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);
        }
        public void SaveOrderTest()
        {
            NMock.Actions.InvokeAction saveOrder = new NMock.Actions.InvokeAction(
            new Action(() => getOrder = order));

            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);
            orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrder);
            orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(getOrder);

            oms.CreateNewOrder(order);
            oms.SaveOrder(order);
            getOrder = ois.GetOrderById(order.Id);
            Assert.IsNotNull(getOrder);
        }