예제 #1
0
        public void UpdatesMeansValueInRepository_RaisesIntegrationEvent()
        {
            var authenticationMeans = new Domain.AuthenticationMeans(Id, Type, "OldValue", ValidSince, ValidUntil);
            var repository          = new Mock <IAuthenticationMeansRepository>(MockBehavior.Strict);

            repository.Setup(r => r.GetAsync(Id)).Returns(Task.FromResult(authenticationMeans)).Verifiable();
            repository.Setup(r => r.UpdateAsync(authenticationMeans)).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 <IAuthenticationMeansUpdated>(e => ValidateEquality(e)))).Returns(Task.CompletedTask).Verifiable();

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

            Assert.IsTrue(result.Successful);
            ValidateEquality(authenticationMeans);
            repository.Verify();
            busPublisher.Verify();
        }
예제 #2
0
        public void DeletesMeansFromRepository_RaisesIntegrationEvent()
        {
            var authenticationMeans = new Domain.AuthenticationMeans(Id, "xxx", "Abcd", DateTimeOffset.UtcNow, DateTimeOffset.MaxValue);

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

            repository.Setup(r => r.GetAsync(Id)).Returns(Task.FromResult(authenticationMeans)).Verifiable();
            repository.Setup(r => r.DeleteAsync(authenticationMeans)).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 <IAuthenticationMeansDeleted>(e => ValidateEquality(e)))).Returns(Task.CompletedTask).Verifiable();

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

            Assert.IsTrue(result.Successful);
            repository.Verify();
            busPublisher.Verify();
        }
        public async Task <IIdentifierResult> HandleAsync(ICreateAuthenticationMeans command, ICorrelationContext context)
        {
            if (command is null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var means = new Domain.AuthenticationMeans(command.Id, command.Label, command.Method, command.Value, command.ValidSince, command.ValidUntil);
            await _repository.AddAsync(means);

            try
            {
                await _repository.SaveChanges();
            }
            catch (EntityAlreadyExistsException)
            {
                throw new BaristaException("authentication_means_already_exists", $"An authentication means with the ID '{command.Id}' already exists.");
            }

            await _busPublisher.Publish(new AuthenticationMeansCreated(means.Id, means.Label, means.Method, means.ValidSince, means.ValidUntil));

            return(new IdentifierResult(means.Id));
        }
예제 #4
0
 private bool ValidateEquality(Domain.AuthenticationMeans domainObject)
 {
     Assert.AreEqual(Cmd.Id, domainObject.Id);
     Assert.AreEqual(Cmd.Value, domainObject.Value);
     return(true);
 }