Beispiel #1
0
        public async void FailedAddNewUserGivenDuplicateEmail()
        {
            // When
            string newGuid      = Guid.NewGuid().ToString();
            var    newAdminUser = new AdminUser
            {
                Id    = newGuid,
                Email = "*****@*****.**"
            };
            var adminUserRoleService = new AdminUserRoleService(_adminUserRepository, _adminRoleRepository);

            //Then
            ArgumentException ex = await Assert.ThrowsAsync <ArgumentException>(
                () => adminUserRoleService.AddAdminUser(newAdminUser));

            Assert.Contains("already used", ex.Message);
            Assert.Equal("email", ex.ParamName);

            using (var db = new GlownyShopContext(_options, _dbLogger.Object))
            {
                var admnUser = await db.AdminUsers.FindAsync(newGuid);

                Assert.Null(admnUser);
            }
        }
Beispiel #2
0
        public async void SuccesAddNewUser()
        {
            // When
            string newId        = Guid.NewGuid().ToString();
            var    newAdminUser = new AdminUser
            {
                Id    = newId,
                Email = "*****@*****.**"
            };
            var adminUserRoleService = new AdminUserRoleService(_adminUserRepository, _adminRoleRepository);
            var adminUser            = await adminUserRoleService.AddAdminUser(newAdminUser);

            // Then
            Assert.NotNull(adminUser);
            using (var db = new GlownyShopContext(_options, _dbLogger.Object))
            {
                var admnUser = await db.AdminUsers.FirstOrDefaultAsync(a =>
                                                                       a.Email == "*****@*****.**");

                Assert.NotNull(admnUser);
                Assert.Equal("*****@*****.**", admnUser.Email);
                Assert.Equal(adminUser.Id, admnUser.Id);

                // Cleanup
                db.AdminUsers.Remove(admnUser);
                await db.SaveChangesAsync();
            }
        }