Beispiel #1
0
        public void UpdatesAuthorizationInRepository_RaisesIntegrationEvent()
        {
            var ua = new Domain.UserAuthorization(PointOfSaleId, UserId, UserAuthorizationLevel.Owner);

            var repository = new Mock <IUserAuthorizationRepository>(MockBehavior.Strict);

            repository.Setup(r => r.GetAsync(PointOfSaleId, UserId)).Returns(Task.FromResult(ua)).Verifiable();
            repository.Setup(r => r.UpdateAsync(ua)).Returns(Task.CompletedTask).Verifiable();
            repository.Setup(r => r.SaveChanges()).Returns(Task.CompletedTask).Verifiable();

            var busPublisher = new Mock <IBusPublisher>(MockBehavior.Strict);

            busPublisher.Setup(p => p.Publish <IPointOfSaleUserAuthorizationUpdated>(It.Is <IPointOfSaleUserAuthorizationUpdated>(e => ValidateEquality(e)))).Returns(Task.CompletedTask).Verifiable();

            var handler = new UpdateUserAuthorizationHandler(repository.Object, busPublisher.Object);

            handler.HandleAsync(Cmd, new Mock <ICorrelationContext>().Object).GetAwaiter().GetResult();

            repository.Verify();
            busPublisher.Verify();
            ValidateEquality(ua);
        }
        public void UpdatesUserAuthorizationInRepository_RaisesIntegrationEvent()
        {
            var userAuthorization = new AccountingGroups.Domain.UserAuthorization(AccountingGroupId, UserId, AccountingGroups.Domain.UserAuthorizationLevel.AuthorizedUser);

            var repository = new Mock <IUserAuthorizationRepository>(MockBehavior.Strict);

            repository.Setup(r => r.GetAsync(AccountingGroupId, UserId)).Returns(Task.FromResult(userAuthorization)).Verifiable();
            repository.Setup(r => r.UpdateAsync(userAuthorization)).Returns(Task.CompletedTask).Verifiable();
            repository.Setup(r => r.SaveChanges()).Returns(Task.CompletedTask).Verifiable();

            var busPublisher = new Mock <IBusPublisher>(MockBehavior.Strict);

            busPublisher.Setup(p => p.Publish(It.Is <IAccountingGroupUserAuthorizationUpdated>(e => ValidateEquality(e)))).Returns(Task.CompletedTask).Verifiable();

            var handler = new UpdateUserAuthorizationHandler(repository.Object, busPublisher.Object);
            var result  = handler.HandleAsync(Cmd, new Mock <ICorrelationContext>().Object).GetAwaiter().GetResult();

            Assert.IsTrue(result.Successful);
            ValidateEquality(userAuthorization);
            repository.Verify();
            busPublisher.Verify();
        }