Exemplo n.º 1
0
 public void SaveUserWithContact()
 {
     try
     {
         var options = CreateNewContextOptions(); using (var db = new UserContextExt(options))
         {
             var repository = new UserRepository(db);
             UserTestHelper.PopulateDefaultMenuDataUserCtx(db);
             var item    = UserTestHelper.GenerateModel();
             var contact = UserTestHelper.GenerateContact();
             var result  = new KeyValuePair <Contact, UserM>(contact, item);
             Assert.DoesNotThrow(() => result = repository.SaveUserWithContact(item, contact));
             Assert.DoesNotThrow(() => item   = repository.GetById(item.Id));
             Assert.DoesNotThrow(() => repository.Delete(item));
             Assert.NotNull(result.Key);
             Assert.NotNull(result.Value);
             Assert.Greater(result.Key.Id, 0);
             Assert.Greater(result.Value.Id, 0);
         }
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex);
         throw;
     }
 }
Exemplo n.º 2
0
 public void ActivateById()
 {
     try
     {
         var options = CreateNewContextOptions(); using (var db = new UserContextExt(options))
         {
             var repository = new UserRepository(db);
             UserTestHelper.PopulateDefaultMenuDataUserCtx(db);
             var item = UserTestHelper.GenerateModel();
             item.LockoutEnabled = true;
             //сохраняем генерированный объект
             Assert.DoesNotThrow(() => repository.Save(item));
             //вызов активации серверного объекта
             Assert.DoesNotThrow(() => item = repository.Activate(item.Id));
             //Удаляем созданный объект
             Assert.DoesNotThrow(() => repository.Delete(item));
             //Проверка, что активация сработала
             Assert.IsTrue(!item.LockoutEnabled);
         }
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex);
         throw;
     }
 }
Exemplo n.º 3
0
 public void Delete()
 {
     try
     {
         var options = CreateNewContextOptions(); using (var db = new UserContextExt(options))
         {
             var repository = new UserRepository(db);
             UserTestHelper.PopulateDefaultMenuDataUserCtx(db);
             var item = UserTestHelper.GenerateModel();
             //сохраняем генерированный объект
             Assert.DoesNotThrow(() => repository.Save(item));
             //Удаляем созданный объект
             Assert.DoesNotThrow(() => repository.Delete(item));
         }
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex);
         throw;
     }
 }
Exemplo n.º 4
0
 public bool GetUserAddresses1(string userName)
 {
     try
     {
         var options = CreateNewContextOptions(); using (var db = new UserContextExt(options))
         {
             var repository = new UserRepository(db);
             UserTestHelper.PopulateDefaultMenuDataUserCtx(db);
             var item = db.Set <UserM>().Single(it => it.UserName == userName);
             IEnumerable <Address> result = null;
             Assert.DoesNotThrow(() => result = repository.GetUserAddresses(item));
             Assert.NotNull(result);
             return(result.Any());
         }
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex);
         throw;
     }
 }
Exemplo n.º 5
0
 public void GetUserByUsername()
 {
     try
     {
         var options = CreateNewContextOptions(); using (var db = new UserContextExt(options))
         {
             var repository = new UserRepository(db);
             UserTestHelper.PopulateDefaultMenuDataUserCtx(db);
             var item = UserTestHelper.GenerateModel();
             Assert.DoesNotThrow(() => repository.Save(item));
             Assert.DoesNotThrow(() => item = repository.GetUserByUsername(item.UserName));
             Assert.DoesNotThrow(() => repository.Delete(item));
             Assert.NotNull(item);
             Assert.Greater(item.Id, 0);
         }
     }
     catch (Exception ex)
     {
         LogEventManager.Logger.Error(ex);
         throw;
     }
 }
Exemplo n.º 6
0
        public void SaveContactAsync2()
        {
            try
            {
                var options = CreateNewContextOptions(); using (var db = new UserContextExt(options))
                {
                    var repository = new UserRepository(db);
                    UserTestHelper.PopulateDefaultMenuDataUserCtx(db);
                    var item    = UserTestHelper.GenerateModel();
                    var contact = UserTestHelper.GenerateContact();

                    Assert.DoesNotThrow(() => repository.Save(item));
                    Assert.DoesNotThrow(() => contact = repository.SaveContactAsync(item.Id, contact).Result);

                    Assert.NotNull(contact);
                    Assert.True(contact.Id > 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }