public async Task Should_be_able_to_Create_key() { var cmd = new CreateApiKey("Mofo", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"), new[] { _applicationId }); var bus = Substitute.For <IMessageBus>(); var ctx = Substitute.For <IMessageContext>(); using (var uow = CreateUnitOfWork()) { var sut = new CreateApiKeyHandler(uow, bus); await sut.HandleAsync(ctx, cmd); var repos = new ApiKeyRepository(uow); var generated = await repos.GetByKeyAsync(cmd.ApiKey); generated.Should().NotBeNull(); generated.Claims.First().Value.Should().BeEquivalentTo(_applicationId.ToString()); uow.SaveChanges(); } }
public async Task Should_be_able_to_Create_a_key_without_applications_mapped() { var cmd = new CreateApiKey("Mofo", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N")); var bus = Substitute.For <IMessageBus>(); var ctx = Substitute.For <IMessageContext>(); using (var uow = CreateUnitOfWork()) { var sut = new CreateApiKeyHandler(uow, bus); await sut.HandleAsync(ctx, cmd); var repos = new ApiKeyRepository(uow); var generated = await repos.GetByKeyAsync(cmd.ApiKey); generated.Should().NotBeNull(); generated.Claims.Should().NotBeEmpty("because keys without appIds are universal"); uow.SaveChanges(); } }