Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Number of sent messages quota (#189)
* Number of sent Messages quota: Building Blocks (#146) * feat: fix pipelinebehaviors, add tokenEnforcer, add Common.Infrastructure * refactor: StatusRepository → StatusesRepository, make repo non nullable in quotaenforcer * fix: Add Common.Infrastructure to Dockerfiles * Use Dapper instead of DbContext * feat: make quota error return a 429. Add Data. Improve condition for exception throwing * fix: remove bad metric AnotherMetricKey * refactor: renames. Load Configuration of DapperContext dirrectly on AddMetricStatusesRepository * fix: remove needless comments/attributes * feat: make httperror have data from QuotaExhaustedException * refactor: var names, file locations, remove comments * fix: remove needless private setters * test: add simple test for QuotaExhaustedException * fix: bad comparison was checking for non-expired metric statuses * test: add further tests to QuotaEnforcerBehavior * fix: mock → stub * fix: ensure single-responsability tests * fix: test command registered with wrong MetricKey(s) * refactor: extract userContextStub to test class * fix: ensure we stay with FluentAssertions * fix: behavior could not be applied to responseless queries * fix: needless connectionstring validation * fix: IsExhaustedUntil was not nullable. Further renames * fix: test-required methods/ctors are public * refactor: pass connectionstring loading to ConsumerApi Program * refactor: separate testdata in behavior tests * refactor: let Dapper manage connections instead of opening a new one each time * fix: load configuration for MetricStatusesDapperContext * refactor: move NonGenericAsyncFunctionAssertionsExtensions to UnitTestTools * refactor: remove QuotaEnforcerBehavior and tests before moving on with TDD * refactor: remove using shortcut for MetricStatus * refactor: QuotaExhaustedException will feed all the exhausted metrics to the http error * fix: bad metricAttribute in tests could deceive developers * test: add first test and SUT generator * test: add all tests for QuotaEnforcerBehavior * fix: tests comparing object instead of property * feat: add QuotaEnforcerBehavior * fix: properties before ctor * fix: returning ExhaustedMetricStatuses directly may lead to unwanted changes to the API * fix: private methods before public methods * fix: use a mock for nextHasRan instead of creating a new next fn for each test * fix: MetricStatusesNoMatchStubRepository needs not a ctor * fix: attributes after ctor * refactor: remove usage of Domain reference * refactor: simplify arrange for tests, rearrange tests and rename them * fix: bad test names * test: tests ensure the right number of exhaustedMetrics are returned * refactor: use aninymous type for exception data * fix: exception data attribute names must be hardcoded * fix: tests should ensure elements exist before accessing them * Number of sent messages quota: Quota.Application (#160) * feat: add metricCalculator, implementation, and message repo * feat: command RecalculateMetricStatuses, IdentityMetricExtensions, repos and calculatorFactory * feat: add implementation to quotasrepo * refactor: code reformat * feat: add draft for quota.update * refactor: domain logic to domain project * fix: logic behind EndOfPeriod * fix: period end/begin logic. Add tests. Meesages' access on quotas module * fix: period calculations wrong for end of year * fix: no need for reference grant * feat: add grants to the postgres setup * fix: prevent EF migration for read-only messages table on quotas * fix: spacings, attribute/param names, EF methods usage * refactor: use first letter in lambda * refactor: tests readability * refactor: removed unused attributes, add message to exception * refactor: further renames * fix: fetching quotas twice. Lack cancellationToken on MessagesRepository * fix: domain logic in extension class * fix: needless repository * fix: MessageEntity configuration * fix: QuotaPeriod min and max values * test: UpdateExhaustion * refactor: needless lines * feat: add message queues to quotas module. * fix: bad handler signature * fix: event bus subscriptions * chore: create test client on startup of AdminCli * feat: add/fix required attributes to event, register repos and services, calls to findIdentities retrieve tierquotas too * fix: remove changes to AdminUI file * fix: no need to test quotas that get un-exhasuted due to lower newUsage * Revert "fix: no need to test quotas that get un-exhasuted due to lower newUsage" This reverts commit c33630e. * test: update with newUsage under Quota.Max should unexhaust it * fix: first day of the week was sunday * refactor: utcNow → pivot * refactor: remove unused method in IIdentitiesRepository * refactor: findByIds → findByAddresses * fix: method names, attribute names, * fix: use includeAll * chore: convert StronglyTypedId constructor to primary constructor * refactor: introduce and use domain error and domain exception in BuildingBlocks.Domain * refactor: Use ServiceCollectionMetricCalculatorFactory instead of ImetricCalculatorFactory * fix: merge * fix: quotaEnforcerBehavior runs on AdminAPI but no UserContext is present * fix: test must receive list of IUserContext * refactor: structure QuotaPeriodTests in Theory mode instead of repeating code * refactor: minor changes to QuotaTests * fix: consumer API would crash if no metrics were found for a certain identity * refactor: quotaPeriods exception with descriptive message * test: DateTimeExtensions such as .EndOfYear * refactor: removed needless comment * feat: add updateMetricStatus methods * fix: needless creation of new MetricStatus, missing call to UpdateMetricStatus * refactor: remove unused variable * test: Quotas through Identities * refactor: fix test data parameters order * refactor: ServiceProviderMetricCalculatorFactory name * refactor: IReadOnlyCollectionsmust be make readonly when returned * refactor: needless where * feat: split QuotaEnforcerBehavior * fix: metricStatuses to be loaded via Dapper * feat: AlwaysSuccessQuotaChecker * Revert "fix: metricStatuses to be loaded via Dapper" This reverts commit 9654ad9. * fix: MetricStatus to be created even if key is not in quotas * fix: bad name for IdentityTests file * fix: needn't order for max, missing null metricStatus when not exhausted anymore * fix: catch exception only in susceptible method * test: Null MetricStatus.IsExhaustedUntil when Quotas are exhausted in the past * refactor: remove unused UpdateAllMetricStatuses method * fix: error messages & performance considerations * refactor: add track to FindByAddresses * refactor: Identity - initialize in ctor * refactor: use service provider instead of direct DI for MetricCalculatorFactory * test: add reference to tests on comment about individual quotas * fix: missing update to interface * refactor: ensure Test of Quotas via Identities uses Identities Domain methods exclusively. * feat: implement AllQuotas to reduce pointf of failure where all quotas should be used. * test: add more MetricStatuses to identity & identity withput quotas has null MetricStatuses' IsExhaustedUntil * fix: QuotaEnforcerBehavior must be updated due to IQuotaChecker changes * refactor: make comment more prominent Co-authored-by: Timo Notheisen <[email protected]> * refactor: renames, method orders, etc. * refactor: Register NumberOfSentMessagesMetricCalculator and load it with sp * fix: remove needless MetricStatusEntityTypeConfiguration for Dapper-accessed entity. * refactor: remove Quota.IsExhaustedUntil * test: ensure MetricStatus are set even when no quotas are exhausted * refactor: singleOrDefault on MetricStatuses * refactor: remove needless line * refactor: restructure tests to reduce dependencies and cross-testing * feat: add MetricStatus to database * fix: do not use specific identity for tests Co-authored-by: Timo Notheisen <[email protected]> * refactor: QuotaCheckerImplTests * fix: EndOfDay/Hour should not be specific to UtcNow * refactor: minor renames * refactor: do not use a Dictionary in the Identities.UpdateMetric method * refactor: invert if * chore: remove reference to MetricKey.TierQuotaDefinitions from migration * refactor: undo metricStatus migration * fix: Identity ignored MetricStatuses * refactor: readd MetricStatus migration after entityconfiguration fix * test: QuotaCheckerImpl CheckQuotaExhaustion should return isSuccess false when one metric is exhausted * chore: move IdentityTests to Domain tests * chore: move test doubles to separate folder * feat: add Owner to MetricStatus ctor. Update migrations * fix: remove migration script missing quotas module * fix: missing reference to test doubles * fix: untracked identities could not be updated correctly * chore: remove unused 'using' * fix: bad namespace on Domain class * fix: minor notes by resharper * chore: improve tests * fix: readd Consumer API after merge problem * chore: delete accidentally added plantuml files * fix: Mediatr not installed for Backbone ArchUnit tests * chore: readd reference from ArchUnit tests to ConsumerApi * chore: fix casing of ConsumerApi folder * fix: ConsumerApi project path * chore: remove unused copy of DateTimeAssertionsExtensions from Quotas.Domain.Tests * test: add validation of year, month and day * chore: remove Backbone.sln.DotSettings * chore: simplify QuotaEnforcerBehaviorTests * feat: add ExhaustionDateValueConverter * fix: names of paramaters of ApplyQuotasForMetricsAttribute not being parsed correctly. Dapper not yet used. * chore: cleanup QuotaEnforcerBehavior * chore: cleanup QuotaEnforcerBehavior * chore: add missing import * chore: cleanup QuotaEnforcerBehavior * chore: remove unused variables and simplify MetricStatusesRepository * test: remove unnecessary assertions from DateTimeAssertionsExtensions * chore: remove redundant .ToList * test: add tests for ExhaustionDate * test: move fields to top * test: fix method name * chore: remove commented out code * test: change some test data * refactor: use empty private ctor for Dapper on MetricStatus * refactor: make MetricKey a record * test: improve QuotaEnforcerBehaviorTests * fix: thowing GenericApplicationError instead of DomainError on QuotaExhausted * chore: update MetricStatus migration * fix: missing schema anotation on Quotas.Messages and ValueConverter for Dapper * feat: add Postgres support to DapperContext * feat: add MetricStatus migration for Postgres --------- Co-authored-by: Timo Notheisen <[email protected]> Co-authored-by: Timo Notheisen <[email protected]> * chore: fix project references * fix: AdminUI Dockerfile missing Common.Infrastructure --------- Co-authored-by: Timo Notheisen <[email protected]> Co-authored-by: Timo Notheisen <[email protected]>
- Loading branch information