Esempio n. 1
0
 public string Get(string userId, string clientId)
 {
     try {
         NewClient x = new NewClient();
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
             connection.Open();
             string sql = string.Format("SELECT clientId, firstName, lastName, birthDate, gender, phone, email, userId, date, isActive, note FROM clients WHERE clientId = '{0}'", clientId);
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 ClientsData c = new ClientsData();
                 using (SQLiteDataReader reader = command.ExecuteReader()) {
                     while (reader.Read())
                     {
                         x.clientId     = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
                         x.firstName    = reader.GetValue(1) == DBNull.Value ? "" : reader.GetString(1);
                         x.lastName     = reader.GetValue(2) == DBNull.Value ? "" : reader.GetString(2);
                         x.birthDate    = reader.GetValue(3) == DBNull.Value ? DateTime.Now.ToString() : reader.GetString(3);
                         x.gender.value = reader.GetValue(4) == DBNull.Value ? 0 : reader.GetInt32(4);
                         x.gender.title = GetGender(x.gender.value).title;
                         x.phone        = reader.GetValue(5) == DBNull.Value ? "" : reader.GetString(5);
                         x.email        = reader.GetValue(6) == DBNull.Value ? "" : reader.GetString(6);
                         x.userId       = reader.GetValue(7) == DBNull.Value ? "" : reader.GetString(7);
                         x.date         = reader.GetValue(8) == DBNull.Value ? DateTime.Today.ToString() : reader.GetString(8);
                         x.isActive     = reader.GetValue(9) == DBNull.Value ? 1 : reader.GetInt32(9);
                         x.note         = reader.GetValue(10) == DBNull.Value ? "" : reader.GetString(10);
                         x.profileImg   = GetProfileImg(userId, x.clientId);
                         x.clientData   = c.GetClientData(userId, clientId, connection);
                     }
                 }
             }
             connection.Close();
         }
         return(JsonConvert.SerializeObject(x, Formatting.None));
     } catch (Exception e) { return("error: " + e); }
 }
Esempio n. 2
0
        public async void DeleteClientAsync_Deletes_One_Client_And_Returns_Number_Of_Deletions(int id)
        {
            //declare a Client
            var       expectedClient = ClientsData.getTestClients().First(cl => cl.Id == id);
            ClientDTO expectedDTO    = _mapper.Map <ClientDTO>(expectedClient);

            //set repo return for getting the object to delete
            _mockRepository.Setup(repo => repo.GetOneByAsync(cl => cl.Id == id))
            .ReturnsAsync(expectedClient);

            //set mockRepo return for Delete action
            _mockRepository.Setup(repo => repo.DeleteTAsync(expectedClient)).ReturnsAsync(1);

            //instantiate the controller, passing the repo object
            var controller = new ClientsController(_mockRepository.Object, _mapper, _logger);

            //Call the controller method
            var actionResult = await controller.DeleteClientAsync(id);

            //Get the int result
            var okObjectResult = actionResult.Result as OkObjectResult;
            var statusCode     = okObjectResult.StatusCode;
            int actualDeleted  = (int)okObjectResult.Value;

            //Assert the result
            Assert.NotNull(actionResult);

            //Validate StatusCode
            Assert.Equal(200, statusCode);

            //Validate the number of BAs deleted
            Assert.Equal(1, actualDeleted);
        }
        public async Task <IActionResult> Create([Bind("Name,VAT,Tel1,Tel2,AddressStreet,AddressNumber,CityID")] Client client)
        {
            try
            {
                if (client.Name != null && !String.IsNullOrEmpty(client.Name))
                {
                    client.Guid      = Guid.NewGuid();
                    client.CompanyID = _userService.User.CompanyID;
                    client.CreatedAt = DateTime.UtcNow;

                    _db.Add(client);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator. " + e);
            }

            ClientsData data = new ClientsData()
            {
                Cities = _db.Cities.ToList(),
                Client = client
            };

            return(View(data));
        }
Esempio n. 4
0
        public async void fillList(string condition)
        {
            ClientsCollection = await dataBase.GetItemsAsync();

            _list = new List <string>();;
            ClientsData client = new ClientsData();

            for (int i = 0; i < ClientsCollection.Count; i++)
            {
                string datos = $"{ClientsCollection[i].id}\t{client.ClientsCollection[ClientsCollection[i].id].Name}\t{ClientsCollection[i].fecha_entrega}\t{ClientsCollection[i].estatus}";

                if (condition == "Entregado" && datos.Substring(datos.LastIndexOf('\t') + 1) == "True")
                {
                    _list.Add(datos);
                }
                else if (condition == "No entregado" && datos.Substring(datos.LastIndexOf('\t') + 1) == "False")
                {
                    _list.Add(datos);
                }
                else if (condition == "")
                {
                    _list.Add(datos);
                }
            }

            lstEntregas.ItemsSource = null;
            lstEntregas.ItemsSource = _list;
        }
Esempio n. 5
0
        private DataService CreateService()
        {
            var testData = new ClientsData();

            testData.ClientsDataList = new List <ClientData>
            {
                new ClientData {
                    AccessTime = DateTime.Now, AccessToken = "test"
                },
                new ClientData {
                    AccessTime = DateTime.Now.AddSeconds(1), AccessToken = "test"
                },
                new ClientData {
                    AccessTime = DateTime.Now.AddSeconds(2), AccessToken = "test"
                },
                new ClientData {
                    AccessTime = DateTime.Now.AddSeconds(3), AccessToken = "test"
                },
                new ClientData {
                    AccessTime = DateTime.Now.AddSeconds(1), AccessToken = "test"
                },
                new ClientData {
                    AccessTime = DateTime.Now.AddDays(10), AccessToken = "test"
                },
                new ClientData {
                    AccessTime = DateTime.Now.AddSeconds(1), AccessToken = "test2"
                },
                new ClientData {
                    AccessTime = DateTime.Now.AddSeconds(3), AccessToken = "test2"
                }
            };

            return(new DataService(testData));
        }
Esempio n. 6
0
        static void PacketProcessing(Packet packet, TcpClient client)
        {
            switch (packet.Type)
            {
            case PacketType.ServerSendLauncherUpdate:
                FileData fileData = Protocol.DataDeserialize <FileData>(packet.Data);
                UpdateManager.SelfUpdate(fileData);
                break;

            case PacketType.ServerSendClientsList:
                ClientsData clients = Protocol.DataDeserialize <ClientsData>(packet.Data);
                Config.Instance.UpdateClients(clients);
                break;

            case PacketType.ServerSendClientsFiles:
                ClientsFilesData clientsFiles = Protocol.DataDeserialize <ClientsFilesData>(packet.Data);
                Config.Instance.UpdateClientsFiles(clientsFiles);
                break;

            case PacketType.ServerSendClientFile:
                fileData = Protocol.DataDeserialize <FileData>(packet.Data);
                UpdateManager.SaveFile(fileData);
                break;

            default:
                break;
            }
        }
Esempio n. 7
0
    public int NewClient(ClientsData client)
    {
        FirmDBEntities ContextDB;

        using (ContextDB = new FirmDBEntities())
        {
            Client cli = new Client
            {
                FullName     = client.FullName,
                FirstName    = client.FirstName,
                LastName     = client.LastName,
                ClientTypeId = client.ClientTypeId,
                Email        = client.Email,
                PhoneNumber  = client.PhoneNumber,
                MobileNumber = client.MobileNumber,
                BirthDate    = client.BirthDate,
                LawyerId     = client.LawyerId,
                CreatedDate  = DateTime.Today,
                ModifyDate   = null
            };
            try
            {
                ContextDB.Clients.Add(cli);
                ContextDB.SaveChanges();
            } catch
            {
                return(0);
            }
            return(cli.Id);
        }
    }
Esempio n. 8
0
    public string Get(string userId, string clientId)
    {
        NewClient x = new NewClient();

        //db.AddColumn(userId, db.GetDataBasePath(userId, dataBase), db.clients, "cids", "VARCHAR(200)");  //new column in cids tbl.
        try {
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
                connection.Open();
                string sql = string.Format("SELECT clientId, firstName, lastName, birthDate, gender, phone, email, userId, date, isActive, note, cids FROM clients WHERE clientId = '{0}'", clientId);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    ClientsData c = new ClientsData();
                    using (SQLiteDataReader reader = command.ExecuteReader()) {
                        while (reader.Read())
                        {
                            x = GetData(reader, userId, true, connection);
                        }
                    }
                }
            }
            Users U = new Users();
            x.userGroupId = U.GetUserGroupId(x.userId);
            return(JsonConvert.SerializeObject(x, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, clientId, userId, "Clients", "Get");
            return(JsonConvert.SerializeObject(x, Formatting.None));
        }
    }
Esempio n. 9
0
        public async void UpdateClientAsync_Updates_One_Client_Returns_200_And_Client_Updated(int id)
        {
            //declare a Client
            var       expectedClient = ClientsData.getTestClients().First <Client>(cl => cl.Id == id);
            ClientDTO expectedDTO    = _mapper.Map <ClientDTO>(expectedClient);

            //set repo return for getting the object to update
            _mockRepository.Setup(repo => repo.GetOneByAsync(cl => cl.Id == expectedClient.Id))
            .ReturnsAsync(expectedClient);

            //set mockRepo return for Update action
            _mockRepository.Setup(repo => repo.UpdateTAsync(expectedClient)).ReturnsAsync(1);

            //instantiate the controller, passing the repo object
            var controller = new ClientsController(_mockRepository.Object, _mapper, _logger);

            //Call the SUT method - returns ActionResult<Client> type
            var actionResult = await controller.UpdateClientAsync(expectedClient.Id, expectedClient);

            //Get the int result from the posted ActionResult
            var       okObjectResult = actionResult.Result as OkObjectResult;
            var       statusCode     = okObjectResult.StatusCode;
            ClientDTO actualDTO      = okObjectResult.Value as ClientDTO;

            //Assert the result
            Assert.NotNull(actionResult);

            //Validate StatusCode
            Assert.Equal(200, statusCode);

            //Validate the actual Client
            actualDTO.Should().BeEquivalentTo(expectedDTO, options => options.ComparingByMembers <ClientDTO>());
        }
Esempio n. 10
0
    public List <ClientsData> GetClients()
    {
        FirmDBEntities ContextDB;

        using (ContextDB = new FirmDBEntities())
        {
            List <ClientsData> myClients = new List <ClientsData>();

            foreach (var c in ContextDB.Clients)
            {
                ClientsData cData = new ClientsData();
                cData.Id           = c.Id;
                cData.FullName     = c.FullName;
                cData.FirstName    = c.FirstName;
                cData.LastName     = c.LastName;
                cData.ClientTypeId = c.ClientTypeId;
                cData.ClientType   = c.ClientType.Name;
                cData.Email        = c.Email;
                cData.PhoneNumber  = c.PhoneNumber;
                cData.MobileNumber = c.MobileNumber;
                cData.BirthDate    = c.BirthDate;
                cData.LawyerId     = c.LawyerId;
                cData.LawyerName   = c.Lawyer.Name;
                cData.CreatedDate  = c.CreatedDate;
                cData.ModifyDate   = c.ModifyDate;
                myClients.Add(cData);
            }
            return(myClients);
        }
    }
Esempio n. 11
0
 public string GetClientGroupCalculation(string userId, List <Clients.NewClient> clientGroup)
 {
     try {
         List <Clients.NewClient> xx = new List <Clients.NewClient>();
         if (string.IsNullOrWhiteSpace(userId) || clientGroup.Count < 2)
         {
             return(JsonConvert.SerializeObject(xx, Formatting.None));
         }
         ClientsData CD = new ClientsData();
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, userDataBase))) {
             connection.Open();
             foreach (var client in clientGroup)
             {
                 var clientData = CD.GetClientData(userId, client.clientId, connection);
                 client.clientData = clientData;
                 var calculation = new NewCalculation();
                 calculation        = GetCalculationData(clientData, 1);
                 client.calculation = calculation;
                 xx.Add(client);
             }
         }
         return(JsonConvert.SerializeObject(xx, Formatting.None));
     } catch (Exception e) {
         L.SendErrorLog(e, null, userId, "ClientsData", "GetClientGroupCalculation");
         return(JsonConvert.SerializeObject(e.Message, Formatting.None));
     }
 }
Esempio n. 12
0
        public async void GetAllClientsAsync_Returns_All_Clients()
        {
            //map Clients test data to DTOs
            var _clients     = ClientsData.getTestClients();
            var expectedDTOs = _mapper.Map <IEnumerable <ClientDTO> >(_clients);

            //specify the mockRepo return
            _mockRepository.Setup(repo => repo.GetAllPagedAsync(cl => cl.Id, parameters)).ReturnsAsync(_clients);

            //instantiate the controller
            var controller = new ClientsController(_mockRepository.Object, _mapper, _logger);

            //Call the SUT method
            var result = await controller.GetAllClientsAsync(parameters);

            //Assert the result
            Assert.NotNull(result);
            var actionResult             = Assert.IsType <ActionResult <IEnumerable <ClientDTO> > >(result);
            var objResult                = Assert.IsType <OkObjectResult>(result.Result);
            var actualClients            = objResult.Value;
            IEnumerable <ClientDTO> dtos = _mapper.Map <IEnumerable <ClientDTO> >(actualClients);

            //use FluentAssertions to compare Collections of Reference types
            dtos.Should().BeEquivalentTo(expectedDTOs, options => options.ComparingByMembers <ClientDTO>());
        }
Esempio n. 13
0
    public string GetClientGroupList(string userId, string cids)
    {
        List <NewClient> xx = new List <NewClient>();

        try {
            if (cids.Contains(";"))
            {
                string[] cids_ = cids.Split(';');
                foreach (string id in cids_)
                {
                    using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
                        connection.Open();
                        string sql = string.Format("SELECT clientId, firstName, lastName, birthDate, gender, phone, email, userId, date, isActive, note, cids FROM clients WHERE clientId = '{0}'", id);
                        using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                            ClientsData c = new ClientsData();
                            using (SQLiteDataReader reader = command.ExecuteReader()) {
                                while (reader.Read())
                                {
                                    NewClient x = GetData(reader, userId, true, connection);
                                    Users     U = new Users();
                                    x.userGroupId = U.GetUserGroupId(x.userId);
                                    xx.Add(x);
                                }
                            }
                        }
                    }
                }
            }
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        } catch (Exception e) {
            L.SendErrorLog(e, cids, userId, "Clients", "GetClientGroupList");
            return(JsonConvert.SerializeObject(xx, Formatting.None));
        }
    }
Esempio n. 14
0
 private void OnDeleteClientCommand()
 {
     if (ClientsData.Contains(this.Client))
     {
         ClientsData.Remove(this.Client);
         this.Client = null;
     }
 }
        public IActionResult Create()
        {
            ClientsData data = new ClientsData()
            {
                Cities = _db.Cities.ToList()
            };

            return(View(data));
        }
        public ClientViewModel()
        {
            Clients = new ObservableCollection <Client>();
            ClientsData _context = new ClientsData();

            foreach (var client in _context.Clients)
            {
                Clients.Add(client);
            }
        }
Esempio n. 17
0
        public static void SeedDB(CMTestsDbContext context)
        {
            context.AddRange(AddressesData.getTestAddresses());
            context.AddRange(BillableActivitiesData.getTestBillableActivities());
            context.AddRange(ClientsData.getTestClients());
            context.AddRange(ContactsData.getTestContacts());
            context.AddRange(EmployeesData.getTestEmployees());
            context.AddRange(EmployeeTypesData.getTestEmployeeTypes());
            context.AddRange(LegalCasesData.getTestLegalCases());

            context.SaveChanges();
        }
        public IActionResult Detail(long id)
        {
            Client client = _db.Clients.First(x => x.ID == id);

            ClientsData data = new ClientsData()
            {
                Cities = _db.Cities.ToList(),
                Client = client
            };

            return(View("Detail", data));
        }
Esempio n. 19
0
        public static void UpdateClientsComboBox(ClientsData clientsData)
        {
            if (ClientsComboBox == null)
            {
                logger.Warn("Clients box not assigned! Can't update.");
                return;
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                ClientsComboBox.ItemsSource  = clientsData.Clients.Select(c => c.Name);
                ClientsComboBox.SelectedItem = clientsData.Clients.FirstOrDefault(c => c.Name == Config.Instance.SelectedClient).Name;
            });
        }
Esempio n. 20
0
        private void InitData()
        {
            List <string> tmp_photo = new List <string>();

            tmp_photo.Add(@"..\..\img\1.jpg");
            tmp_photo.Add(@"..\..\img\2.jpg");
            tmp_photo.Add(@"..\..\img\3.jpg");

            for (int i = 0; i < 10; i++)
            {
                ApartmentsData.Add(new Apartment($"Apartment-{i}", $"Description-{i}", i * 200.2,
                                                 new DateTime(2010, 2, 1), new DateTime(2010, 2, 4), tmp_photo.ToArray()));
                ClientsData.Add(new Client($"Client-{i}", $"3809{i}3{i + 1}2{i + 2}", ApartmentsData.ToArray()));
            }
        }
Esempio n. 21
0
        public void ClientsDataTest()
        {
            // Arrange
            var clientsData = new ClientsData();
            var clientData  = new ClientData
            {
                AccessTime  = DateTime.Now,
                AccessToken = "token"
            };

            clientsData.ClientsDataList = new List <ClientData>
            {
                // Act
                clientData
            };

            // Assert
            Assert.Single(clientsData.ClientsDataList);
        }
Esempio n. 22
0
        private void OnUpdateClientCommand()
        {
            if (ClientsData.Contains(this.Client))
            {
                ClientWindow window = new ClientWindow();

                Client currentClient = new Client();

                currentClient.Copy(Client);

                (window.DataContext as ClientWindowViewModel).Client = currentClient;

                bool?result = window.ShowDialog();

                if (result == true)
                {
                    client.Copy(currentClient);
                }
            }
        }
Esempio n. 23
0
        private void OnAddClientCommand()
        {
            ClientWindow window = new ClientWindow();

            bool?result = window.ShowDialog();

            if (result == true)
            {
                Client client = (window.DataContext as ClientWindowViewModel).Client;

                if (client != null)
                {
                    int maxId = 0;
                    if (ClientsData.Count != 0)
                    {
                        maxId = ClientsData.Select(x => x.Id).Max();
                    }
                    client.Id = maxId + 1;
                    ClientsData.Add(client);
                }
            }
        }
Esempio n. 24
0
    private static NewClient GetData(SQLiteDataReader reader, string userId, bool getClientData, SQLiteConnection connection)
    {
        NewClient x = new NewClient();

        x.clientId     = reader.GetValue(0) == DBNull.Value ? null : reader.GetString(0);
        x.firstName    = reader.GetValue(1) == DBNull.Value ? null : reader.GetString(1);
        x.lastName     = reader.GetValue(2) == DBNull.Value ? null : reader.GetString(2);
        x.birthDate    = reader.GetValue(3) == DBNull.Value ? DateTime.Now.ToString() : reader.GetString(3);
        x.gender.value = reader.GetValue(4) == DBNull.Value ? 0 : reader.GetInt32(4);
        x.gender.title = GetGenderTitle(x.gender.value);
        x.phone        = reader.GetValue(5) == DBNull.Value ? null : reader.GetString(5);
        x.email        = reader.GetValue(6) == DBNull.Value ? null : reader.GetString(6);
        x.userId       = reader.GetValue(7) == DBNull.Value ? null : reader.GetString(7);
        x.date         = reader.GetValue(8) == DBNull.Value ? DateTime.Today.ToString() : reader.GetString(8);
        x.isActive     = reader.GetValue(9) == DBNull.Value ? 1 : reader.GetInt32(9);
        x.note         = reader.GetValue(10) == DBNull.Value ? null : reader.GetString(10);
        x.cids         = reader.GetValue(11) == DBNull.Value ? null : reader.GetString(11);
        if (string.IsNullOrWhiteSpace(x.cids))
        {
            x.cids = null;
        }
        if (!x.clientId.Contains(';'))
        {
            x.profileImg = GetProfileImg(userId, x.clientId);
        }
        x.clientData = new ClientsData.NewClientData();
        Calculations calc = new Calculations();

        x.clientData.age = calc.Age(x.birthDate);
        Users users = new Users();

        x.userGroupId = users.GetUserGroupId(x.userId);
        if (getClientData)
        {
            ClientsData c = new ClientsData();
            x.clientData = c.GetClientData(userId, x.clientId, connection);
        }
        return(x);
    }
Esempio n. 25
0
        public async Task GetAllClientsAsync_Returns_All_Clients_Paged(string url, int pageNumber, int pageSize)
        {
            //Arrange
            //create test HttpClient
            var client = _factory.CreateClient();

            //get test Clients
            IEnumerable <Client> expectedClients = ClientsData.getTestClients();

            //Act
            string uri          = $"{url}?pageNumber={pageNumber}&pageSize={pageSize}";
            var    httpResponse = await client.GetAsync(uri);

            //process Http response
            string serializedResponse = httpResponse.Content.ReadAsStringAsync().Result;
            var    actualClients      = JsonConvert.DeserializeObject <IEnumerable <Client> >(serializedResponse);

            //Assert
            Assert.True(httpResponse.IsSuccessStatusCode);

            //use FluentAssertions to compare Collections of Reference types
            actualClients.Should().BeEquivalentTo(expectedClients, options => options.ComparingByMembers <Client>());
        }
Esempio n. 26
0
        private void OnSearchCommand()
        {
            Client foundClient = null;
            string messageText = null;

            switch (SearchType)
            {
            case NameSearchType:
                foundClient = ClientsData.FirstOrDefault(x => x.FullName.Equals(SearchText.Trim()));
                messageText = foundClient?.FullName;
                break;

            case PhoneSearchType:
                foundClient = ClientsData.SingleOrDefault(x => x.Phone.Equals(SearchText.Trim()));
                messageText = foundClient?.Phone;
                break;

            case PNSearchType:
                foundClient = ClientsData.SingleOrDefault(x => x.PersonalNumber.Equals(SearchText.Trim()));
                messageText = foundClient?.PersonalNumber;
                break;

            case EmailSearchType:
                foundClient = ClientsData.SingleOrDefault(x => x.Email.Equals(SearchText.Trim()));
                messageText = foundClient?.Email;
                break;
            }

            if (foundClient != null)
            {
                MessageBox.Show($"The list contains person with {SearchType.ToLower()}: {messageText} / On row: {ClientsData.IndexOf(foundClient) + 1}");
            }
            else
            {
                MessageBox.Show($"Not valid {SearchType.ToLower()}!");
            }
        }
Esempio n. 27
0
        public ClientsControllerTests()
        {
            //get Clients test data
            _clients = ClientsData.getTestClients();

            //AutoMapper Configuration
            var profiles      = new AutoMapperProfiles();
            var configuration = new MapperConfiguration(config => config.AddProfile(profiles));

            _mapper = new Mapper(configuration);

            //Configure Logger Mock
            var _loggerMock = new Mock <ILogger <ClientsController> >();

            _logger = _loggerMock.Object;

            //Mock Repository initialization
            _mockRepository = new Mock <IGenericRepository <Client> >();

            //QueryStringParameters for paging
            parameters            = new QueryStringParameters();
            parameters.pageNumber = 1;
            parameters.pageSize   = 10;
        }
Esempio n. 28
0
        public async void AddClientAsync_Creates_One_Client_Returns_201_And_Client_Created(int id)
        {
            //get a Client and set expected DTO
            var       expectedClient = ClientsData.getTestClients().First <Client>(cl => cl.Id == id);
            ClientDTO expectedDTO    = _mapper.Map <ClientDTO>(expectedClient);

            //set mockRepo return for Add action
            _mockRepository.Setup(repo => repo.AddTAsync(expectedClient)).ReturnsAsync(1);

            //set repo return for getting the newly created object
            _mockRepository.Setup(repo => repo.GetOneByAsync(cl =>
                                                             cl.Name == expectedClient.Name &&
                                                             cl.Description == expectedClient.Description &&
                                                             cl.Website == expectedClient.Website))
            .ReturnsAsync(expectedClient);

            //instantiate the controller, passing the repo object
            var controller = new ClientsController(_mockRepository.Object, _mapper, _logger);

            //Call the SUT method - returns ActionResult<Client> type
            var actionResult = await controller.AddClientAsync(expectedClient);

            //Get the int result from the posted ActionResult
            var       createdResult = actionResult.Result as CreatedResult;
            var       statusCode    = createdResult.StatusCode;
            ClientDTO actualDTO     = createdResult.Value as ClientDTO;

            //Assert the result
            Assert.NotNull(actionResult);

            //Validate the return is 1 Client created
            Assert.Equal(201, statusCode);

            //Validate the actual Client
            actualDTO.Should().BeEquivalentTo(expectedDTO, options => options.ComparingByMembers <ClientDTO>());
        }
 public Clientes()
 {
     InitializeComponent();
     BindingContext = new ClientsData();
 }
Esempio n. 30
0
 public DataService(ClientsData data)
 {
     this.data = data;
 }