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)); }
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); }
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); }
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")); }
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); }
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)); } }
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); }
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); }