コード例 #1
0
 public void TearDown()
 {
     _mockContactsService = null;
     _fixture             = null;
     _target = null;
     _mapper = null;
 }
コード例 #2
0
        public void When_InputIsNull_MapThrowsException()
        {
            ReadQuery getReadQuery = null;

            _target = _fixture.Freeze <ReadQueryHandler>();
            Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                       await _target.Handle(getReadQuery, default(CancellationToken)));
        }
コード例 #3
0
        public void When_InputIsValid_HandlerContactSuccessfully()
        {
            var expected      = _fixture.Create <List <ContactDto> >();
            var query         = _fixture.Create <ReadQuery>();
            var expectedModel = _fixture.Create <List <Contact> >();

            _mapper = _fixture.Freeze <Mock <IMapper> >();
            _mapper.Setup(x => x.Map <IEnumerable <ContactDto> >(It.IsAny <List <Contact> >())).Returns(expected);


            _mockContactsService = _fixture.Freeze <Mock <IContactService> >();
            _mockContactsService.Setup(x => x.GetAllContactAsync()).ReturnsAsync(expectedModel);

            _target = _fixture.Create <ReadQueryHandler>();
            var actual = _target.Handle(query, default(CancellationToken));

            Assert.AreEqual(expected, actual.Result);

            _mapper.Verify(x => x.Map <IEnumerable <ContactDto> >(It.IsAny <List <Contact> >()), Times.Once);
            _mockContactsService.Verify(x => x.GetAllContactAsync(), Times.Once);
        }