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>()); }
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)); }
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()); } }
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 ); }