public async Task UserUpdatedEventHandler_Consume_Updates_Name()
        {
            AuthenticationContext.OpenInMemoryConnection();

            try
            {
                var userUpdatedEvent = new UserUpdatedEvent
                {
                    UserKey      = Guid.NewGuid(),
                    FirstName    = "Ellen",
                    LastName     = "Doe",
                    EmailAddress = "*****@*****.**"
                };

                var user = new User
                {
                    UserKey = userUpdatedEvent.UserKey,
                    Name    = "John Doe"
                };

                var credential = new Credential
                {
                    CredentialType = CredentialType.Email,
                    User           = user,
                    Identifier     = "*****@*****.**"
                };

                using (var context = AuthenticationContext.GetInMemoryContext())
                {
                    context.Users.Add(user);
                    context.Credentials.Add(credential);

                    context.SaveChanges();
                }

                using (var context = AuthenticationContext.GetInMemoryContext())
                {
                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(userUpdatedEvent);
                }

                using (var context = AuthenticationContext.GetInMemoryContext())
                {
                    Assert.AreEqual("Ellen Doe", context.Users.Single().Name);
                    Assert.AreEqual("*****@*****.**", context.Credentials.Single().Identifier);
                }
            }
            finally
            {
                AuthenticationContext.CloseInMemoryConnection();
            }
        }
Example #2
0
        public async Task UserUpdatedEventHandler_Consume_Updates_Name()
        {
            CharityActionContext.OpenInMemoryConnection();

            try
            {
                var userUpdatedEvent = new UserUpdatedEvent
                {
                    UserKey      = Guid.NewGuid(),
                    FirstName    = "Ellen",
                    LastName     = "Doe",
                    EmailAddress = "*****@*****.**",
                    ProfileImage = "new image"
                };

                var charity = new Charity
                {
                    CharityKey = Guid.NewGuid()
                };

                var charityAction = new CharityAction
                {
                    OrganiserUserKey  = userUpdatedEvent.UserKey,
                    OrganiserUserName = "******",
                    OrganiserImage    = "old image",
                    Charity           = charity
                };

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    context.CharityActions.Add(charityAction);
                    context.SaveChanges();
                }

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(userUpdatedEvent);
                }

                using (var context = CharityActionContext.GetInMemoryContext())
                {
                    Assert.AreEqual("Ellen Doe", context.CharityActions.Single().OrganiserUserName);
                    Assert.AreEqual("new image", context.CharityActions.Single().OrganiserImage);
                }
            }
            finally
            {
                CharityActionContext.CloseInMemoryConnection();
            }
        }
        public async Task UserUpdatedEventHandler_Handle_Returns_Success()
        {
            DonationsContext.OpenInMemoryConnection();

            try
            {
                var user = new User {
                    UserKey      = Guid.NewGuid(),
                    ProfileImage = "PrettyImage",
                    UserName     = "******"
                };

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

                using (var context = DonationsContext.GetInMemoryContext())
                {
                    context.Users.Add(user);
                    await context.SaveChangesAsync();

                    var handler = new UserUpdatedEventHandler(context);
                    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();
            }
        }
Example #4
0
        public async Task UserUpdatedEventHandler_Consume_Event_Has_No_UserKey()
        {
            StoryContext.OpenInMemoryConnection();

            try
            {
                var userUpdatedEvent = new UserUpdatedEvent
                {
                    UserKey      = Guid.Empty,
                    FirstName    = "Ellen",
                    LastName     = "Doe",
                    ProfileImage = "new image"
                };

                var charityAction = new User
                {
                    UserKey      = Guid.NewGuid(),
                    Name         = "John Doe",
                    ProfileImage = "old image"
                };

                using (var context = StoryContext.GetInMemoryContext())
                {
                    context.Users.Add(charityAction);
                    context.SaveChanges();
                }

                using (var context = StoryContext.GetInMemoryContext())
                {
                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(userUpdatedEvent);
                }

                using (var context = StoryContext.GetInMemoryContext())
                {
                    Assert.AreEqual("John Doe", context.Users.Single().Name);
                    Assert.AreEqual("old image", context.Users.Single().ProfileImage);
                }
            }
            finally
            {
                StoryContext.CloseInMemoryConnection();
            }
        }
Example #5
0
        public async Task UserUpdatedEventHandler_Consume_Event_Has_No_UserKey()
        {
            CharityContext.OpenInMemoryConnection();

            try
            {
                var userUpdatedEvent = new UserUpdatedEvent
                {
                    UserKey   = Guid.Empty,
                    FirstName = "Ellen",
                    LastName  = "Doe"
                };

                var charity = new Charity
                {
                    OwnerUserKey  = Guid.NewGuid(),
                    OwnerUserName = "******"
                };

                using (var context = CharityContext.GetInMemoryContext())
                {
                    context.Charities.Add(charity);
                    context.SaveChanges();
                }

                using (var context = CharityContext.GetInMemoryContext())
                {
                    var handler = new UserUpdatedEventHandler(context);
                    await handler.ConsumeAsync(userUpdatedEvent);
                }

                using (var context = CharityContext.GetInMemoryContext())
                {
                    Assert.AreEqual("John Doe", context.Charities.Single().OwnerUserName);
                }
            }
            finally
            {
                CharityContext.CloseInMemoryConnection();
            }
        }