public void Register_ShouldReturn_RegisterResultEmailInUse() { // Arrange var credentialEntities = new List <CredentialEntity> { new CredentialEntityBuilder().SetId(1).SetEmail("*****@*****.**").SetPassword("42818AAC3AEFB82B8A9E136A40657A0DD8582A0C6C544755806BC20E9D32D4E3").SetDummyRole("Gebruikert").Create(), }; 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()); var credentials = new Credential { Email = "*****@*****.**", Password = "******" }; // Act var result = listener.Register(new RegisterCommand(credentials, "")); // Assert mapperMock.VerifyAll(); Assert.AreEqual(RegisterResult.EmailInUse, result); }
public void Register_ShouldReturn_RegisterResultOk() { // 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); mapperMock.Setup(x => x.Insert(It.IsAny <CredentialEntity>())).Returns(new CredentialEntity()); var listener = new AccountListener(mapperMock.Object, new LoggerFactory()); var credentials = new Credential { Email = "*****@*****.**", Password = "******" }; // Act var result = listener.Register(new RegisterCommand(credentials, "")); // Assert mapperMock.VerifyAll(); Assert.AreEqual(RegisterResult.Ok, result); }
public void Register_ShouldThrow_DatabaseException_OnError() { // Arrange var mapperMock = new Mock <ICredentialDataMapper>(MockBehavior.Strict); mapperMock.Setup(x => x.Find(It.IsAny <Expression <Func <CredentialEntity, bool> > >())).Throws <Exception>(); var listener = new AccountListener(mapperMock.Object, new LoggerFactory()); // Act Action act = () => { listener.Register(new RegisterCommand(new Credential(), "")); }; // Assert var exception = Assert.ThrowsException <DatabaseException>(act); Assert.AreEqual("Something unexpected happened while inserting in the database", exception.Message); mapperMock.VerifyAll(); }