public async Task ReturnLogDTO_WhenLogIsFound() { var logId = 1; var description = "description"; var mappingProviderMocked = new Mock <IMappingProvider>(); var paginatedListMocked = new Mock <IPaginatedList <LogDTO> >(); var dateTimeWrapperMocked = new Mock <IDateTimeWrapper>(); var userManagerWrapperMocked = new Mock <IUserManagerWrapper <User> >(); var loggerMocked = new Mock <ILogger <LogBookService> >(); Log mapInput = null; mappingProviderMocked.Setup(mpm => mpm.MapTo <LogDTO>(It.IsAny <Log>())) .Callback <object>(inputArg => mapInput = inputArg as Log); LogBookTestUtils.ResetAutoMapper(); LogBookTestUtils.InitializeAutoMapper(); LogBookTestUtils.GetContextWithLogAndAuthorAndStatusAndCategory(nameof(ReturnLogDTO_WhenLogIsFound), logId, description); using (var assertContext = new AlphaHotelDbContext(LogBookTestUtils.GetOptions(nameof(ReturnLogDTO_WhenLogIsFound)))) { var logbookService = new LogBookService(assertContext, mappingProviderMocked.Object, paginatedListMocked.Object, dateTimeWrapperMocked.Object, userManagerWrapperMocked.Object, loggerMocked.Object); var log = await assertContext.Logs.FirstOrDefaultAsync(l => l.Id == logId); await logbookService.FindLog(logId); Assert.AreEqual(log.Id, mapInput.Id); } }
public async Task ThrowException_WhenLogIsNotFound() { var logId = 1; var mappingProviderMocked = new Mock <IMappingProvider>(); var paginatedListMocked = new Mock <IPaginatedList <LogDTO> >(); var dateTimeWrapperMocked = new Mock <IDateTimeWrapper>(); var userManagerWrapperMocked = new Mock <IUserManagerWrapper <User> >(); var loggerMocked = new Mock <ILogger <LogBookService> >(); LogBookTestUtils.ResetAutoMapper(); LogBookTestUtils.InitializeAutoMapper(); //LogBookTestUtils.(nameof(FindLog_ThrowException_WhenLogIsNotFound)); using (var assertContext = new AlphaHotelDbContext(LogBookTestUtils.GetOptions(nameof(ThrowException_WhenLogIsNotFound)))) { var logbookService = new LogBookService(assertContext, mappingProviderMocked.Object, paginatedListMocked.Object, dateTimeWrapperMocked.Object, userManagerWrapperMocked.Object, loggerMocked.Object); await Assert.ThrowsExceptionAsync <ArgumentException>( async() => await logbookService.FindLog(logId)); } }