示例#1
0
        public void TestCanExecute()
        {
            var repo = new ActionRepository();

            repo.AddAction("true", s => { }, s => true);
            repo.AddAction("false", s => { }, s => false);
            Assert.IsTrue(repo.CanExecute("true", null));
            Assert.IsFalse(repo.CanExecute("false", null));
            Assert.IsFalse(repo.CanExecute("notExisting", null));
        }
示例#2
0
        public void TestExecute()
        {
            int i    = 0;
            var repo = new ActionRepository();

            repo.AddAction("add", s => i++);
            repo.AddAction("add2", s => i++, s => true);
            repo.Execute("add", null);
            Assert.AreEqual(1, i);
            repo.Execute("add2", null);
            Assert.AreEqual(2, i);
        }
示例#3
0
        public void TestAddMultiTimes()
        {
            int a    = 0;
            int b    = 0;
            var repo = new ActionRepository();

            repo.AddAction("add", s => a++);
            repo.AddAction("add", s => b++, s => true);
            repo.Execute("add", null);
            Assert.AreEqual(0, a);
            Assert.AreEqual(1, b);
        }
示例#4
0
        public void TestContains()
        {
            var repo = new ActionRepository();

            repo.AddAction("Hello", s => { });
            Assert.IsTrue(repo.Contains("Hello"));
            Assert.IsTrue(repo.Contains("hello"));
            Assert.IsFalse(repo.Contains(" hello"));
        }
示例#5
0
        public void TestClear()
        {
            int b    = 0;
            var repo = new ActionRepository();

            repo.AddAction("add", s => b++, s => true);
            Assert.AreEqual(1, repo.CanExecuteCount);
            Assert.AreEqual(1, repo.ExecuteCount);
            repo.Clear();
            Assert.AreEqual(0, repo.CanExecuteCount);
            Assert.AreEqual(0, repo.ExecuteCount);
        }
示例#6
0
        public async Task <IHttpActionResult> AddAction([FromBody] Action newAction)
        {
            ActionRepository _repo = new ActionRepository();

            try
            {
                _repo.AddAction(newAction);
                return(StatusCode(HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                return(StatusCode(HttpStatusCode.BadRequest));
            }
        }
示例#7
0
        public void TestReleaseExecute()
        {
            int i       = 0;
            var repo    = new ActionRepository();
            var release = repo.AddAction("a", s => i++);

            Assert.IsTrue(repo.Contains("a"));
            repo.Execute("a", null);
            Assert.AreEqual(1, i);
            release.Release();
            Assert.IsFalse(repo.Contains("a"));
            repo.Execute("a", null);
            Assert.AreEqual(1, i);
        }
示例#8
0
        public void TestAddNull()
        {
            var repo = new ActionRepository();

            try
            {
                repo.AddAction("Hello", null);
                Assert.Fail();
            }
            catch (ArgumentNullException) { }

            Assert.IsFalse(repo.Contains("Hello"));
            repo.Execute("Hello", null);
        }