Example #1
0
        public async Task GetFormDataAsyncThrowsNotFoundExceptionIfEntityDoesNotExistTest()
        {
            var mockLoggerService = new Mock <ILoggerService>();
            var mockUnitOfWork    = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(x => x.Repository <FormDataEntity>().GetAsync(It.IsAny <Expression <Func <FormDataEntity, bool> > >()))
            .Returns(() => Task.FromResult <FormDataEntity>(null));
            var persistenceService = new FormsPersistenceService(mockUnitOfWork.Object, mockLoggerService.Object);

            await persistenceService.GetFormDataAsync(It.IsAny <Guid>());
        }
Example #2
0
        public async Task GetFormDataAsyncCallsCorrectUnitOfWorkMethodTest()
        {
            var entity = new FormDataEntity();

            var mockLoggerService = new Mock <ILoggerService>();
            var mockUnitOfWork    = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(x => x.Repository <FormDataEntity>().GetAsync(It.IsAny <Expression <Func <FormDataEntity, bool> > >()))
            .Returns(() => Task.FromResult(entity));

            var persistenceService = new FormsPersistenceService(mockUnitOfWork.Object, mockLoggerService.Object);

            await persistenceService.GetFormDataAsync(It.IsAny <Guid>());

            mockUnitOfWork.Verify(m => m.Repository <FormDataEntity>().GetAsync(It.IsAny <Expression <Func <FormDataEntity, bool> > >()), Times.Once);
        }
Example #3
0
        public async Task GetFormDataAsyncReturnsSerializedObjectTest()
        {
            var entity = new FormDataEntity {
                SerializedFormData = "SerializedObject"
            };

            var mockLoggerService = new Mock <ILoggerService>();
            var mockUnitOfWork    = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(x => x.Repository <FormDataEntity>().GetAsync(It.IsAny <Expression <Func <FormDataEntity, bool> > >()))
            .Returns(() => Task.FromResult(entity));

            var persistenceService = new FormsPersistenceService(mockUnitOfWork.Object, mockLoggerService.Object);

            var result = await persistenceService.GetFormDataAsync(It.IsAny <Guid>());

            Assert.AreEqual(typeof(string), result.GetType());
        }