public static async Task SeedContacts(DbAccess dbAccess, IMapper mapper) { var createClient1 = new CreateContactCommand() { FirstName = "Joe", LastName = "Bloggs", DateOfBirth = DateTime.Parse("01/01/1980") }; var createClient2 = new CreateContactCommand() { FirstName = "Sally", LastName = "Bloggs", DateOfBirth = DateTime.Parse("01/01/1980") }; var createHandler = new CreateContactHandler(dbAccess, mapper); await createHandler.Handle(createClient1, CancellationToken.None); await createHandler.Handle(createClient2, CancellationToken.None); }
public async Task Throws_RequestException_Contact_Exists() { using var factory = new AppDbContextFactory(); using var context = factory.CreateContext(true); // Arrange var sut = new CreateContactHandler(_logger, context, _mediator.Object); var contact = context.Contacts.First(); var cmd = new CreateContactCommand { Name = contact.Name.ToLower(), Address = contact.Address.ToUpper() }; // Act & Assert var ex = await Assert.ThrowsAsync <RequestException>(() => sut.Handle(cmd)); _mediator.Verify(m => m.Publish(It.IsAny <ContactCreatedNotification>(), default), Times.Never()); }
public async Task CreateContactCommand_Should_add_contact_and_return_id() { // Arrange var command = new CreateContactCommand() { FirstName = "Joe", LastName = "Bloggs", DateOfBirth = DateTime.Parse("01/01/1980") }; var handler = new CreateContactHandler(dbAccess, mapper); // Act var result = await handler.Handle(command, CancellationToken.None); // Assert Assert.Equal(1, result); }
public async Task OK() { using var factory = new AppDbContextFactory(); using var context = factory.CreateContext(true); // Arrange var sut = new CreateContactHandler(_logger, context, _mediator.Object); var contacts = context.Contacts.ToList(); var initialCount = contacts.Count; var cmd = new CreateContactCommand { Name = "C", Address = "C", DateOfBirth = DateTime.Now }; // Act var result = await sut.Handle(cmd); // Assert Assert.True(contacts.Count < context.Contacts.Count()); Assert.True(result.Id > 0); _mediator.Verify(m => m.Publish(It.IsAny <ContactCreatedNotification>(), default), Times.Once()); }
public async Task ContactHandler_Create_SaveAsync() { //Arrange var dateTimeNow = DateTime.Now; Contact result = new Contact(); var command = new CreateContactCommand { FirstName = "zzz", Surname = "zzz", EmailAddress = "*****@*****.**", ContactType = 1 }; var mockContactRepository = new Mock <ContactRepository>(null); //Act var sut = new CreateContactHandler(mockContactRepository.Object); await sut.Handle(command, CancellationToken.None); //Assert mockContactRepository.Verify(x => x.SaveAsync(It.Is <Contact>(a => a.FirstName == command.FirstName && a.Surname == command.Surname && a.EmailAddress == command.EmailAddress), It.IsAny <CancellationToken>()), Times.Once); mockContactRepository.VerifyNoOtherCalls(); }
public void Arrange() { MappingBootstrapper.Initialize(); var dfeSignInServiceMock = new Mock <ISignInService>(); var contactResponse = Builder <Contact> .CreateNew().Build(); var contactRequest = Builder <CreateContactRequest> .CreateNew().Build(); var contactRepositoryMock = CreateContactRepositoryMock(contactResponse); var mediator = new Mock <IMediator>(); var contactQueryRepository = new Mock <IContactQueryRepository>(); dfeSignInServiceMock.Setup(x => x.InviteUser(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>())) .Returns(Task.FromResult(new InviteUserResponse { IsSuccess = true })); var createContactHandler = new CreateContactHandler(contactRepositoryMock.Object, contactQueryRepository.Object, dfeSignInServiceMock.Object, mediator.Object, new Mock <ILogger <CreateContactHandler> >().Object); _result = createContactHandler.Handle(contactRequest, new CancellationToken()).Result; }
public async Task Then_local_contact_is_updated_with_signInId() { await CreateContactHandler.Handle(new CreateContactRequest { FamilyName = "Smith", Email = "*****@*****.**", GivenName = "Dave" }, CancellationToken.None); ContactRepository.Verify(r => r.UpdateSignInId(_newContactId, _existingLoginUserId)); }
public async Task Then_local_contact_is_created() { await CreateContactHandler.Handle(new CreateContactRequest { FamilyName = "Smith", Email = "*****@*****.**", GivenName = "Dave" }, CancellationToken.None); ContactRepository.Verify(r => r.CreateNewContact(It.Is <Contact>(c => c.Email == "*****@*****.**"))); }