public void AddRole_ShouldReturn_True() { // Arrange var credentials = new Credential { Email = "*****@*****.**", Password = "******" }; var credentialEntities = new List <CredentialEntity>() { new CredentialEntity() { Email = credentials.Email, Password = credentials.Password, CredentialRoles = new List <CredentialRoleEntity>() } }; CredentialEntity updateParam = null; var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict); mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Returns(credentialEntities); mapperMock.Setup(x => x.Update(It.IsAny <CredentialEntity>())) .Callback <CredentialEntity>(entity => { updateParam = entity; }); var listener = new AccountListener(mapperMock.Object, new LoggerFactory()); var roleRequest = new RoleRequest() { Email = credentials.Email, Role = Roles.Sales }; // Act var result = listener.AddRole(new AddRoleCommand(roleRequest, "")); // Assert mapperMock.VerifyAll(); Assert.IsTrue(result); Assert.IsNotNull(updateParam); Assert.AreEqual(roleRequest.Email, updateParam.Email); Assert.AreEqual(roleRequest.Role.ToString(), updateParam.CredentialRoles.FirstOrDefault().Role.Name); }
public void AddRole_ShouldThrow_DatabaseException() { // Arrange var credentialEntities = new List <CredentialEntity>(); var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict); mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Returns(credentialEntities); var listener = new AccountListener(mapperMock.Object, new LoggerFactory()); // Act Action act = () => { listener.AddRole(new AddRoleCommand(new RoleRequest(), "")); }; // Assert var exception = Assert.ThrowsException <DatabaseException>(act); Assert.AreEqual("Something unexpected happened while updating in the database", exception.Message); mapperMock.VerifyAll(); }