public void AddContactWithNullValuesThrowsException() { var cmd = new AddContactCommand(null); var handler = new AddContactCommandHandler(uow.Object, eventBus.Object, repo.Object); Assert.Throws <InvalidEntityException>(() => handler.Handle(cmd, new System.Threading.CancellationToken())); }
public void AddContactWithInvalidValuesThrowsException() { var model = ContactsModelObjectMother.Random(); model.FirstName = null; var cmd = new AddContactCommand(model); var handler = new AddContactCommandHandler(uow.Object, eventBus.Object, repo.Object); Assert.Throws <EntityValidationException>(() => handler.Handle(cmd, new System.Threading.CancellationToken())); }
public PhoneMainViewModel(IBirthdaySource source, ISettingsService settings, INavigationService navigation) : base(source, settings, navigation) { AboutCommand = new RelayCommand(About); SettingsCommand = new RelayCommand(Settings); RateCommand = new RateThisAppCommand(); PinCommand = new RelayCommand(PinToStart); var addContactCmd = new AddContactCommand(); addContactCmd.ContactAdded += addContactCmd_ContactAdded; AddContactCommand = addContactCmd; ViewPeopleCommand = new ViewPeopleCommand(); }
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); }
public HttpResponseMessage Post(AddContactCommand cmd) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } var contact = new Contact { FirstName = cmd.FirstName, LastName = cmd.LastName }; db.Store(contact); return(Request.CreateResponse(HttpStatusCode.Created)); }
public async Task <ActionResult> AddContact([CustomizeValidator(Interceptor = typeof(API.Middleware.ValidatorInterceptor))] ContactViewModel contact) { var getContactByNameQuery = new GetContactByNameQuery(contact.Name); var getContact = await Mediator.Send(getContactByNameQuery); if (getContact != null) { return(BadRequest("This name is already taken.")); } var addContactCommand = new AddContactCommand(contact.Name, contact.Type, contact.Company, contact.PhoneNumber, contact.Email, contact.Notes); await Mediator.Send(addContactCommand); return(NoContent()); }
public void AddRepeatedContactThrowsException() { var original = ContactEntityObjectMother.Random(); var duplicated = ContactEntityObjectMother.Random(); duplicated.Name = original.Name; repo.Setup(x => x.ExistsContactWithName(duplicated.Name, null)).Returns(true); var model = ContactsModelObjectMother.FromEntity(duplicated); var cmd = new AddContactCommand(model); var handler = new AddContactCommandHandler(uow.Object, eventBus.Object, repo.Object); Assert.Throws <DomainException>(() => handler.Handle(cmd, new System.Threading.CancellationToken())); }
public async void AddContactCommandTest() { //Arange var testHelper = new TestHelper(); AddContactCommand command = new AddContactCommand("someone", "*****@*****.**", "156464654", null); AddContactCommandHandler handler = new AddContactCommandHandler(testHelper.contactsContext, testHelper.GetInMemoryContactRepository(), testHelper.GetInMemoryUnitOfWork()); //Act var insertedId = await handler.Handle(command, new System.Threading.CancellationToken()); var contact = await testHelper.GetInMemoryContactRepository().GetByIdAsync(insertedId); //Asert insertedId.Should().BeGreaterThan(0); contact.Should().NotBeNull(); }
private void CreateContact(string firstName, string lastName, string number, string street, string city, string zipCode, string country) { var request = new AddContactCommand() { FirstName = firstName, LastName = lastName, City = city, Country = country, Number = number, Street = street, ZipCode = zipCode }; var httpContent = new StringContent(JsonSerializer.ToJsonString(request), Encoding.UTF8, "application/json"); var response = _client.PostAsync("contacts", httpContent).GetAwaiter().GetResult(); response.StatusCode.Should().Be(HttpStatusCode.Created); _id = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); }
public async void Adds_New_Contact_Successfully() { //Arrange var contact = new Contact { Id = Guid.Empty, Name = "Contact", Type = "Client", Company = "Contact co.", PhoneNumber = "000", Email = "Contact@", Notes = "ABC", Source = "Social Media" }; var user = new User { Id = "1U", UserName = "******", DisplayName = "TestUser ", Email = "@test", Level = "mid" }; UserAccessor.Setup(x => x.GetLoggedUser()).ReturnsAsync(user).Verifiable(); Mediator.Setup(x => x.Send(It.IsAny <AddContactCommand>(), new CancellationToken())) .ReturnsAsync(Unit.Value); //Act var addContactCommand = new AddContactCommand(contact.Name, contact.Type, contact.Company, contact.PhoneNumber, contact.Email, contact.Notes); var handler = new AddContactCommandHandler(Context, UserAccessor.Object); var result = await handler.Handle(addContactCommand, new CancellationToken()); //Assert result.Should() .BeOfType <Unit>() .Equals(Unit.Value); UserAccessor.Verify(); DbContextFactory.Destroy(Context); }
public void AddContactCallsCollaborators() { var model = ContactsModelObjectMother.Random(); repo.Setup(x => x.Add(It.IsAny <ContactEntity>())); uow.Setup(x => x.StartChanges()); uow.Setup(x => x.CommitChanges()); eventBus.Setup(x => x.Record(It.Is <ContactAddedDomainEvent>(p => p.FirstName == model.FirstName && p.LastName == model.LastName && p.AggregateRootId == model.Id))); eventBus.Setup(x => x.PublishAsync()).Returns(Task.Delay(500)); var cmd = new AddContactCommand(model); var handler = new AddContactCommandHandler(uow.Object, eventBus.Object, repo.Object); var x = handler.Handle(cmd, new System.Threading.CancellationToken()).Result; repo.VerifyAll(); uow.VerifyAll(); eventBus.VerifyAll(); }
/// <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 Task <ActionResult> Add(AddContactCommand cmd) { var response = await httpClient.PostAsJsonAsync("contacts", cmd); return(RedirectToAction("index")); }
public async Task <ActionResult <AddContactCommandResponse> > Post([FromBody] AddContactCommand command, string token) { command.Token = token; return(await _mediator.Send(command)); }
private void RaiseCanExecuteChanged(object sender, DataErrorsChangedEventArgs e) { SaveCommand.RaiseCanExecuteChanged(); AddContactCommand.RaiseCanExecuteChanged(); AddGroupCommand.RaiseCanExecuteChanged(); }
async void HandleNewUsers(AddContactCommand addContactCommand, IConnection connection) { await @lock.ReaderLockAsync(); try { if (this.connection != connection) return; if (addContactCommand.TrId == null && addContactCommand.List == UserLists.ReverseList.listCode) { User user = GetUserInner(addContactCommand.LoginName); UserLists.PendingList.Users.AddUserInner(user); OnUserAddedToList(new UserListUserEventArgs(user, UserLists.PendingList, false)); } } finally { @lock.ReaderRelease(); } }
public ActiveCampaignResponse Add(AddContactCommand command) { return(ExecutePostRequest <ActiveCampaignResponse>("contact_add", command)); }