Exemple #1
0
        public async Task Return_WhenStatusIsChanged()
        {
            var logId       = 1;
            var oldStatusId = 1;
            var newStatusId = 2;

            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.GetContextWithLogAndStatuses(nameof(Return_WhenStatusIsChanged), logId, oldStatusId, newStatusId);

            using (var assertContext = new AlphaHotelDbContext(LogBookTestUtils.GetOptions(nameof(Return_WhenStatusIsChanged))))
            {
                var logbookService = new LogBookService(assertContext, mappingProviderMocked.Object, paginatedListMocked.Object, dateTimeWrapperMocked.Object, userManagerWrapperMocked.Object, loggerMocked.Object);

                var log = await assertContext.Logs.FirstOrDefaultAsync(l => l.StatusId == oldStatusId);

                await logbookService.ChangeStatusOfLogAsync(newStatusId, logId);


                Assert.AreEqual(newStatusId, log.StatusId);
            }
        }
Exemple #2
0
        public async Task ThrowException_WhenStatusIdIsLargerThanStatusesCount()
        {
            var logId    = 1;
            var statusId = 5;

            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.GetContextWithLogAndStatuses(nameof(ThrowException_WhenStatusIdIsLargerThanStatusesCount), logId);

            using (var assertContext = new AlphaHotelDbContext(LogBookTestUtils.GetOptions(nameof(ThrowException_WhenStatusIdIsLargerThanStatusesCount))))
            {
                var logbookService = new LogBookService(assertContext, mappingProviderMocked.Object, paginatedListMocked.Object, dateTimeWrapperMocked.Object, userManagerWrapperMocked.Object, loggerMocked.Object);
                await Assert.ThrowsExceptionAsync <ArgumentException>(
                    async() => await logbookService.ChangeStatusOfLogAsync(statusId, logId));
            }
        }