Пример #1
0
        public void DeletesUserAuthorizationFromRepository_RaisesIntegrationEvent()
        {
            var userAuth = new AccountingGroups.Domain.UserAuthorization(AccountingGroupId, UserId, UserAuthorizationLevel.Owner);

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

            repository.Setup(r => r.GetAsync(AccountingGroupId, UserId)).Returns(Task.FromResult(userAuth)).Verifiable();
            repository.Setup(r => r.DeleteAsync(userAuth)).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 <IAccountingGroupUserAuthorizationDeleted>(e => ValidateEquality(e)))).Returns(Task.CompletedTask).Verifiable();

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

            Assert.IsTrue(result.Successful);
            repository.Verify();
            busPublisher.Verify();
        }
        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.DeleteAsync(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 <IPointOfSaleUserAuthorizationDeleted>(It.Is <IPointOfSaleUserAuthorizationDeleted>(e => ValidateEquality(e)))).Returns(Task.CompletedTask).Verifiable();

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

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

            repository.Verify();
            busPublisher.Verify();
            ValidateEquality(ua);
        }