Esempio n. 1
0
        public async Task MongoUserStore_ShouldPutThingsIntoUsersCollectionByDefault()
        {
            var user = new MongoIdentityUser(TestUtils.RandomString(10));

            using (var dbProvider = MongoDbServerTestUtils.CreateDatabase())
            {
                var store = await MongoUserStore <MongoIdentityUser> .CreateAsync(dbProvider.Database);

                // ACT
                var result = await store.CreateAsync(user, CancellationToken.None);

                // ASSERT
                Assert.True(result.Succeeded);
                var collections      = await(await dbProvider.Database.ListCollectionsAsync()).ToListAsync();
                var collectionExists = collections.Any(x => x["name"].ToString().Equals("users", StringComparison.Ordinal));
                Assert.True(collectionExists, "Default collection name should not be changed from the initial collection name ('users') since it will cause breaking change to current users");
            }
        }
Esempio n. 2
0
        public async Task MongoIdentityUser_CanBeSavedAndRetrieved_WhenItBecomesTheSubclass()
        {
            var username      = TestUtils.RandomString(10);
            var countryName   = TestUtils.RandomString(10);
            var loginProvider = TestUtils.RandomString(5);
            var providerKey   = TestUtils.RandomString(5);
            var displayName   = TestUtils.RandomString(5);
            var myCustomThing = TestUtils.RandomString(10);
            var user          = new MyIdentityUser(username)
            {
                MyCustomThing = myCustomThing
            };

            user.AddClaim(new Claim(ClaimTypes.Country, countryName));
            user.AddLogin(new MongoUserLogin(new UserLoginInfo(loginProvider, providerKey, displayName)));

            using (var dbProvider = MongoDbServerTestUtils.CreateDatabase())
            {
                var store = new MongoUserStore <MyIdentityUser>(dbProvider.Database);

                // ACT, ASSERT
                var result = await store.CreateAsync(user, CancellationToken.None);

                Assert.True(result.Succeeded);

                // ACT, ASSERT
                var retrievedUser = await store.FindByIdAsync(user.Id, CancellationToken.None);

                Assert.NotNull(retrievedUser);
                Assert.Equal(username, retrievedUser.UserName);
                Assert.Equal(myCustomThing, retrievedUser.MyCustomThing);

                var countryClaim = retrievedUser.Claims.FirstOrDefault(x => x.ClaimType == ClaimTypes.Country);
                Assert.NotNull(countryClaim);
                Assert.Equal(countryName, countryClaim.ClaimValue);

                var retrievedLoginProvider = retrievedUser.Logins.FirstOrDefault(x => x.LoginProvider == loginProvider);
                Assert.NotNull(retrievedLoginProvider);
                Assert.Equal(providerKey, retrievedLoginProvider.ProviderKey);
                Assert.Equal(displayName, retrievedLoginProvider.ProviderDisplayName);
            }
        }
        public async Task CreateAsync_ShouldCreateUser()
        {
            // ARRANGE
            using (var dbProvider = MongoDbServerTestUtils.CreateDatabase())
            {
                var userStore = new MongoUserStore <MongoIdentityUser>(dbProvider.Database) as IUserStore <MongoIdentityUser>;
                var user      = new MongoIdentityUser(TestUtils.RandomString(10));

                // ACT
                await userStore.CreateAsync(user, CancellationToken.None);

                // ASSERT
                var collection    = dbProvider.Database.GetDefaultCollection();
                var retrievedUser = await collection.FindByIdAsync(user.Id);

                Assert.NotNull(retrievedUser);
                Assert.Equal(user.UserName, retrievedUser.UserName);
                Assert.Equal(user.NormalizedUserName, retrievedUser.NormalizedUserName);
            }
        }
Esempio n. 4
0
        public async Task MongoIdentityUser_ShouldSaveAndRetrieveTheFutureOccuranceCorrectly()
        {
            var lockoutEndDate = new DateTime(2017, 2, 1, 0, 0, 0, DateTimeKind.Utc).AddTicks(8996910);
            var user           = new MongoIdentityUser(TestUtils.RandomString(10));

            user.LockUntil(lockoutEndDate);

            using (var dbProvider = MongoDbServerTestUtils.CreateDatabase())
            {
                var store = await MongoUserStore <MongoIdentityUser> .CreateAsync(dbProvider.Database);

                // ACT
                var result = await store.CreateAsync(user, CancellationToken.None);

                // ASSERT
                Assert.True(result.Succeeded);
                var collection    = dbProvider.Database.GetCollection <MongoIdentityUser>(Constants.DefaultCollectionName);
                var retrievedUser = await collection.FindByIdAsync(user.Id);

                Assert.Equal(user.LockoutEndDate, retrievedUser.LockoutEndDate);
            }
        }