public async Task ContactHandler_Get_GetAllByIdAsync() { //Arrange var getId = 0; Contact result = new Contact(); GetContactByIdQueryDto resultDto = new GetContactByIdQueryDto(); var command = new GetContactByIdQuery(getId); var mockContactRepository = new Mock <ContactRepository>(null); //Act mockContactRepository.Setup(x => x.GetByIdAsync(getId, It.IsAny <CancellationToken>())).ReturnsAsync(result); var sut = new GetContactByIdQueryHandler(mockContactRepository.Object); resultDto = await sut.Handle(command, CancellationToken.None); //Act Assert.NotNull(result); Assert.Equal(resultDto.Id, getId); mockContactRepository.Verify(x => x.GetByIdAsync(getId, It.IsAny <CancellationToken>()), Times.Once); mockContactRepository.VerifyNoOtherCalls(); }
public async void GetContactByIdQueryTest() { //Arange var testHelper = new TestHelper(); var contact = Contact.Create("someone", "*****@*****.**", "156464654", null, testHelper.contactsContext); await testHelper.contactsContext.AddAsync(contact); await testHelper.contactsContext.SaveChangesAsync(); GetContactByIdQuery query = new GetContactByIdQuery(contact.Id); GetContactByIdQueryHandler handler = new GetContactByIdQueryHandler(testHelper.contactsContext); //Act var result = await handler.Handle(query, default); //Asert result.Should().NotBeNull(); result.FullName.Should().Be("someone"); }