Ejemplo n.º 1
0
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var mapperMock = new Mock <IMapper>();

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

            var locationReadRepositoryMock = new Mock <ILocationReadRepository>();

            locationReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <int?>())).Returns(Task.FromResult(Enumerable.Empty <Location>()));
            var locationReadRepository = locationReadRepositoryMock.Object;

            var locationOdataProviderMock = new Mock <ILocationOdataProvider>();

            locationOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <LocationClass, bool> >)null);
            var LocationOdataProvider = locationOdataProviderMock.Object;

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

            var handler = new ListLocationQueryHandler(mapper, locationReadRepository, LocationOdataProvider);

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

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <LocationsModel>));
        }
Ejemplo n.º 2
0
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var mapperMock = new Mock <IMapper>();

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

            var locationReadRepositoryMock = new Mock <ILocationReadRepository>();

            locationReadRepositoryMock.Setup(x => x.ListAsync(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <int?>())).Throws <SomeDatabaseSpecificException>();
            var LocationReadRepository = locationReadRepositoryMock.Object;

            var locationOdataProviderMock = new Mock <ILocationOdataProvider>();

            locationOdataProviderMock.Setup(x => x.GetFilterPredicate(It.IsAny <string>())).Returns((Expression <Func <LocationClass, bool> >)null);
            var LocationOdataProvider = locationOdataProviderMock.Object;

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

            var handler = new ListLocationQueryHandler(mapper, LocationReadRepository, LocationOdataProvider);

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

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