//TODO: uncomment when implementation is done
        //[Fact]
        public async Task ThenAggregateIsNotFound()
        {
            //Arrange
            var municipalityLatestItem         = _syndicationContext.AddMunicipalityLatestItemFixture();
            var mockPersistentLocalIdGenerator = new Mock <IPersistentLocalIdGenerator>();

            mockPersistentLocalIdGenerator
            .Setup(x => x.GenerateNextPersistentLocalId())
            .Returns(new PersistentLocalId(5));

            var body = new StreetNameProposeRequest()
            {
                GemeenteId  = $"https://data.vlaanderen.be/id/gemeente/{municipalityLatestItem.NisCode}",
                Straatnamen = new Dictionary <Taal, string>()
                {
                    { Taal.NL, "Rodekruisstraat" },
                    { Taal.FR, "Rue de la Croix-Rouge" }
                }
            };

            //Act
            Func <Task> act = async() => await _controller.Propose(ResponseOptions, _idempotencyContext, _syndicationContext, mockPersistentLocalIdGenerator.Object, body);

            //Assert
            act.Should().Throw <AggregateNotFoundException>();
        }
        //TODO: change with validation story
        //[Fact]
        public async Task ThenResultIsNotFound()
        {
            var mockPersistentLocalIdGenerator = new Mock <IPersistentLocalIdGenerator>();

            //Arrange
            var importMunicipality = new ImportMunicipality(
                new MunicipalityId(Guid.NewGuid()),
                new NisCode("123"),
                _fixture.Create <Provenance>());

            DispatchArrangeCommand(importMunicipality);


            var body = new StreetNameProposeRequest()
            {
                GemeenteId  = $"https://data.vlaanderen.be/id/gemeente/{123}",
                Straatnamen = new Dictionary <Taal, string>()
                {
                    { Taal.NL, "Rodekruisstraat" },
                    { Taal.FR, "Rue de la Croix-Rouge" }
                }
            };

            //Act
            var result = await _controller.Propose(ResponseOptions, _idempotencyContext, _syndicationContext, mockPersistentLocalIdGenerator.Object, body);

            result.Should().BeOfType <NotFoundResult>();
        }
        public async Task <IActionResult> ProposeStreetName(
            [FromBody] StreetNameProposeRequest streetNameProposeRequest,
            [FromServices] IActionContextAccessor actionContextAccessor,
            [FromServices] ProblemDetailsHelper problemDetailsHelper,
            [FromServices] ProposeStreetNameToggle proposeStreetNameToggle,
            CancellationToken cancellationToken = default)
        {
            if (!proposeStreetNameToggle.FeatureEnabled)
            {
                return(NotFound());
            }

            var contentFormat = DetermineFormat(actionContextAccessor.ActionContext);

            IRestRequest BackendRequest() => CreateBackendRequestWithJsonBody(
                "straatnamen/voorgesteld",
                streetNameProposeRequest,
                Method.POST);

            var value = await GetFromBackendWithBadRequestAsync(
                contentFormat.ContentType,
                BackendRequest,
                CreateDefaultHandleBadRequest(),
                problemDetailsHelper,
                cancellationToken : cancellationToken);

            return(new BackendResponseResult(value, BackendResponseResultOptions.ForBackOffice()));
        }
        public async Task <IActionResult> Propose(
            [FromServices] IOptions <ResponseOptions> options,
            [FromServices] IdempotencyContext idempotencyContext,
            [FromServices] SyndicationContext syndicationContext,
            [FromServices] IPersistentLocalIdGenerator persistentLocalIdGenerator,
            [FromBody] StreetNameProposeRequest streetNameProposeRequest,
            CancellationToken cancellationToken = default)
        {
            try
            {
                //TODO REMOVE WHEN IMPLEMENTED
                return(new CreatedWithETagResult(new Uri(string.Format(options.Value.DetailUrl, "1")), "1"));

                //TODO real data please
                var fakeProvenanceData = new Provenance(
                    DateTime.UtcNow.ToInstant(),
                    Application.StreetNameRegistry,
                    new Reason(""),
                    new Operator(""),
                    Modification.Insert,
                    Organisation.DigitaalVlaanderen
                    );

                var identifier = streetNameProposeRequest.GemeenteId
                                 .AsIdentifier()
                                 .Map(IdentifierMappings.MunicipalityNisCode);

                var municipality = await syndicationContext.MunicipalityLatestItems
                                   .AsNoTracking()
                                   .SingleOrDefaultAsync(i =>
                                                         i.NisCode == identifier.Value, cancellationToken);

                var persistentLocalId = persistentLocalIdGenerator.GenerateNextPersistentLocalId();
                var cmd      = streetNameProposeRequest.ToCommand(new MunicipalityId(municipality.MunicipalityId), fakeProvenanceData, persistentLocalId);
                var position = await IdempotentCommandHandlerDispatch(idempotencyContext, cmd.CreateCommandId(), cmd, cancellationToken);

                return(new CreatedWithLastObservedPositionAsETagResult(new Uri(string.Format(options.Value.DetailUrl, persistentLocalId)), position.ToString(), Application.StreetNameRegistry.ToString()));
            }
            catch (IdempotencyException)
            {
                return(Accepted());
            }
        }
Exemplo n.º 5
0
        public async Task ThenTheStreetNameIsProposed()
        {
            const int expectedLocation = 5;

            //Arrange
            var municipalityLatestItem         = _syndicationContext.AddMunicipalityLatestItemFixture();
            var mockPersistentLocalIdGenerator = new Mock <IPersistentLocalIdGenerator>();

            mockPersistentLocalIdGenerator
            .Setup(x => x.GenerateNextPersistentLocalId())
            .Returns(new PersistentLocalId(expectedLocation));

            var importMunicipality = new ImportMunicipality(
                new MunicipalityId(municipalityLatestItem.MunicipalityId),
                new NisCode(municipalityLatestItem.NisCode),
                _fixture.Create <Provenance>());

            DispatchArrangeCommand(importMunicipality);

            var body = new StreetNameProposeRequest()
            {
                GemeenteId  = $"https://data.vlaanderen.be/id/gemeente/{municipalityLatestItem.NisCode}",
                Straatnamen = new Dictionary <Taal, string>()
                {
                    { Taal.NL, "Rodekruisstraat" },
                    { Taal.FR, "Rue de la Croix-Rouge" }
                }
            };

            //Act
            var result = (CreatedWithETagResult)await _controller.Propose(ResponseOptions, _idempotencyContext, _syndicationContext, mockPersistentLocalIdGenerator.Object, body);

            //Assert
            var expectedPosition = 1;

            result.Location.Should().Be(string.Format(DetailUrl, 1));
            //TODO: Correct when implementation is done
            //result.Location.Should().Be(string.Format(DetailUrl, expectedLocation));
            result.ETag.Should().Be(expectedPosition.ToString());
        }