コード例 #1
0
        public async Task ThrowsExeptionWhenLogbookIsNull()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenLogbookIsNull));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01());

                await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockedBusinessValidator = new Mock <IBusinessValidator>();
                var sut = new LogbookService(assertContext, mockedBusinessValidator.Object);

                var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.UpdateLogbookAsync(10, "name", 1, "picture"));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.LogbookNotFound));
            }
        }
コード例 #2
0
        public async Task Succeed_ReturnLogbookWhenParametersAreValid()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnLogbookWhenParametersAreValid));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01());

                await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockedBusinessValidator = new Mock <IBusinessValidator>();
                var sut = new LogbookService(assertContext, mockedBusinessValidator.Object);

                var logbookDTO = await sut.UpdateLogbookAsync(1, "Hotel", 1, "picture");

                Assert.AreEqual(logbookDTO.Name, "Hotel");
                Assert.AreEqual(logbookDTO.Picture, "picture");
            }
        }