Example #1
0
        public async Task ThrowsExeptionWhenNameIsNull()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenNameIsNull));

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

                var ex = await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.CreateLogbookAsync(null, 1, "picture"));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.NameCanNotBeNullOrEmpty));
            }
        }
Example #2
0
        public async Task SucceedCreateLogbook()
        {
            var options = TestUtils.GetOptions(nameof(SucceedCreateLogbook));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                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.CreateLogbookAsync("LogbookName", 1, "picture");

                mockedBusinessValidator.Verify(x => x.IsNameInRange("LogbookName"), Times.Exactly(1));
                Assert.AreEqual(logbookDTO.Name, "LogbookName");
            }
        }
Example #3
0
        public async Task ThrowsExeptionWhenLogbookNameAlreadyExists()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenLogbookNameAlreadyExists));

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

                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 <AlreadyExistsException>(() => sut.CreateLogbookAsync(TestHelpersLogbook.TestLogbook01().Name, 1, "picture"));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.LogbookAlreadyExists));
            }
        }