Пример #1
0
 public void AddNullClient()
 {
     using (var db = new EntitesContext())
     {
         clientDAO = new DbClientDAO(db);
         Assert.ThrowsException <ArgumentNullException>(() => clientDAO.Add(null));
     }
 }
Пример #2
0
 public void RemoveNoDBClient()
 {
     using (var db = new EntitesContext())
     {
         ClearTable.Clients(db);
         clientDAO = new DbClientDAO(db);
         clientDAO.Add(CreateNew());
         Assert.IsFalse(clientDAO.Remove(123));
     }
 }
Пример #3
0
        public void ContainsDBClient()
        {
            var client = CreateNew();

            using (var db = new EntitesContext())
            {
                ClearTable.Clients(db);
                clientDAO = new DbClientDAO(db);
                clientDAO.Add(client);
                Assert.IsTrue(clientDAO.ContainsDB(client));
            }
        }
Пример #4
0
        public void NoContainsDBClient()
        {
            var client = CreateNew();

            using (var db = new EntitesContext())
            {
                ClearTable.Clients(db);
                clientDAO = new DbClientDAO(db);
                clientDAO.Add(client);
                client.Name = "asdasd";
                Assert.IsFalse(clientDAO.ContainsDB(client));
            }
        }
Пример #5
0
        public void AddClient()
        {
            int idExpected = 1;
            int add;

            using (var db = new EntitesContext())
            {
                ClearTable.Clients(db);
                clientDAO = new DbClientDAO(db);
                add       = clientDAO.Add(CreateNew());
            }

            Assert.AreEqual(add, idExpected);
        }
Пример #6
0
        public void GetByIdClient()
        {
            Client getById;
            Client clientExpected = CreateNew(1);

            using (var db = new EntitesContext())
            {
                ClearTable.Clients(db);
                clientDAO = new DbClientDAO(db);
                clientDAO.Add(CreateNew());
                getById = clientDAO.GetById(1);
            }

            Assert.AreEqual(getById, clientExpected);
        }
Пример #7
0
        public void GetAllClient()
        {
            List <Client> getAll;
            var           clients = CreateListEntities.Clients();

            using (var db = new EntitesContext())
            {
                ClearTable.Clients(db);
                clientDAO = new DbClientDAO(db);

                foreach (var cl in clients)
                {
                    clientDAO.Add(cl);
                }

                getAll = clientDAO.GetAll();
            }

            CollectionAssert.AreEqual(getAll, clients);
        }
Пример #8
0
        public void UpdateNoDBClient()
        {
            Client clientNoDB = new Client
            {
                Id            = 234,
                Name          = "______",
                ContactPerson = "______",
                Address       = "______",
                Phone         = "______",
            };

            using (var db = new EntitesContext())
            {
                ClearTable.Clients(db);
                clientDAO = new DbClientDAO(db);
                clientDAO.Add(CreateNew());

                Assert.IsFalse(clientDAO.Update(clientNoDB));
            }
        }
Пример #9
0
        public void UpdateClient()
        {
            bool update;

            using (var db = new EntitesContext())
            {
                ClearTable.Clients(db);
                clientDAO = new DbClientDAO(db);
                clientDAO.Add(CreateNew());
                update = clientDAO.Update(new Client
                {
                    Id            = 1,
                    Name          = "____",
                    Address       = "____",
                    ContactPerson = "____",
                    Phone         = "____",
                });
            }

            Assert.IsTrue(update);
        }
Пример #10
0
        public bool Save(Client entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            CheckArgument(entity);

            int id;

            if (!clientDAO.ContainsDB(entity))
            {
                id = clientDAO.Add(entity);
            }
            else
            {
                return(false);
            }

            return(id > 0);
        }