public void WalletService_NotLoggedUser() { //init var friendUserMoq = new Mock <IUser>(); var walletDAOMoq = new Mock <IWalletDAO>(); var userSessionMoq = WalletServiceMoqCreator.CreateIUserSessionMoq(null); var walletService = new WalletService(userSessionMoq.Object, walletDAOMoq.Object); //system-under-test walletService.GetWalletsByUser(friendUserMoq.Object); //asserts //The last instruction have to throw an UserNotLoggedInException. }
public void WalletService_IfUserFriend_WalletList() { //init var friendsWallets = new List <IWallet>() { new Wallet() }; var walletDAOMoq = new Mock <IWalletDAO>(); walletDAOMoq .Setup(w => w.FindWalletsByUser(It.IsAny <IUser>())) .Returns(friendsWallets) .Verifiable(); var anotherFriendUserMoq = new Mock <IUser>(); anotherFriendUserMoq .Setup(au => au.Equals(It.IsAny <IUser>())) .Returns(true) .Verifiable(); var friends = new List <IUser>(); friends.Add(anotherFriendUserMoq.Object); Mock <IUser> friendUserMoq = WalletServiceMoqCreator.CreateFriendIUserMoq(friends); var loggedUser = new User(); var userSessionMoq = WalletServiceMoqCreator.CreateIUserSessionMoq(loggedUser); var walletService = new WalletService(userSessionMoq.Object, walletDAOMoq.Object); //system-under-test var wallets = walletService.GetWalletsByUser(friendUserMoq.Object); //asserts Assert.AreNotEqual(0, wallets.Count); anotherFriendUserMoq.VerifyAll(); friendUserMoq.VerifyAll(); userSessionMoq.VerifyAll(); }