public void GetAccounts_RaisesWebUiException() { _accountServiceMock.Setup(m => m.GetList(It.IsAny <Expression <Func <Account, bool> > >())).Throws <ServiceException>(); var target = new NavLeftController(_accountServiceMock.Object, null); target.GetAccounts(new WebUser()); }
public void Can_Get_Accounts() { var mock = new Mock <IAccountService>(); mock.Setup(m => m.GetList()).Returns(new List <Account>() { new Account() { AccountID = 1, AccountName = "Acc 1", Cash = 100M, UserId = "1" }, new Account() { AccountID = 2, AccountName = "Acc 2", Cash = 200M, UserId = "1" }, new Account() { AccountID = 3, AccountName = "Acc 3", Cash = 1000M, UserId = "1" }, }); var target = new NavLeftController(mock.Object, null); var result = (((PartialViewResult)target.GetAccounts(new WebUser() { Id = "1" })).Model as IEnumerable <Account>)?.ToList(); Assert.IsNotNull(result); Assert.AreEqual(result?.Count, 3); Assert.AreEqual(result?[0].AccountID, 1); Assert.AreEqual(result?[1].AccountID, 2); Assert.AreEqual(result?[2].AccountID, 3); }
public void GetAccounts_RaisesWebUiException() { var mock = new Mock <IAccountService>(); mock.Setup(m => m.GetList()).Throws <ServiceException>(); var target = new NavLeftController(mock.Object, null); target.GetAccounts(new WebUser()); }
public void Can_Get_Accounts_By_UserId() { var userId = "1"; _accountServiceMock.Setup(m => m.GetList(It.IsAny <Expression <Func <Account, bool> > >())).Returns(_accounts.Where(x => x.UserId == userId)); var target = new NavLeftController(_accountServiceMock.Object, null); var result = (((PartialViewResult)target.GetAccounts(new WebUser() { Id = "1" })).Model as IEnumerable <Account>)?.ToList(); Assert.IsNotNull(result); Assert.AreEqual(3, result?.Count); Assert.AreEqual(1, result?[0].AccountID); Assert.AreEqual(2, result?[1].AccountID); Assert.AreEqual(3, result?[2].AccountID); }