public async void EditContactCommandTest()
        {
            //Arange
            var testHelper = new TestHelper();

            var contact = Contact.Create("someone", "*****@*****.**", "156464654", null, testHelper.contactsContext);

            await testHelper.contactsContext.AddAsync(contact);

            await testHelper.contactsContext.SaveChangesAsync();

            EditContactCommand editCommand = new EditContactCommand(new Application.DTO.ContactDTO()
            {
                Id = contact.Id, FullName = "another", Email = "*****@*****.**", PhoneNumber = "55555555555", Address = "herguhrgrhg"
            });
            EditContactCommandHandler editContactCommandHandler = new EditContactCommandHandler(testHelper.contactsContext, testHelper.GetInMemoryContactRepository(), testHelper.GetInMemoryUnitOfWork());

            //Act
            await editContactCommandHandler.Handle(editCommand, default);

            var updatedContact = await testHelper.GetInMemoryContactRepository().GetByIdAsync(contact.Id);

            //Assert
            updatedContact.Should().NotBeNull();
            updatedContact.FullName.Should().Be("another");
        }
예제 #2
0
        public void Execute_Returns_Edited_Contact()
        {
            // Setup
            InitializeTestEntities();

            // Act
            Contact result = new EditContactCommand(_serviceFactory.Object).WithContactId(_contact.Id)
                             .SetName("Name")
                             .SetDirectPhone("111-111-1111")
                             .SetMobilePhone("222-222-2222")
                             .SetExtension("33")
                             .SetEmail("*****@*****.**")
                             .SetAssistant("Assistant")
                             .SetReferredBy("Referred By")
                             .SetNotes("Notes")
                             .RequestedByUserId(_user.Id)
                             .Execute();

            // Verify
            Assert.IsNotNull(result, "No contact was created");
            Assert.AreEqual("Name", result.Name, "The contact's name was incorrect");
            Assert.AreEqual("111-111-1111", result.DirectPhone, "The contact's direct phone was incorrect");
            Assert.AreEqual("222-222-2222", result.MobilePhone, "The contact's mobile phone was incorrect");
            Assert.AreEqual("33", result.Extension, "The contact's extension was incorrect");
            Assert.AreEqual("*****@*****.**", result.Email, "The contact's email was incorrect");
            Assert.AreEqual("Assistant", result.Assistant, "The contact's assistant was incorrect");
            Assert.AreEqual("Referred By", result.ReferredBy, "The contact's referred by was incorrect");
            Assert.AreEqual("Notes", result.Notes, "The contact's notes was incorrect");
        }
예제 #3
0
 public SyncController(MyJobLeadsDbContext context,
                       ContactByIdQuery contactByIdQuery,
                       EditContactCommand editContactCmd,
                       IProcess <GetJigsawContactDetailsParams, ExternalContactSearchResultsViewModel.ContactResultViewModel> getJsContactProc)
 {
     _context          = context;
     _contactByIdQuery = contactByIdQuery;
     _editContactCmd   = editContactCmd;
     _getJsContactProc = getJsContactProc;
 }
예제 #4
0
        public virtual ActionResult Edit(EditContactViewModel model)
        {
            Contact contact;

            try
            {
                // Determine if this is a new contact or not
                if (model.Id == 0)
                {
                    contact = new CreateContactCommand(_serviceFactory).WithCompanyId(model.Company.Id)
                              .SetAssistant(model.Assistant)
                              .SetDirectPhone(model.DirectPhone)
                              .SetEmail(model.Email)
                              .SetExtension(model.Extension)
                              .SetMobilePhone(model.MobilePhone)
                              .SetName(model.Name)
                              .SetNotes(model.Notes)
                              .SetTitle(model.Title)
                              .SetReferredBy(model.ReferredBy)
                              .RequestedByUserId(CurrentUserId)
                              .Execute();
                }
                else
                {
                    contact = new EditContactCommand(_serviceFactory).WithContactId(model.Id)
                              .SetAssistant(model.Assistant)
                              .SetDirectPhone(model.DirectPhone)
                              .SetEmail(model.Email)
                              .SetExtension(model.Extension)
                              .SetMobilePhone(model.MobilePhone)
                              .SetName(model.Name)
                              .SetNotes(model.Notes)
                              .SetTitle(model.Title)
                              .SetReferredBy(model.ReferredBy)
                              .RequestedByUserId(CurrentUserId)
                              .Execute();
                }

                return(RedirectToAction(MVC.Contact.Details(contact.Id)));
            }

            catch (ValidationException ex)
            {
                foreach (var error in ex.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }

                // Retrieve the company from the database for the sidebar
                model.Company = new CompanySummaryViewModel(new CompanyByIdQuery(_unitOfWork, _companyAuthProcess).WithCompanyId(model.Company.Id).Execute());
                return(View(model));
            }
        }
예제 #5
0
        public PhoneBookInstance()
        {
            IAddContactCommand    cnd   = new AddContactCommand();
            IExistContactByNumber exist = new ExistContactByNumber();
            IEditContactCommand   editContactCommand   = new EditContactCommand();
            IExistByIdQuery       existByIdQuery       = new ExistByIdQuery();
            IDeleteContactCommand deleteContactCommand = new DeleteContactCommad();

            _contactQuery = new ContactQuery();

            _addUseCase    = new AddUserUseCase(cnd, exist);
            _deleteUseCase = new DeleteUseCase(existByIdQuery, deleteContactCommand);
            _editUserCase  = new EditUseCase(existByIdQuery, editContactCommand);
        }
예제 #6
0
        public async Task <ActionResult> EditContact([CustomizeValidator(Interceptor = typeof(API.Middleware.ValidatorInterceptor))] ContactViewModel contact)
        {
            var contactDetailsQuery = new ContactDetailsQuery(contact.Id);
            var getContact          = await Mediator.Send(contactDetailsQuery);

            if (getContact == null)
            {
                return(NotFound("Contact not found"));
            }

            var editContactCommand = new EditContactCommand(getContact, contact.Name, contact.Type, contact.Company, contact.PhoneNumber, contact.Email, contact.Notes, contact.Source);
            await Mediator.Send(editContactCommand);

            return(NoContent());
        }
 private void InvalidateCommands()
 {
     EditFeeScheuleCommand.RaiseCanExecuteChanged();
     SaveCommand.RaiseCanExecuteChanged();
     PrintCommand.RaiseCanExecuteChanged();
     CancelCommand.RaiseCanExecuteChanged();
     DeleteCommand.RaiseCanExecuteChanged();
     EditAttributeCommand.RaiseCanExecuteChanged();
     DeleteAttributeCommand.RaiseCanExecuteChanged();
     DeleteFeeScheuleCommand.RaiseCanExecuteChanged();
     NewOrderCommand.RaiseCanExecuteChanged();
     EditContactCommand.RaiseCanExecuteChanged();
     DeleteContactCommand.RaiseCanExecuteChanged();
     EditEmployeeCommand.RaiseCanExecuteChanged();
     DeleteEmployeeCommand.RaiseCanExecuteChanged();
 }
        public async void Edits_Contact_Successfully()
        {
            //Arrange
            var contact = Context.Contacts.First();

            Mediator.Setup(x => x.Send(It.IsAny <EditContactCommand>(), new CancellationToken()))
            .ReturnsAsync(Unit.Value);

            //Act
            var editContactCommand = new EditContactCommand(contact, "name", "type", "company", "123 123 123", "email", "", "");
            var handler            = new EditContactCommandHandler(Context);
            var result             = await handler.Handle(editContactCommand, new CancellationToken());

            //Assert
            result.Should()
            .BeOfType <Unit>()
            .Equals(Unit.Value);

            DbContextFactory.Destroy(Context);
        }
예제 #9
0
        /// <summary>
        /// ViewModel for main window.
        /// </summary>
        public MainWindowVM()
        {
            ContactService = new ContactService();

            ContactVMs = ContactService.GetContactVMs();

            GroupNames =
                new ObservableCollection <string>(ContactService.Groups.Select(it => it.Name))
            {
                SystemGroupNames.ALL_CONTACTS
            };

            SelectedGroup = SystemGroupNames.ALL_CONTACTS;

            AddGroupCommand               = new AddGroupCommand();
            AddContactToGroupCommand      = new AddContactToGroupCommand();
            RemoveContactFromGroupCommand = new RemoveContactFromGroupCommand();
            EditContactCommand            = new EditContactCommand();

            AddContactCommand = new AddContactCommand();

            DeleteContactCommand = new DeleteContactCommand();
            DeleteGroupCommand   = new DeleteGroupCommand();
        }
        public async void EditContact_True()
        {
            //arrange
            var contact     = ContactFaker.GetContactOk();
            var contactType = ContactTypeFaker.GetContactTypeOk();

            var faker = new Faker();

            var contactName = faker.Person.FullName;

            var randomizerTextRegex = RandomizerFactory
                                      .GetRandomizer(new FieldOptionsTextRegex
            {
                Pattern = @"^\(999\) 999-\d{4}$"
            });

            var contactPhone = randomizerTextRegex.Generate().ToUpper();

            var contactBirthDate = faker.Date.Past();


            var editContactCommand = new EditContactCommand(
                contactId: contact.Id,
                contactName: contactName,
                contactPhone: contactPhone,
                contactBirthDate: contactBirthDate,
                contactTypeId: contactType.Id
                );


            _dependencyResolverMock
            .Setup(x =>
                   x.Resolve <IContactRepository>())
            .Returns(_contactRepositoryMock.Object);


            _dependencyResolverMock
            .Setup(x =>
                   x.Resolve <IContactTypeRepository>())
            .Returns(_contactTypeRepositoryMock.Object);


            _contactRepositoryMock
            .Setup(x =>
                   x.GetByIdAsync(editContactCommand.ContactId))
            .Returns(Task.FromResult(contact));

            _contactTypeRepositoryMock
            .Setup(x =>
                   x.GetByIdAsync(editContactCommand.ContactTypeId))
            .Returns(Task.FromResult(contactType));



            _contactRepositoryMock
            .Setup(x =>
                   x.CommitAsync())
            .Returns(Task.FromResult(CommitResponse.Ok()));


            var handler = new ContactCommandHandler(_dependencyResolverMock.Object);

            //act
            var result = await handler.Handle(editContactCommand, new CancellationToken());



            //result

            Assert.True(result.Success);

            _contactRepositoryMock.Verify(x => x.GetByIdAsync(editContactCommand.ContactId), Times.Once);
            _contactTypeRepositoryMock.Verify(x => x.GetByIdAsync(editContactCommand.ContactTypeId), Times.Once);
            _contactRepositoryMock.Verify(x => x.Update(contact), Times.Once);
            _contactRepositoryMock.Verify(x => x.CommitAsync(), Times.Once);

            _mediatorHandler.Verify(x => x.NotifyDomainNotification(It.IsAny <DomainNotification>()), Times.Never);
        }
예제 #11
0
 private void RaiseContactChanges()
 {
     OnPropertyChanged(() => SelectedContactIndex);
     EditContactCommand.RaiseCanExecuteChanged();
 }