static Client GenerateClient()
 {
     Random randomize = new Random();
     int clientId = randomize.Next(1, 10);
     string clientName = "Client" + clientId.ToString();
     Client client = new Client();
     client.name = clientName;
     return client;
 }
 public void RememberClientTest()
 {
     IRepository<Client> _clientRepository = new ClientRepository();
     Program.ClearInformation();
     Client client = new Client(2, "Petr Petrov");
     _clientRepository.Save(client);
     Client actual = _clientRepository.GetItem(client.id);
     Assert.AreEqual(client.id, actual.id);
     Assert.AreEqual(client.name, actual.name);
     Program.ClearInformation();
 }
        public static bool ChooseAgent(Client client)
        {
            var agents = new AgentRepository().GetAll().ToArray();
            int agentId;

            Random randomize = new Random();
            int indexOfAgent = randomize.Next(0, agents.Count() - 1);

            agentId = agents[indexOfAgent].id;

            return AgentLogic.Apply(client, agentId);
        }
        public static bool Apply(Client client, int agentId)
        {
            int builderId = BuilderLogic.AskBuilders();
            if (builderId != -1)
            {
                int projectId = BuilderLogic.AskForTheProject();
                client.id = AddClient(client);
                bool contractIsMade = MakeContract(client.id, agentId, builderId, projectId);

                return true;
            }
            return false;
        }
 public static int AddClient(Client client)
 {
     ClientRepository clientRepository = new ClientRepository();
     try
     {
         return clientRepository.GetAll().Where(_client => _client.name.Split(' ')[0] == client.name).First().id;
     }
     catch
     {
         new ClientRepository().Add(client);
         return client.id;
     }
 }
        public void IsExistingClientTest()
        {
            Program.ClearInformation();
            IRepository<Client> _clientRepository = new ClientRepository();
            _clientRepository.Save(new Client (1,"Ivan Ivanov"));
            IEnumerable<Client> clientRepository = _clientRepository.GetItems();

            Client client = new Client(2,"Petr Petrov");
            bool expected=false;
            bool actual = Realtor.IsExistingClient(clientRepository, client.name);
            Assert.AreEqual(expected, actual);
            Program.ClearInformation();
        }
        static void AutoFilling()
        {
            Product[] product = new Product[10];
            Client[] client = new Client[10];
            Manager[] manager = new Manager[10];

            product[0] = new Product(1, "House", "Moskovskaya, 320", "for sale");
            product[1] = new Product(2, "Office", "MOPRa, 30", "for sale");
            product[2] = new Product(3, "House", "Belorusskaya, 10", "for sale");
            product[3] = new Product(4, "Bar", "MOPRa, 3", "for sale");
            product[4] = new Product(5, "House", "Leningradskaya, 35", "for sale");
            product[5] = new Product(6, "Cafe", "Molodogvardeiskaya, 70", "for sale");
            product[6] = new Product(7, "House", "Moskovskaya, 30", "for sale");
            product[7] = new Product(8, "Club", "Zelenaya, 11", "for sale");
            product[8] = new Product(9, "House", "Lugivaja, 11", "for sale");
            product[9] = new Product(10, "Pizzeria", "Pionerskaya, 4", "for sale");

            client[0] = new Client(1, "Fedor Dvinyatin");
            client[1] = new Client(2, "Alexei Volkov");
            client[2] = new Client(3, "Ivan Ivanov");
            client[3] = new Client(4, "Petr Bojko");
            client[4] = new Client(5, "Egor Valedinsky");
            client[5] = new Client(6, "Alexander Evtuh");
            client[6] = new Client(7, "Alexei Lohnitsky");
            client[7] = new Client(8, "Mokin Alexander");
            client[8] = new Client(9, "Pavlovets Sergey");
            client[9] = new Client(10, "Igor Pujko");

            manager[0] = new Manager(1, "Viktor Oniskevich");
            manager[1] = new Manager(2, "Petr Glinskij");
            manager[2] = new Manager(3, "Fedor Yakubuk");
            manager[3] = new Manager(4, "Vasily Sapon");
            manager[4] = new Manager(5, "Igor Ivanovskiy");
            manager[5] = new Manager(6, "Alexander Dubrovsky");
            manager[6] = new Manager(7, "Olga Golub");
            manager[7] = new Manager(8, "Egor Pirozhkov");
            manager[8] = new Manager(9, "Boris Zhukovich");
            manager[9] = new Manager(10, "Igor Stepanchuk");

            IRepository<Client> _clientRepository = new ClientRepository();
            IRepository<Product> _productRepository = new ProductRepository();
            IRepository<Manager> _managerRepository = new ManagerRepository();

            for (int  i=0 ; i<=9 ; i++)
            {
                _clientRepository.Save(client[i]);
                _productRepository.Save(product[i]);
                _managerRepository.Save(manager[i]);
            }
        }
        public void ClientRepositoryTest()
        {
            ClientRepository repository = new ClientRepository();
            Client expectedClient = new Client { name = "clientsomeclient" };

            repository.Add(expectedClient);

            Client realClient = repository.GetAll().Last();

            Assert.AreEqual(expectedClient, realClient);

            repository.Delete(realClient);

            realClient = repository.GetAll().Last();

            Assert.AreNotEqual(expectedClient.name, realClient.name);
        }
        public void ClientRepositoryTest()
        {
            ClientRepository repository = new ClientRepository();
            Client expectedClient = new Client(repository.GetAll().Count() + 1, "clientsomeclient");

            repository.Add(expectedClient);

            Client realClient = repository.GetItem(expectedClient.id);

            Assert.AreEqual(expectedClient, realClient);

            repository.Delete(expectedClient);

            realClient = repository.GetItem(expectedClient.id);

            Assert.AreEqual(null, realClient);
        }
 partial void DeleteClient(Client instance);
 partial void UpdateClient(Client instance);
 partial void InsertClient(Client instance);
 /// <summary>
 /// Method saves a new Client in file
 /// </summary>
 /// <param name="client"></param>
 /// <param name="id"></param>
 /// <param name="name"></param>
 public static void RememberClient(IRepository<Client> client, int id, string name)
 {
     Client newClient = new Client(id, name);
     client.Save(newClient);
 }