public void ClientService_Add_ShouldExeculteWithSuccess()
        {
            // Arrage
            var client = _clientTestAutoMockerFixture.GenerateValidClient();

            // Act
            _clientService.Add(client);

            // Assert
            _clientTestAutoMockerFixture.Mocker.GetMock <IClientRepository>().Verify(r => r.Add(client), Times.Once);
            _clientTestAutoMockerFixture.Mocker.GetMock <IMediator>().Verify(m => m.Publish(It.IsAny <INotification>(), CancellationToken.None), Times.Once);
        }
        public void ClienteService_Adicionar_DeveExecutarComSucesso()
        {
            // Arrange
            var cliente = _clienteTestsAutoMockerFixture.GerarClienteValido();

            // Act
            _clienteService.Add(cliente);

            // Assert
            Assert.True(cliente.IsValid());
            _clienteTestsAutoMockerFixture.Mocker.GetMock <IClientRepository>().Verify(r => r.Add(cliente), Times.Once);
            _clienteTestsAutoMockerFixture.Mocker.GetMock <IMediator>().Verify(m => m.Publish(It.IsAny <INotification>(), CancellationToken.None), Times.Once);
        }
Beispiel #3
0
        private void InsertButton_Click(object sender, EventArgs e)
        {
            try
            {
                Client client = new Client();

                client.SetRG(RGBox.Text);
                client.SetPostalCode(ZIPBox.Text);
                client.SetName(NameBox.Text);
                client.SetEmail(EmailBox.Text);
                client.SetCPF(CPFBox.Text);
                client.SetBirth(BirthBox.Text);

                service.Add(client);

                MessageBox.Show("Done");

                RGBox.Text    = "";
                ZIPBox.Text   = "";
                NameBox.Text  = "";
                EmailBox.Text = "";
                CPFBox.Text   = "";
                BirthBox.Text = "";
            }catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        public IHttpActionResult Post(ClientDto clientDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ClientDto clientDtoAdded = new ClientDto();

            try {
                clientDtoAdded = clientService.Add(clientDto);
            }
            #region Exceptions & Log
            catch (VuelingException e) {
                Log.Error(ResourceApi.AddError
                          + e.InnerException + ResourceApi.ErrorLogSeparation
                          + e.Message + ResourceApi.ErrorLogSeparation
                          + e.Data + ResourceApi.ErrorLogSeparation
                          + e.StackTrace);

                var response = new HttpResponseMessage(HttpStatusCode.NotFound);

                throw new HttpResponseException(response);
                #endregion
            }
            return(CreatedAtRoute(ResourceApi.HttpRoute,
                                  new { id = clientDtoAdded.Id }, clientDtoAdded));
        }
Beispiel #5
0
        public async Task <IActionResult> Add([FromBody] NewClient model)
        {
            var client = await _svc.Add(model);

            Audit(AuditId.ClientState);
            return(Json(client));
        }
Beispiel #6
0
        public void Setup(string workspaceName, params string[] tfsProjectNames)
        {
            _workspace = _workspaceService.List().FirstOrDefault(f => f.Name == workspaceName);
            if (_workspace == null)
            {
                Console.WriteLine($"can't find workspace {workspaceName}");
                Environment.Exit(0);
            }

            _clients = _clientService.List();

            foreach (var tfsProjectName in tfsProjectNames)
            {
                var client = _clients.FirstOrDefault(f => f.Name == tfsProjectName && f.WorkspaceId == _workspace.Id);

                if (client != null)
                {
                    continue;
                }

                client = _clientService.Add(new Client
                {
                    Name        = tfsProjectName,
                    WorkspaceId = _workspace.Id
                });

                Console.WriteLine($"synced client {client.Name} in workspace {_workspace.Name}");
            }

            _clients = _clientService.List();
        }
Beispiel #7
0
 public ActionResult Create(ClientViewModel cvm)
 {
     try
     {
         ClientService CS     = new ClientService();
         Client        client = new Client()
         {
             CIN           = cvm.CIN,
             DateNaissance = cvm.DateNaissance,
             Profession    = cvm.Profession,
             Salaire       = cvm.Salaire,
             FullName      = new NomComplet()
             {
                 LastName  = cvm.FullName.LastName,
                 FirstName = cvm.FullName.FirstName
             },
             Address = new Address()
             {
                 Rue   = cvm.Address.Rue,
                 Ville = cvm.Address.Ville
             }
         };
         CS.Add(client);
         CS.Commit();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public IHttpActionResult AddClient(ClientModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var service = new ClientService();

                int id = service.Add(BindingManager.ToClientEntity(model));
                if (id == 0)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResponseType.Error, Description = "Entity was not created."
                    }));
                }

                return(Ok(new ResponseModel()
                {
                    Result = ResponseType.Success
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(InternalServerError(ex));
            }
        }
Beispiel #9
0
        private bool AddClient()
        {
            var client = new ClientDto();

            FillDataFromFields(client);
            return(_clientService.Add(client, out _));
        }
 public ActionResult Create(ClientVM clientobj)
 {
     if (ModelState.IsValid)
     {
         var client = Mapper.Map <ClientVM, Client>(clientobj);
         _clientService.Add(client);
         return(RedirectToAction("Index"));
     }
     return(View(clientobj));
 }
Beispiel #11
0
        public void Add()
        {
            var addedClient = ClientService.Add(new Client()
            {
                Name        = "Client #1",
                WorkspaceId = DefaultWorkspaceId
            });

            Assert.IsNotNull(addedClient);
            Assert.AreEqual(1, ClientService.List().Count());
        }
        public void Add()
        {
            var newClient = new ClientDTO();

            newClient.CompanyName = CompanyName;
            newClient.PostalCode  = string.Format("{0}-{1}", PostalCode1, PostalCode2);
            newClient.Address     = Address;
            newClient.Email       = Email;
            newClient.PhoneNumber = PhoneNumber;
            ClientService.Add(newClient);
            TryClose();
        }
Beispiel #13
0
        public void Delete()
        {
            var addedClient = ClientService.Add(new Client()
            {
                Name        = "Client #1",
                WorkspaceId = DefaultWorkspaceId
            });

            Assert.IsNotNull(addedClient);
            Assert.AreEqual(1, ClientService.List().Count);
            Assert.IsTrue(ClientService.Delete(addedClient.Id.Value));
            Assert.IsFalse(ClientService.List().Any());
        }
Beispiel #14
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    clientService.Add(Input.Name, Input.Surname, Input.Address, Input.PostalCode,
                                      Input.CNP, Input.Country, Input.City, Input.District, Input.PhoneNumber, Input.Email);

                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    //var callbackUrl = Url.Page(
                    //    "/Account/ConfirmEmail",
                    //    pageHandler: null,
                    //    values: new { area = "Identity", userId = user.Id, code = code },
                    //    protocol: Request.Scheme);

                    //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                    //    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Beispiel #15
0
        public void GetByName()
        {
            var addedClient = ClientService.Add(new Client()
            {
                Name        = "Client #1",
                WorkspaceId = DefaultWorkspaceId
            });

            var loadedClient = ClientService.GetByName("Client #1");

            Assert.IsNotNull(loadedClient);
            Assert.AreEqual(addedClient.Id, loadedClient.Id);
            Assert.AreEqual(addedClient.Name, loadedClient.Name);
            Assert.AreEqual(addedClient.WorkspaceId, loadedClient.WorkspaceId);
        }
        public void Add()
        {
            var workSpace = new WorkspaceService().List().FirstOrDefault();
            var srv       = new ClientService();

            var obj = new Client()
            {
                Name        = "New Client" + DateTime.Now.Ticks,
                HourlyRate  = new Random(13).NextDouble(),
                Currency    = "USD",
                WorkspaceId = workSpace.Id
            };
            var act = srv.Add(obj);

            Assert.Greater(act.Id, 0);
        }
Beispiel #17
0
        public void ClientService_Add_ShouldFailDueInvalidClient()
        {
            // Arrage
            var client     = _clientTestBogusFixture.GenerateInvalidClient();
            var clientRepo = new Mock <IClientRepository>();
            var mediator   = new Mock <IMediator>();

            var clientService = new ClientService(clientRepo.Object, mediator.Object);

            // Act
            clientService.Add(client);

            // Assert
            clientRepo.Verify(r => r.Add(client), Times.Never);
            mediator.Verify(m => m.Publish(It.IsAny <INotification>(), CancellationToken.None), Times.Never);
        }
Beispiel #18
0
        public Form2()
        {
            InitializeComponent();

            List <Client> Clients = ClientService.GetAll();

            if (Clients.Count == 0)
            {
                ClientService.Add(new Client("c01"));
                ClientService.Add(new Client("c02"));
                ClientService.Add(new Client("c03"));

                Clients = ClientService.GetAll();
            }
            clientBindingSource.DataSource = Clients;
        }
        public void ClienteService_Adicionar_DeveFalharDevidoClienteInvalido()
        {
            // Arrange
            var cliente     = _clienteTestsBogus.GerarClienteInvalido();
            var clienteRepo = new Mock <IClientRepository>();
            var mediatr     = new Mock <IMediator>();

            var clienteService = new ClientService(clienteRepo.Object, mediatr.Object);

            // Act
            clienteService.Add(cliente);

            // Assert
            Assert.False(cliente.IsValid());
            clienteRepo.Verify(r => r.Add(cliente), Times.Never);
            mediatr.Verify(m => m.Publish(It.IsAny <INotification>(), CancellationToken.None), Times.Never);
        }
        public Result Add(Client client)
        {
            var result = new Result();

            try
            {
                ClientService clientService = new ClientService();
                clientService.Add(client);
                result.IsSuccess = true;
            }
            catch (Exception exception)
            {
                result.IsSuccess     = false;
                result.ExceptionInfo = exception;
            }
            return(result);
        }
        public void GetById()
        {
            var srv = new ClientService();

            var obj = GetClientMock();

            obj = srv.Add(obj);

            var expId = obj.Id;

            var actObj = srv.Get(expId.Value);

            Assert.IsNotNull(actObj);

            Assert.IsTrue(actObj.Id.HasValue);

            Assert.GreaterOrEqual(actObj.Id, 1);
        }
        public void Delete()
        {
            var srv = new ClientService();

            var obj = GetClientMock();

            obj = srv.Add(obj);

            var expId = obj.Id;

            var act = srv.Delete(obj.Id.Value);

            Assert.True(act == true);

            var actObj = srv.Get(expId.Value);

            Assert.IsFalse(actObj.Id.HasValue);
        }
Beispiel #23
0
        public void Edit()
        {
            var addedClient = ClientService.Add(new Client()
            {
                Name        = "Client #1",
                WorkspaceId = DefaultWorkspaceId
            });

            var loadedClient = ClientService.Get(addedClient.Id.Value);

            loadedClient.Name = "TestEdit";
            var editedClient = ClientService.Edit(loadedClient);

            Assert.IsNotNull(editedClient);
            Assert.AreEqual(addedClient.Id, editedClient.Id);
            Assert.AreEqual(loadedClient.Name, editedClient.Name);
            Assert.AreEqual(addedClient.WorkspaceId, editedClient.WorkspaceId);
        }
        private void BtnAdd_Click(object sender, EventArgs e)//add new client
        {
            //check if the book information is null
            if (TxtFullname.Text == string.Empty || TxtPhone.Text == string.Empty)
            {
                MessageBox.Show("Clients information can't be null");
                return;
            }
            //check if the phone number contain digit
            if (!isDigit(TxtPhone.Text))
            {
                MessageBox.Show("the phone can not contain letter");
                return;
            }
            //check if the fullname contain letter
            if (!Regex.IsMatch(TxtFullname.Text, @"^[a-zA-Z\s]*$"))
            {
                MessageBox.Show("the fullname can not contain digit");
                return;
            }
            //check if given client is already exists
            foreach (Client item in _clientService.Clients())
            {
                if (item.isActive == true)
                {
                    if (item.Fullname == TxtFullname.Text && item.Phone == TxtPhone.Text)
                    {
                        MessageBox.Show("such client is already exists");
                        return;
                    }
                }
            }
            Client client = new Client()//client to adding
            {
                Fullname = TxtFullname.Text,
                Phone    = TxtPhone.Text,
                isActive = true
            };

            _clientService.Add(client);
            DgvClients.Rows.Add(client.Id, client.Fullname, client.Phone);
            ResetSearch();
            Reset();
        }
Beispiel #25
0
        public void BulkDelete()
        {
            var ids = new List <int>();

            for (int i = 0; i < 3; i++)
            {
                var addedClient = ClientService.Add(new Client()
                {
                    Name        = "Client #" + i,
                    WorkspaceId = DefaultWorkspaceId
                });
                Assert.IsNotNull(addedClient);
                ids.Add(addedClient.Id.Value);
            }

            Assert.AreEqual(3, ClientService.List().Count);
            Assert.IsTrue(ClientService.Delete(ids.ToArray()));
            Assert.IsFalse(ClientService.List().Any());
        }
Beispiel #26
0
        public void Save()
        {
            try
            {
                var IsSaved = objClientService.Add(CurrentClient);
                LoadData();

                if (IsSaved)
                {
                    Message = "Клиент успешно добавлен !";
                }
                else
                {
                    Message = "Ошибка добавления !";
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
        }
        public void Edit()
        {
            var workSpace = new WorkspaceService().List().FirstOrDefault();
            var srv       = new ClientService();

            var obj = new Client()
            {
                Name        = "New Client" + DateTime.Now.Ticks,
                HourlyRate  = new Random(13).NextDouble(),
                Currency    = "USD",
                WorkspaceId = workSpace.Id
            };
            var exp = srv.Add(obj);

            Assert.Greater(exp.Id, 0);

            exp.Name = "Edit Test - " + DateTime.Now.Ticks;
            var act = srv.Edit(exp);

            Assert.True(act.Name == exp.Name);
            Assert.True(act.Name != obj.Name);
        }