public void WriteAsync_NewUserAccount_ExpectUserAccountRetured(
            DbContextOptions <UserAccountDbContext> options)
        {
            var testUserAccount1 = new UserAccount
            {
                Id       = Guid.NewGuid(),
                Email    = "foo2@localhost",
                Accounts = new List <ExternalAccount>
                {
                    new ExternalAccount
                    {
                        Email    = "foo2@provider",
                        Provider = "facebook",
                        Subject  = "123456712",
                    },
                    new ExternalAccount
                    {
                        Email    = "bar2@provider",
                        Provider = "google",
                        Subject  = "789456111",
                    }
                },
                Claims = new List <UserAccountClaim>
                {
                    new UserAccountClaim("name", "foo2"),
                    new UserAccountClaim("email", "foo2@localhost"),
                }
            };

            using (var context =
                       new UserAccountDbContext(options, StoreOptions))
            {
                var store = new UserAccountStore(
                    context,
                    NullLogger <UserAccountStore> .Create()
                    );

                var userAccount = store.WriteAsync(testUserAccount1).Result;
                Assert.NotNull(userAccount);
            }
        }
Example #2
0
        public void WriteAsync_UpdateUserAccount_ExpectUserAccountRetured(DbContextOptions <UserAccountDbContext> options)
        {
            var testUserAccount1 = new UserAccount
            {
                Id       = Guid.NewGuid(),
                Email    = "foox@localhost",
                Accounts = new List <ExternalAccount>
                {
                    new ExternalAccount
                    {
                        Email    = "foox@provider",
                        Provider = "facebook",
                        Subject  = "123456789",
                    },
                    new ExternalAccount
                    {
                        Email    = "bar@provider",
                        Provider = "google",
                        Subject  = "789456123",
                    }
                },
                Claims = new List <UserAccountClaim>
                {
                    new UserAccountClaim("name", "foo"),
                    new UserAccountClaim("email", "foo@localhost"),
                    new UserAccountClaim("w00t", "some junk"),
                }
            };

            using (var context = new UserAccountDbContext(options, StoreOptions))
            {
                context.UserAccounts.Add(testUserAccount1.ToEntity());
                context.SaveChanges();
                testUserAccount1 = context.UserAccounts.AsNoTracking()
                                   .FirstOrDefault(c => c.Id == testUserAccount1.Id).ToModel();
            }

            UserAccount userAccount;

            using (var context = new UserAccountDbContext(options, StoreOptions))
            {
                var store = new UserAccountStore(context, NullLogger <UserAccountStore> .Create());

                testUserAccount1.VerificationKeySentAt = DateTime.Now;
                testUserAccount1.VerificationPurpose   = 1;
                testUserAccount1.VerificationStorage   = "hallo welt";

                userAccount = store.WriteAsync(testUserAccount1).Result;

                Assert.NotNull(userAccount);
            }

            using (var context = new UserAccountDbContext(options, StoreOptions))
            {
                var updatedAccount = testUserAccount1 = context.UserAccounts
                                                        .Include(c => c.Accounts)
                                                        .Include(c => c.Claims)
                                                        .FirstOrDefault(c => c.Id == testUserAccount1.Id).ToModel();

                Assert.NotNull(updatedAccount);
                Assert.Equal(updatedAccount.VerificationStorage, userAccount.VerificationStorage);
                Assert.Equal(2, updatedAccount.Accounts.Count());
                Assert.Equal(3, updatedAccount.Claims.Count());
            }
        }