示例#1
0
        public static Mock<IJavascriptProxy> addMoqsFor_IJavascriptProxy_Libraries(this  Mock<IJavascriptProxy> javascriptProxy, TM_Moq_Database tmDb)
        {
            //GetLibraries(...)
            javascriptProxy.Setup((proxy) => proxy.GetLibraries())
                           .Returns(tmDb.getLibraries());
            //GetFolders(...)
            javascriptProxy.Setup((proxy) => proxy.GetFolders(It.IsAny<Guid>()))
                           .Returns((Guid libraryId) => tmDb.Folders_by_Library[libraryId.str()]);

            //GetGuidanceItemsInView(...)
            javascriptProxy.Setup((proxy) => proxy.GetGuidanceItemsInView(It.IsAny<Guid>()))
                           .Returns((Guid viewId) => tmDb.GuidanceItems_in_View[viewId.str()]);

            //GetGuidanceItemsInViews(...)
            javascriptProxy.Setup((proxy) => proxy.GetGuidanceItemsInViews(It.IsAny<List<Guid>>()))
                           .Returns((List<Guid> viewIds)
                                =>{
                                        var guidanceItems = new List<TM_GuidanceItem>();
                                        foreach(var viewId in viewIds)
                                            guidanceItems.AddRange(tmDb.GuidanceItems_in_View[viewId.str()]);
                                        return guidanceItems;
                                  });
            //GetGuidanceItemHtml(...)
            javascriptProxy.Setup((proxy) => proxy.GetGuidanceItemHtml(It.IsAny<Guid>()))
                           .Returns((Guid guidanceId) => tmDb.GuidanceItemsHtml[guidanceId.str()]);

            //GetAllGuidanceItems(...)
            javascriptProxy.Setup((proxy) => proxy.GetAllGuidanceItems())
                           .Returns(()
                                =>{
                                        var allGuidanceItems = new List<TM_GuidanceItem>();
                                        foreach(var guidanceItems in tmDb.GuidanceItems_in_Library.Values)
                                            allGuidanceItems.AddRange(guidanceItems);
                                        return allGuidanceItems;
                                  });

            //GetGuidanceItemsInLibrary(...)
            javascriptProxy.Setup((proxy) => proxy.GetGuidanceItemsInLibrary(It.IsAny<Guid>()))
                           .Returns((Guid libraryId) => tmDb.GuidanceItems_in_Library[libraryId.str()]);
            return javascriptProxy;
        }
示例#2
0
        public static Mock<IJavascriptProxy> addMoqsFor_IJavascriptProxy_User(this Mock<IJavascriptProxy> javascriptProxy, TM_Moq_Database tmDb)
        {
            //GetUser_byName(name)
            javascriptProxy.Setup((proxy) => proxy.GetUser_byName(It.IsAny<String>()))
                           .Returns((string name)=> tmDb.TMUsers.user(name)  );

            //GetUser_byID(id)
            javascriptProxy.Setup((proxy) => proxy.GetUser_byID(It.IsAny<int>()))
                           .Returns((int id)=> tmDb.TMUsers.user(id));

            //GetUsers()
            javascriptProxy.Setup((proxy) => proxy.GetUsers())
                           .Returns(tmDb.TMUsers);

            //CreateUser(...)
            javascriptProxy.Setup((proxy) => proxy.CreateUser(It.IsAny<NewUser>()))
                           .Returns((NewUser newUser)
                           	  =>{
                           			if (newUser.username.inValid() ||  tmDb.TMUsers.user(newUser.username).notNull())
                           				return 0;
                           			return tmDb.newUser(newUser.username, newUser.passwordHash, newUser.email, newUser.firstname, newUser.lastname, newUser.note);
                                });

            //CreateUsers(...)
            //CreateUser(...)
            javascriptProxy.Setup((proxy) => proxy.CreateUsers(It.IsAny<List<NewUser>>()))
                           .Returns((List<NewUser> newUsers)
                           		=>{
                           			var newUsersIds = new List<int>();
                                    foreach(var newUser in newUsers)
                                        newUsersIds.Add(javascriptProxy.Object.CreateUser(newUser));
                                    return newUsersIds;
                           		  });
            //DeleteUser(...)
            javascriptProxy.Setup((proxy) => proxy.DeleteUser(It.IsAny<int>()))
                           .Returns((int id)=> tmDb.TMUsers.delete(id));

            //DeleteUsers(...)
            javascriptProxy.Setup((proxy) => proxy.DeleteUsers(It.IsAny<List<int>>()))
                           .Returns((List<int> userIds)
                           		=>{
                           			var results = new List<bool>();
                                    foreach(var userId in userIds)
                                        results.Add(javascriptProxy.Object.DeleteUser(userId));
                                    return results;
                           		  });

            //UpdateUser(...)
            //			javascriptProxy.Setup((proxy) => proxy.UpdateUser(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<string>(),It.IsAny<string>()))
            //						   .Returns((int userId, string email, string firstname, string lastname)=> tmDb.TMUsers.updateUser(userId, email, firstname, lastname));

            return javascriptProxy;
        }
示例#3
0
        public static Mock<IJavascriptProxy> addMoqsFor_IJavascriptProxy_Session(this  Mock<IJavascriptProxy> javascriptProxy, TM_Moq_Database tmDb)
        {
            //Login(...)
            javascriptProxy.Setup((proxy) => proxy.Login(It.IsAny<String>(), It.IsAny<String>()))
                           .Returns((string username, string passwordHash)=>  tmDb.login(username,passwordHash));
            //Login_PwdInClearText(...)
            javascriptProxy.Setup((proxy) => proxy.Login_PwdInClearText(It.IsAny<String>(), It.IsAny<String>()))
                           .Returns((string username, string password)=>  tmDb.login_PwdInClearText(username,password));

            return javascriptProxy;
        }
示例#4
0
        public static IJavascriptProxy createMoqDatabaseObject()
        {
            var tmDb = new TM_Moq_Database();

            var javascriptProxy = new Mock<IJavascriptProxy>();

            //ProxyType
            javascriptProxy.Setup(proxy => proxy.ProxyType)
                           .Returns("Moq Object");

            //GetTime()
            javascriptProxy.Setup(proxy => proxy.GetTime())
                           .Returns("(Via Moq) 01/11/2222 01:02:03 PM");

            javascriptProxy .addMoqsFor_IJavascriptProxy_User(tmDb)
                            .addMoqsFor_IJavascriptProxy_Session(tmDb)
                            .addMoqsFor_IJavascriptProxy_Libraries(tmDb);

            return javascriptProxy.Object;
        }