예제 #1
0
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <IEnumerable <TypePlanningModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <TypePlanningModel>());
            var mapper = mapperMock.Object;

            var typePlanningReadRepositoryMock = new Mock <ITypePlanningReadRepository>();

            typePlanningReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <TypePlanning, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Returns(Task.FromResult(Enumerable.Empty <TypePlanning>()));
            var typePlanningReadRepository = typePlanningReadRepositoryMock.Object;

            var typePlanningOdataProviderMock = new Mock <ITypePlanningOdataProvider>();

            typePlanningOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <TypePlanning, bool> >)null);
            var typePlanningOdataProvider = typePlanningOdataProviderMock.Object;

            var query = new ListTypePlanningQuery(null, null, null);

            var handler = new ListTypePlanningQueryHandler(mapper, typePlanningReadRepository, typePlanningOdataProvider);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <TypePlanningsModel>));
        }
예제 #2
0
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <IEnumerable <TypePlanningModel> >(It.IsAny <object>())).Returns(Enumerable.Empty <TypePlanningModel>());
            var mapper = mapperMock.Object;

            var typePlanningReadRepositoryMock = new Mock <ITypePlanningReadRepository>();

            typePlanningReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <Expression <Func <TypePlanning, bool> > >(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>();
            var typePlanningReadRepository = typePlanningReadRepositoryMock.Object;

            var typePlanningOdataProviderMock = new Mock <ITypePlanningOdataProvider>();

            typePlanningOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <TypePlanning, bool> >)null);
            var typePlanningOdataProvider = typePlanningOdataProviderMock.Object;

            var query = new ListTypePlanningQuery(null, null, null);

            var handler = new ListTypePlanningQueryHandler(mapper, typePlanningReadRepository, typePlanningOdataProvider);

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.ListTypePlanningFailure);
        }