Exemple #1
0
        public async Task UserCreatedEventHandler_Consume_Creates_User()
        {
            StoryContext.OpenInMemoryConnection();
            try
            {
                var userCreatedEvent = new UserCreatedEvent
                {
                    UserKey      = Guid.NewGuid(),
                    ProfileImage = "image",
                    FirstName    = "John",
                    LastName     = "Doe"
                };

                using (var context = StoryContext.GetInMemoryContext())
                {
                    var handler = new UserCreatedEventHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile()));
                    await handler.ConsumeAsync(userCreatedEvent);
                }

                using (var context = StoryContext.GetInMemoryContext())
                {
                    Assert.AreEqual(1, context.Users.Count());
                    Assert.AreEqual(userCreatedEvent.UserKey, context.Users.Single().UserKey);
                    Assert.AreEqual(userCreatedEvent.ProfileImage, context.Users.Single().ProfileImage);
                    Assert.AreEqual(Helpers.GetUserName(userCreatedEvent), context.Users.Single().Name);
                }
            }
            finally
            {
                StoryContext.CloseInMemoryConnection();
            }
        }
        public async Task UserCreatedEventHandler_Handle_Returns_Success()
        {
            DonationsContext.OpenInMemoryConnection();

            try
            {
                var Event = new UserCreatedEvent()
                {
                    UserKey      = Guid.NewGuid(),
                    AddressLine1 = "AddressLine1",
                    AddressLine2 = "AddressLine2",
                    BirthDate    = DateTime.UtcNow,
                    City         = "TestCity",
                    Country      = "TestCountry",
                    EmailAddress = "*****@*****.**",
                    FirstName    = "FirstTest",
                    LastName     = "LastTest",
                    PhoneNumber  = "0600000000",
                    ProfileImage = "PrettyImage"
                };

                using (var context = DonationsContext.GetInMemoryContext())
                {
                    var handler = new UserCreatedEventHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile()));
                    await handler.ConsumeAsync(Event);
                }

                using (var context = DonationsContext.GetInMemoryContext())
                {
                    Assert.AreEqual(1, context.Users.Count());
                    Assert.AreEqual(Event.FirstName + " " + Event.LastName, context.Users.Single().UserName);
                    Assert.AreEqual(Event.ProfileImage, context.Users.Single().ProfileImage);
                    Assert.AreEqual(Event.UserKey, context.Users.Single().UserKey);
                }
            }
            finally
            {
                DonationsContext.CloseInMemoryConnection();
            }
        }