Example #1
0
        public void Setup()
        {
            adminService = new ManageStoreService();
            storeOne = stores[0];
            storeTwo = stores[1];

            adminService.context = mockDbContext.Object;
        }
 /// <summary>
 /// Find a Store which is owned by the ownerId
 /// </summary>
 /// <param name="ownerId"> Presumed store owner</param>
 /// <returns></returns>
 public Store OwnedStore(int ownerId)
 {
     // Create a bare store
     Store store = new Store();
     store.UserId = ownerId;
     // createList of stores
        // IDbSet<Store> storeOwned = context.Stores();
     List<Store> stores = GetStores(ownerId);
     if (stores.Count > 0)
     {
         store = stores[0];
     }
     return store;
 }
 /// <summary>
 /// Edits the Discount to the Store
 /// </summary>
 /// <param name="changesToStore"></param>
 /// <returns></returns>
 public Store EditStore(Store ownedStore, Store changesToStore, out bool success)
 {
     success = false;
     // grab store with the StoreId of the one wanting to change.
     if (changesToStore.DiscountRate > 0 && changesToStore.DiscountRate < 100)
     {
         // change the Discount rate
         ownedStore.DiscountRate = changesToStore.DiscountRate;
         context.SaveChanges();
         success = true;
     }
     // return store with new discountRate
     return ownedStore;
 }
        /// <summary>
        /// Create a store, sets store owner as Owner, if person
        /// already owns a store, return null
        /// </summary>
        /// <param name="owner">User that is a StoreOwner</param>
        /// <returns>store created or null</returns>
        public Store CreateStore(User owner)
        {
            Store newStore = null;
            List<Store> store = FindStore(owner);
            // check that no stores are returned and owner.RoleId is still attached to the proper id#
            if (store.Count == 0 && owner.RoleId == (int)Role.StoreOwner)
            {
                // set newStore
                newStore = new Store();
                // create store properties
                newStore.Name = owner.LastName + "'s";
                newStore.UserId = owner.UserId;
                newStore.DiscountRate = 0;

                RuleEngineService ruleEngineService = new RuleEngineService();
                System.Workflow.Activities.Rules.RuleSet ruleset = ruleEngineService.GetRulesByName("TestStore");
                ruleEngineService.RunRules<Store>(newStore, ruleset);

               // context.Stores().Add(newStore);
                // save changes to objects tied to the context
                context.SaveChanges();
            }
            return newStore;
        }
        public void CreateStoreStoreOwnerPassTest()
        {
            store = new Store();
            userTest.RoleId = 2;

            // set the entity
            mockManageUserService.Object.context = mockIPracticeGDVPDao.Object;
            // return new store object on factory create
            mockStoreFactory.Setup(m => m.Create<Store>()).Returns(store);

            mockIPracticeGDVPDao.Setup(m => m.Stores()).Returns(mockDbSetStore.Object);
            // return empty list, user currently owns no stores!
            mockManageUserService.Setup(m => m.FindStore(userTest)).Returns(new List<Store>());
            // object expected
            Assert.AreSame(store, mockManageUserService.Object.CreateStore(userTest));

            // verify all methods are called
            mockIPracticeGDVPDao.Verify(m => m.SaveChanges());
            mockDbSetStore.Verify(m => m.Add(store));
            // verify new store stored contains same UserId
            Assert.AreEqual(userTest.UserId, store.UserId);
        }
Example #6
0
 public static List<Store> CreateStores(int createNTables)
 {
     List<Store> stores = new List<Store>();
     for (int index = 0; index < createNTables; index++)
     {
         Store store = new Store();
         store.DiscountRate = index + 1;
         store.Name = "CommanderPaul" +createNTables;
         store.StoreId = index + 1;
         store.StoreInventories = new List<StoreInventory>();
         store.Transactions = new List<Transaction>();
         store.UserId = index;
         store.UserProfile = UserTest.CreateUser();
         stores.Add(store);
     }
     return stores;
 }
 public ActionResult Index(Store storeToChange)
 {
     bool success;
     Store store = adminService.EditStore(adminService.OwnedStore(UserAuth.Current.ActingUser.UserId), storeToChange, out success);
     return Json(new {DiscountRate = store.DiscountRate, Name = store.Name, StoreId = store.StoreId, Success = success});
 }
 public void Setup()
 {
     // set mocks
     dao = new Mock<IPracticeGDVPDao>();
     factory = new Mock<IFactory>();
     auth = new Mock<IUserAuth>();
     context = new Mock<IHttpContext>();
     session = new Mock<ISession>();
     // set factory
     factory.Setup(f => f.Create<PracticeGDVPDao, IPracticeGDVPDao>()).Returns(dao.Object);
     factory.Setup(f => f.Create<ContextWrapper,IHttpContext>(HttpContext.Current)).Returns(context.Object);
     context.SetupGet(c => c.Session).Returns(session.Object);
     session.SetupGet(s => s["__UserAuth"]).Returns(auth.Object);
     Factory.Instance = factory.Object;
     // create instance of controller
     manageStoreController = new ManageStoreController();
     // set stores
     stores = StoreTest.CreateStores(2);
     storeOne = stores[0];
     storeTwo = stores[1];
 }