コード例 #1
0
        public async Task HandleAsync_Will_Use_Event_Payload_Correctly()
        {
            // Arrange
            var configMapServiceSpy      = new ConfigMapServiceSpy();
            var namespaceRepositorySpy   = new NamespaceRepositorySpy();
            var roleRepositorySpy        = new RoleRepositorySpy();
            var roleBindingRepositorySpy = new RoleBindingRepositorySpy();
            var sut = new ContextAccountCreatedDomainEventHandler(
                configMapServiceSpy,
                namespaceRepositorySpy,
                roleRepositorySpy,
                roleBindingRepositorySpy
                );

            var roleArn = "arn:aws:iam::123456789012:Role/RolePath";
            var id      = Guid.NewGuid();
            var contextAccountCreatedDomainEventData = new ContextAccountCreatedDomainEventData(
                capabilityId: id,
                capabilityName: "foo",
                capabilityRootId: "foo-" + id.ToString().Substring(0, 8),
                contextId: Guid.NewGuid(),
                contextName: "baa",
                accountId: "210987654321",
                roleArn: roleArn,
                roleEmail: ""
                );

            var generalDomainEvent =
                new GeneralDomainEvent(
                    "1",
                    "eventName",
                    Guid.NewGuid(),
                    string.Empty,
                    JObject.FromObject(contextAccountCreatedDomainEventData)
                    );

            var @event = new ContextAccountCreatedDomainEvent(generalDomainEvent);


            // Act
            await sut.HandleAsync(@event);


            // Assert
            Assert.NotEmpty(configMapServiceSpy.Roles.Single().Key);
            Assert.NotEmpty(configMapServiceSpy.Roles.Single().Value);

            var namespaceName = namespaceRepositorySpy.Namespaces.Single().NamespaceName;

            Assert.NotNull(namespaceName);

            Assert.Equal(contextAccountCreatedDomainEventData.CapabilityRootId, namespaceName);

            Assert.Equal(namespaceName, roleRepositorySpy.Namespaces.Single());

            Assert.Equal(namespaceName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item1);
            Assert.Equal(namespaceName + "-full-access-role",
                         roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item2);
            Assert.Equal(namespaceName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item3);
        }
コード例 #2
0
        public ContextAccountCreatedDomainEvent Build()
        {
            var roleArn = "arn:aws:iam::123456789012:Role/RolePath";
            var id      = Guid.NewGuid();
            var contextAccountCreatedDomainEventData = new ContextAccountCreatedDomainEventData(
                capabilityId: id,
                capabilityName: "foo",
                capabilityRootId: "foo-" + id.ToString().Substring(0, 8),
                contextId: Guid.NewGuid(),
                contextName: "baa",
                accountId: "210987654321",
                roleArn: roleArn,
                roleEmail: ""
                );

            var generalDomainEvent =
                new GeneralDomainEvent(
                    "1",
                    "eventName",
                    Guid.NewGuid().ToString(),
                    string.Empty,
                    JObject.FromObject(contextAccountCreatedDomainEventData)
                    );



            return(new ContextAccountCreatedDomainEvent(generalDomainEvent));
        }
コード例 #3
0
        public async Task SendAsync(GeneralDomainEvent generalDomainEvent)
        {
            var     eventType    = _eventRegistry.GetInstanceTypeFor(generalDomainEvent.EventName);
            dynamic domainEvent  = Activator.CreateInstance(eventType, generalDomainEvent);
            dynamic handlersList = _eventRegistry.GetEventHandlersFor(domainEvent);

            foreach (var handler in handlersList)
            {
                await handler.HandleAsync(domainEvent);
            }
        }
コード例 #4
0
        public async Task HandleAsync_Will_Use_Event_Payload_Correctly()
        {
            // Arrange

            var configMapServiceSpy      = new ConfigMapServiceSpy();
            var namespaceRepositorySpy   = new NamespaceRepositorySpy();
            var roleRepositorySpy        = new RoleRepositorySpy();
            var roleBindingRepositorySpy = new RoleBindingRepositorySpy();
            var logger = new LoggerFactory().CreateLogger <CapabilityRegisteredEventHandler>();
            var sut    = new CapabilityRegisteredEventHandler(
                configMapServiceSpy,
                namespaceRepositorySpy,
                roleRepositorySpy,
                roleBindingRepositorySpy,
                logger
                );

            var capabilityName = "capabilityName".ToLower();
            var roleArn        = "rolearn";

            var data = new CapabilityRegisteredDomainEventData(capabilityName, roleArn);
            var g    = new GeneralDomainEvent(
                "1",
                "capability_registered",
                Guid.NewGuid().ToString(),
                "sender",
                JObject.FromObject(data)
                );
            var @event = new CapabilityRegisteredDomainEvent(g);


            // Act
            await sut.HandleAsync(@event);


            // Assert
            Assert.Equal(capabilityName, configMapServiceSpy.Roles.Single().Key);
            Assert.Equal(roleArn, configMapServiceSpy.Roles.Single().Value);

            Assert.Equal(capabilityName, namespaceRepositorySpy.Namespaces.Single().NamespaceName);
            Assert.Equal(capabilityName, namespaceRepositorySpy.Namespaces.Single().NamespaceName);

            Assert.Equal(capabilityName, roleRepositorySpy.Namespaces.Single());

            Assert.Equal(capabilityName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item1);
            Assert.Equal(capabilityName + "-full-access-role",
                         roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item2);
            Assert.Equal(capabilityName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item3);
        }