コード例 #1
0
 public GivenMunicipalityExists(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
 {
     _fixture            = new Fixture();
     _controller         = CreateApiBusControllerWithUser <StreetNameController>("John Doe");
     _idempotencyContext = new FakeIdempotencyContextFactory().CreateDbContext(Array.Empty <string>());
     _syndicationContext = new FakeSyndicationContextFactory().CreateDbContext(Array.Empty <string>());
 }
コード例 #2
0
 public async Task <IActionResult> Post(
     [FromServices] IdempotencyContext context,
     [FromCommandId] Guid commandId,
     [FromBody] RegisterBPostImportRequest registerBPostImport,
     CancellationToken cancellationToken)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState)); // TODO: Check what this returns in the response
     }
     return(await IdempotentCommandHandlerDispatch(
                context,
                commandId,
                () => RegisterBPostImportRequestMapping.Map(registerBPostImport),
                cancellationToken));
 }
コード例 #3
0
        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());
            }
        }
コード例 #4
0
        public void SetUp()
        {
            // Boilerplate
            _mockRepository = new MockRepository(MockBehavior.Strict);
            _fixture        = new Fixture();

            // Mock setup
            _dateTime            = _mockRepository.Create <IDateTime>();
            _cache               = _mockRepository.Create <ICache>();
            _httpContextAccessor = _mockRepository.Create <IHttpContextAccessor>();

            // Mock default
            SetupMockDefaults();

            // Sut instantiation
            _idempotencyContext = new IdempotencyContext(
                _dateTime.Object,
                _cache.Object,
                _httpContextAccessor.Object
                );
        }