예제 #1
0
        public async Task HandleShouldReturnFailWhenDatabaseSpecificErrorOccurs()
        {
            // Arrange
            var id = Guid.NewGuid();

            var informationReadRepositoryMock = new Mock <IInformationReadRepository>();

            informationReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <SomeDatabaseSpecificException>();
            var informationReadRepository = informationReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <InformationModel>(It.IsAny <object>())).Returns(new InformationModel());
            var mapper = mapperMock.Object;

            var query = new GetInformationQuery(id);

            var handler = new GetInformationQueryHandler(mapper, informationReadRepository);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Message == CustomFailures.GetInformationFailure);
        }
예제 #2
0
        public async Task HandleShouldReturnOk()
        {
            // Arrange
            var    id   = Guid.NewGuid();
            string name = "name";
            string nameOnApplication = "nameOnApplication";
            var    description       = "description";
            var    icon = Guid.NewGuid();

            var informationReadRepositoryMock = new Mock <IInformationReadRepository>();

            informationReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(new Information(id, name, nameOnApplication, description, icon)));
            var informationReadRepository = informationReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <InformationModel>(It.IsAny <object>())).Returns(new InformationModel());
            var mapper = mapperMock.Object;

            var query = new GetInformationQuery(id);

            var handler = new GetInformationQueryHandler(mapper, informationReadRepository);

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

            // Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result <InformationModel>));
        }
예제 #3
0
        public async Task HandleShouldReturnFailWhenNotFound()
        {
            // Arrange
            var id = Guid.NewGuid();

            var informationReadRepositoryMock = new Mock <IInformationReadRepository>();

            informationReadRepositoryMock.Setup(x => x.GetAsync(id)).Throws <EntityNotFoundDbException>();
            var informationReadRepository = informationReadRepositoryMock.Object;

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <InformationModel>(It.IsAny <object>())).Returns(new InformationModel());
            var mapper = mapperMock.Object;

            var query = new GetInformationQuery(id);

            var handler = new GetInformationQueryHandler(mapper, informationReadRepository);

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

            // Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().OnlyContain(x => x.Code == HandlerFaultCode.NotFound.Name);
        }