示例#1
0
        public async Task RetrievedEventsAreVersionedCorrectly()
        {
            await _containerFixture.ExecuteScopeAsync(serviceProvider =>
            {
                var eventStore        = serviceProvider.GetService <IEventStore>();
                var fakeClock         = FakeClock.FromUtc(2019, 8, 20);
                fakeClock.AutoAdvance = Duration.FromSeconds(1);

                var aggregateId = "3B2358C4-FC85-4EAB-870F-5B908DD8B8A5";

                var testEvent0 = new TestEvent(fakeClock.GetCurrentInstant());
                var testEvent1 = new TestEvent(fakeClock.GetCurrentInstant());
                var testEvent2 = new TestEvent(fakeClock.GetCurrentInstant());

                eventStore.SaveEvents(aggregateId, new[] {
                    testEvent0,
                    testEvent1,
                    testEvent2
                });

                var retrievedEvents = eventStore.GetEventsForAggregate(aggregateId);

                Assert.Equal(0, retrievedEvents[0].Version);
                Assert.Equal(1, retrievedEvents[1].Version);
                Assert.Equal(2, retrievedEvents[2].Version);

                return(Task.CompletedTask);
            });
        }
示例#2
0
        public void UtcDateConstruction()
        {
            Instant   instant = Instant.FromUtc(2010, 1, 1, 0, 0);
            FakeClock clock   = FakeClock.FromUtc(2010, 1, 1);

            Assert.AreEqual(instant, clock.Now);
        }
示例#3
0
        public RegisterUserTest()
        {
            var clock           = FakeClock.FromUtc(2020, 02, 29);
            var userRoleService = new UserRoleDomainService();

            _userRegistrationService = new UserRegistrationDomainService(clock, userRoleService);
        }
示例#4
0
        public void UtcDateTimeConstruction()
        {
            Instant   instant = Instant.FromUtc(2010, 1, 1, 10, 30, 25);
            FakeClock clock   = FakeClock.FromUtc(2010, 1, 1, 10, 30, 25);

            Assert.AreEqual(instant, clock.GetCurrentInstant());
        }
示例#5
0
        public async Task CanDisconnectFromActionstepOrg()
        {
            var fakeClock = FakeClock.FromUtc(2019, 10, 10);
            var now       = fakeClock.GetCurrentInstant();

            var testTokenSetRepository = new TestTokenSetRepository();

            // Add test token
            var testUser = new WCAUser()
            {
                Id = "0"
            };
            const string orgKey = "testOrgKey";

            await testTokenSetRepository.AddOrUpdateTokenSet(new TokenSet("token0", "bearer0", 3600, new Uri("https://test-endpoint/api/"), orgKey, "testRefreshToken", now, testUser.Id));

            // Make sure the test item was added so we can be sure it was removed and not missing to begin with
            Assert.Single(testTokenSetRepository.TokenSets);

            IRequestHandler <DisconnectFromActionstepOrg.DisconnectFromActionstepOrgCommand> handlerUnderTest = new DisconnectFromActionstepOrg.Handler(new DisconnectFromActionstepOrg.ValidatorCollection(), testTokenSetRepository);

            await handlerUnderTest.Handle(new DisconnectFromActionstepOrg.DisconnectFromActionstepOrgCommand()
            {
                AuthenticatedUser = testUser, ActionstepOrgKey = orgKey
            }, new CancellationToken());

            Assert.Empty(testTokenSetRepository.TokenSets);
        }
示例#6
0
        public async Task AddOrUpdateTokenSetThrowsIfOwnerNotFound()
        {
            var options = new DbContextOptionsBuilder <WCADbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(AddOrUpdateTokenSetThrowsIfOwnerNotFound))
                          .Options;

            var clock = FakeClock.FromUtc(2019, 10, 1, 8, 0, 0);

            // Run the test against one instance of the context
            var serviceScopeFactory = new Mock <IServiceScopeFactory>();

            serviceScopeFactory.Setup(f => f.CreateScope()).Returns(() =>
            {
                var serviceScope = new Mock <IServiceScope>();
                serviceScope.Setup(s => s.ServiceProvider.GetService(It.IsAny <Type>())).Returns(new WCADbContextTransient(options));
                return(serviceScope.Object);
            });

            var service = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);

            var ex = await Assert.ThrowsAsync <UserNotFoundException>(async() =>
            {
                await service.AddOrUpdateTokenSet(new TokenSet("at", "testToken0", 3600, new Uri("https://uri/"), "org0", "rt", Instant.FromUtc(2019, 10, 1, 8, 0), userId: "doesNotExistInDb"));
            });

            Assert.Equal("Couldn't find user attempting to add or update TokenSet. (User ID: 'doesNotExistInDb')", ex.Message);
        }
示例#7
0
        public void DateTimeParsing(int year, int month, int day, int hour, int min, string expected)
        {
            var clock = FakeClock.FromUtc(year, month, day, hour, min, 0);

            string result = Utils.DateTime(clock.UtcNow());

            result.Should().Be(expected);
        }
示例#8
0
        public async Task GetTokenWithSubstitution()
        {
            var options = new DbContextOptionsBuilder <WCADbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetTokenWithSubstitution))
                          .Options;

            var clock   = FakeClock.FromUtc(2019, 10, 1, 8, 0, 0);
            var user1Id = string.Empty;

            var serviceScopeFactory = new Mock <IServiceScopeFactory>();

            serviceScopeFactory.Setup(f => f.CreateScope()).Returns(() =>
            {
                var serviceScope = new Mock <IServiceScope>();
                serviceScope.Setup(s => s.ServiceProvider.GetService(It.IsAny <Type>())).Returns(new WCADbContextTransient(options));
                return(serviceScope.Object);
            });

            // Run the test against one instance of the context
            using (var context = new WCADbContextTransient(options))
            {
                var entityEntry1 = context.Users.Add(new WCAUser()
                {
                    Email = "user1@domain"
                });
                var entityEntry2 = context.Users.Add(new WCAUser()
                {
                    Email = "user2@domain"
                });
                await context.SaveChangesAsync();

                user1Id = entityEntry1.Entity.Id;
                var startTime = DateTime.UtcNow;

                context.ActionstepCredentialSubstitutions.Add(new ActionstepCredentialSubstitution()
                {
                    CreatedBy           = entityEntry1.Entity,
                    ForOwner            = entityEntry1.Entity,
                    SubstituteWithOwner = entityEntry2.Entity
                });
                context.SaveChanges();

                // Will be disposed of in implementation
                var service1 = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);

                // Create tokens for each user
                await service1.AddOrUpdateTokenSet(new TokenSet("at", "testToken0", 3600, new Uri("https://uri/"), "org", "rt", Instant.FromUtc(2019, 10, 1, 8, 0), entityEntry1.Entity.Id));

                await service1.AddOrUpdateTokenSet(new TokenSet("at", "testToken1", 3600, new Uri("https://uri/"), "org", "rt", Instant.FromUtc(2019, 10, 1, 8, 0), entityEntry2.Entity.Id));
            }

            // Use a separate instance of the context to verify correct data was saved to database
            var service2         = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);
            var substitutedToken = await service2.GetTokenSet(new TokenSetQuery(user1Id, "org"));

            // Should return second token which was substituted instead of first
            Assert.Equal("testToken1", substitutedToken?.TokenType);
        }
        private static async Task <IReadOnlyList <MasterGame> > SearchGames(string searchString)
        {
            var fakeRepo    = new FakeMasterGameRepo(new FakeFantasyCriticUserStore(FakeClock.FromUtc(2019, 1, 1)));
            var masterGames = await fakeRepo.GetMasterGames();

            var searchResults = MasterGameSearching.SearchMasterGames(searchString, masterGames);

            return(searchResults);
        }
示例#10
0
        public void With_20181102_163030_in_utc_must_be_same_in_utc_now()
        {
            var clock            = FakeClock.FromUtc(2018, 11, 02, 16, 30, 30);
            var dateTimeProvider = new DateTimeProvider(_configuration["TimeZoneId"], clock);
            var utcNow           = dateTimeProvider.UtcNow();
            var expectedNow      = new DateTime(2018, 11, 02, 16, 30, 30);

            utcNow.Should().Be(expectedNow, "because it must be the same time");
        }
示例#11
0
        public void Summer_20180710_163030_in_utc_must_be_20180710_113030_in_mex_local_now()
        {
            var clock            = FakeClock.FromUtc(2018, 07, 10, 16, 30, 30);
            var dateTimeProvider = new DateTimeProvider(_configuration["TimeZoneId"], clock);
            var localNow         = dateTimeProvider.LocalNow();
            var expectedLocalNow = new DateTime(2018, 07, 10, 11, 30, 30);

            localNow.Should().Be(expectedLocalNow, "because mex is -5 in that date");
        }
示例#12
0
        public void Summer_local_today_with_20180710_163030_in_utc_must_be_20180710_0500_for_mex()
        {
            var clock            = FakeClock.FromUtc(2018, 07, 10, 16, 30, 30);
            var dateTimeProvider = new DateTimeProvider(_configuration["TimeZoneId"], clock);
            var todayMexInUtc    = dateTimeProvider.TodayLocalInUtc();
            var expectedToday    = new DateTime(2018, 07, 10, 05, 00, 00);

            todayMexInUtc.Should().Be(expectedToday, "because mex is -5 in UTC for summer");
        }
示例#13
0
        public void Winter_local_today_with_20181102_163030_in_utc_must_be_20181102_0600_for_mex()
        {
            var clock            = FakeClock.FromUtc(2018, 11, 02, 16, 30, 30);
            var dateTimeProvider = new DateTimeProvider(_configuration["TimeZoneId"], clock);
            var todayMexInUtc    = dateTimeProvider.TodayLocalInUtc();
            var expectedToday    = new DateTime(2018, 11, 02, 06, 00, 00);

            todayMexInUtc.Should().Be(expectedToday, "because mex is -6 in UTC for winter");
        }
示例#14
0
        public void AbortParsingJwtStringWhenExpired()
        {
            var clock = FakeClock.FromUtc(2020, 12, 31);

            bool success = JsonWebToken.TryParseFromJwtString(JWT_STRING, clock, out var jwt);

            success.Should().BeFalse();
            jwt.Should().BeNull();
        }
        public InMemoryUnitOfWorkTest()
        {
            _clock = FakeClock.FromUtc(2020, 02, 29);
            _fakeDomainEventHandler = new FakeDomainEventHandler();
            _unitOfWork             = new InMemoryUnitOfWork(_clock, IdTestHelper.BuildFakeGenerator());

            AuthUserDatabase.Get.AuthUsersTable.Clear();
            AuthUserDatabase.Get.RolesTable.Clear();
            AuthUserDatabase.Get.DomainEventsTable.Clear();
        }
示例#16
0
        public void AbortParsingJwtStringWhenInvalidHash()
        {
            var clock = FakeClock.FromUtc(2020, 01, 16, 12, 0, 0);

            string invalidJwtString = JWT_STRING.Substring(0, JWT_STRING.Length - 1) + 'A';
            bool   success          = JsonWebToken.TryParseFromJwtString(invalidJwtString, clock, out var jwt);

            success.Should().BeFalse();
            jwt.Should().BeNull();
        }
示例#17
0
        public void ParseValidJwtString()
        {
            var clock = FakeClock.FromUtc(2020, 01, 16, 12, 0, 0);

            bool success = JsonWebToken.TryParseFromJwtString(JWT_STRING, clock, out var jwt);

            success.Should().BeTrue();
            jwt.Should().NotBeNull();
            jwt !.UserId.Should().Be(UserId);
        }
        public void WithGeneralIsoZonedDateTimeSerializer_Deserialize()
        {
            var clock       = FakeClock.FromUtc(2014, 05, 02, 10, 30, 45);
            var now         = clock.Now.InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault());
            var serialisers = new DefaultNodaSerializerSettings(DateTimeZoneProviders.Tzdb)
                              .WithGeneralIsoZonedDateTimeSerializer();

            var expected = now;
            var actual   = serialisers.ZonedDateTimeSerializer.Deserialize(now.ToString());

            Assert.Equal(expected, actual);
        }
示例#19
0
        public void TestGenerateJwtString()
        {
            var registeredUser = RoleTestHelper.RegisteredUser().WithId(2).Build();
            var authUser       = BuildAuthUser(UserId, "User", registeredUser);

            var clock = FakeClock.FromUtc(2020, 01, 16, 12, 0, 0);

            var    token     = JsonWebToken.Generate(authUser, clock);
            string jwtString = token.ToJwtString();

            jwtString.Should().Be(JWT_STRING);
        }
示例#20
0
        public void TestUtcNow()
        {
            var clock = FakeClock.FromUtc(2020, 02, 29, 23, 59, 18);

            var now = clock.UtcNow();

            now.Year.Should().Be(2020);
            now.Month.Should().Be(2);
            now.Day.Should().Be(29);
            now.Hour.Should().Be(23);
            now.Minute.Should().Be(59);
            now.Second.Should().Be(18);
        }
示例#21
0
        public void EventHasEventIdSet()
        {
            var fakeClock = FakeClock.FromUtc(2019, 8, 20);

            fakeClock.AutoAdvance = Duration.FromSeconds(1);

            var testEvent = new TestEvent(fakeClock.GetCurrentInstant())
            {
                SomeTestValue = "Test Value 1"
            };

            Assert.NotEqual(Guid.Empty, testEvent.EventId);
        }
示例#22
0
        public async Task ShouldRefreshAllRefreshableTokens()
        {
            using (var authDelegatingHandler = new AuthDelegatingHandler()
            {
                InnerHandler = _handler
            })
                using (var httpClient = new HttpClient(authDelegatingHandler))
                    using (var memoryCache = new MemoryCache(new MemoryCacheOptions()))
                    {
                        var fakeClock = FakeClock.FromUtc(2019, 10, 10);
                        var now       = fakeClock.GetCurrentInstant();

                        var testTokenSetRepository = new TestTokenSetRepository();

                        //// Add test tokens

                        // Valid tokens (shouldn't be refreshed)
                        await testTokenSetRepository.AddOrUpdateTokenSet(new TokenSet("token0", "bearer0", 3600, new Uri("https://test-endpoint/api/"), "testOrgKey", "testRefreshToken", now, "0", "0"));

                        await testTokenSetRepository.AddOrUpdateTokenSet(new TokenSet("token1", "bearer1", 3600, new Uri("https://test-endpoint/api/"), "testOrgKey", "testRefreshToken", now, "1", "1"));

                        // Nearing expiry (should be refreshed)
                        await testTokenSetRepository.AddOrUpdateTokenSet(new TokenSet("token2", "bearer2", 3600, new Uri("https://test-endpoint/api/"), "testOrgKey", "testRefreshToken", now.Minus(Duration.FromDays(18)), "2", "2"));

                        // Expired (shouldn't be refreshed, as it will fail anyway)
                        await testTokenSetRepository.AddOrUpdateTokenSet(new TokenSet("token3", "bearer3", 3600, new Uri("https://test-endpoint/api/"), "testOrgKey", "testRefreshToken", now.Minus(Duration.FromDays(30)), "3", "3"));

                        var actionstepServiceConfigurationOptions = new ActionstepServiceConfigurationOptions("clientId", "clientSecret");
                        var actionstepService = new ActionstepService(new NullLogger <ActionstepService>(), httpClient, actionstepServiceConfigurationOptions, testTokenSetRepository, fakeClock, memoryCache);

                        var config = new ConfigurationBuilder();
                        config.AddInMemoryCollection(new Dictionary <string, string>()
                        {
                            { "WCACoreSettings:PEXASettings:Environment", "Test" }
                        });

                        var wcaCoreSettingsOptions = Options.Create(config.Build().Get <WCACoreSettings>());

                        var refreshTokens = new RefreshAllTokens(testTokenSetRepository, actionstepService, fakeClock);

                        await refreshTokens.Run(null, new NullLogger <RefreshAllTokens>());

                        Assert.Equal("token0", testTokenSetRepository.TokenSets.Single(t => t.Id == "0").AccessToken);
                        Assert.Equal("token1", testTokenSetRepository.TokenSets.Single(t => t.Id == "1").AccessToken);
                        Assert.Equal("updatedAccessToken", testTokenSetRepository.TokenSets.Single(t => t.Id == "2").AccessToken);
                        Assert.Equal("token3", testTokenSetRepository.TokenSets.Single(t => t.Id == "3").AccessToken);
                    }
        }
示例#23
0
        public async Task GetTokensByRefreshExpiryReturnsCorrectItems()
        {
            var options = new DbContextOptionsBuilder <WCADbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetTokensByRefreshExpiryReturnsCorrectItems))
                          .Options;

            var clock = FakeClock.FromUtc(2019, 10, 1, 8, 0, 0);

            var serviceScopeFactory = new Mock <IServiceScopeFactory>();

            serviceScopeFactory.Setup(f => f.CreateScope()).Returns(() =>
            {
                var serviceScope = new Mock <IServiceScope>();
                serviceScope.Setup(s => s.ServiceProvider.GetService(It.IsAny <Type>())).Returns(new WCADbContextTransient(options));
                return(serviceScope.Object);
            });

            // Run the test against one instance of the context
            using (var context = new WCADbContextTransient(options))
            {
                var entityEntry = context.Users.Add(new WCAUser());
                await context.SaveChangesAsync();

                var service1 = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);

                /// Expiry will be 21 days after <see cref="TokenSet.ReceivedAt"/>.
                /// These two should expire on 22 Oct 2019
                /// Org keys must be different because only one set of credentials can be stored per user+org combination.
                await service1.AddOrUpdateTokenSet(new TokenSet("at", "testToken0", 3600, new Uri("https://uri/"), "org0", "rt", Instant.FromUtc(2019, 10, 1, 8, 0), entityEntry.Entity.Id));

                await service1.AddOrUpdateTokenSet(new TokenSet("at", "testToken1", 3600, new Uri("https://uri/"), "org1", "rt", Instant.FromUtc(2019, 10, 1, 8, 0), entityEntry.Entity.Id));

                /// These two should expire on 23 Oct 2019
                await service1.AddOrUpdateTokenSet(new TokenSet("at", "testToken2", 3600, new Uri("https://uri/"), "org2", "rt", Instant.FromUtc(2019, 10, 2, 8, 0), entityEntry.Entity.Id));

                await service1.AddOrUpdateTokenSet(new TokenSet("at", "testToken3", 3600, new Uri("https://uri/"), "org3", "rt", Instant.FromUtc(2019, 10, 2, 8, 0), entityEntry.Entity.Id));

                context.SaveChanges();
            }

            // Use a separate instance of the context to verify correct data was saved to database
            var service2            = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);
            var tokensAboutToExpire = await service2.GetTokensByRefreshExpiry(Instant.FromUtc(2019, 10, 22, 9, 0));

            Assert.Equal(2, tokensAboutToExpire.Count());
            Assert.NotNull(tokensAboutToExpire.Single(t => t.TokenType.Equals("testToken0", StringComparison.InvariantCulture)));
            Assert.NotNull(tokensAboutToExpire.Single(t => t.TokenType.Equals("testToken1", StringComparison.InvariantCulture)));
        }
示例#24
0
                public void CleansUpOldExports()
                {
                    var mockFileManager = new Mock <IFileManager>();
                    var clock           = FakeClock.FromUtc(2020, 01, 01, 01, 01, 00);

                    var sut = GetSut(
                        clock: clock,
                        fileManager: mockFileManager.Object);

                    sut.Exporter.Command.Execute(null);

                    var fiveMinutesAgo = clock.InTzdbSystemDefaultZone().GetCurrentLocalDateTime().Minus(Period.FromMinutes(5));

                    mockFileManager.Verify(f => f.DeleteExportsBefore(It.Is((LocalDateTime l) =>
                                                                            l == fiveMinutesAgo)));
                }
示例#25
0
        public async Task CanGetTokenById()
        {
            var options = new DbContextOptionsBuilder <WCADbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CanGetTokenById))
                          .Options;

            var clock      = FakeClock.FromUtc(2019, 10, 1, 8, 0, 0);
            var user1Id    = string.Empty;
            var tokenSetId = string.Empty;

            var serviceScopeFactory = new Mock <IServiceScopeFactory>();

            serviceScopeFactory.Setup(f => f.CreateScope()).Returns(() =>
            {
                var serviceScope = new Mock <IServiceScope>();
                serviceScope.Setup(s => s.ServiceProvider.GetService(It.IsAny <Type>())).Returns(new WCADbContextTransient(options));
                return(serviceScope.Object);
            });

            // Run the test against one instance of the context
            using (var context = new WCADbContextTransient(options))
            {
                var entityEntry1 = context.Users.Add(new WCAUser()
                {
                    Email = "user1@domain"
                });
                await context.SaveChangesAsync();

                user1Id = entityEntry1.Entity.Id;
                var startTime = DateTime.UtcNow;

                var service1 = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);

                // Create token to test retrieval
                var addedTokenSet = await service1.AddOrUpdateTokenSet(new TokenSet("at", "testToken", 3600, new Uri("https://uri/"), "org", "rt", Instant.FromUtc(2019, 10, 1, 8, 0), entityEntry1.Entity.Id));

                tokenSetId = addedTokenSet.Id;
            }

            // Use a separate instance of the context to verify correct data was saved to database
            var service2          = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);
            var retrievedTokenSet = await service2.GetTokenSetById(tokenSetId);

            // Should return second token which was substituted instead of first
            Assert.Equal("testToken", retrievedTokenSet.TokenType);
        }
示例#26
0
        public async Task GetTokenReturnsNullIfNotFound()
        {
            var options = new DbContextOptionsBuilder <WCADbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(GetTokenReturnsNullIfNotFound))
                          .Options;

            var clock = FakeClock.FromUtc(2019, 10, 1, 8, 0, 0);

            var serviceScopeFactory = new Mock <IServiceScopeFactory>();

            serviceScopeFactory.Setup(f => f.CreateScope()).Returns(() =>
            {
                var serviceScope = new Mock <IServiceScope>();
                serviceScope.Setup(s => s.ServiceProvider.GetService(It.IsAny <Type>())).Returns(new WCADbContextTransient(options));
                return(serviceScope.Object);
            });

            var service = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);
            var tokenShouldntBeFound = await service.GetTokenSet(new TokenSetQuery("User doesn't exist", "Org doesn't exist"));

            Assert.Null(tokenShouldntBeFound);
        }
示例#27
0
        public async Task CanAddTokenSet()
        {
            var options = new DbContextOptionsBuilder <WCADbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(CanAddTokenSet))
                          .Options;

            var clock      = FakeClock.FromUtc(2019, 10, 1, 8, 0, 0);
            var tokenSetId = string.Empty;

            // Run the test against one instance of the context
            using (var context = new WCADbContextTransient(options))
            {
                var entityEntry1 = context.Users.Add(new WCAUser()
                {
                    Email = "user1@domain"
                });
                await context.SaveChangesAsync();

                var startTime = DateTime.UtcNow;

                var serviceScopeFactory = new Mock <IServiceScopeFactory>();
                serviceScopeFactory.Setup(f => f.CreateScope()).Returns(() =>
                {
                    var serviceScope = new Mock <IServiceScope>();
                    serviceScope.Setup(s => s.ServiceProvider.GetService(It.IsAny <Type>())).Returns(new WCADbContextTransient(options));
                    return(serviceScope.Object);
                });

                var tokenSetRepository = new TokenSetRepository(new TestTelemetryLogger(), serviceScopeFactory.Object, clock);

                // Create token to test retrieval
                var addedTokenSet = await tokenSetRepository.AddOrUpdateTokenSet(new TokenSet(nameof(CanAddTokenSet), "testToken", 3600, new Uri("https://uri/"), "org", "rt", Instant.FromUtc(2019, 10, 1, 8, 0), entityEntry1.Entity.Id));

                var savedCredential = context.ActionstepCredentials.AsNoTracking().ToArray()[0];

                Assert.Equal(nameof(CanAddTokenSet), savedCredential.AccessToken);
            }
        }
示例#28
0
        public async Task CanSaveAndReadSingleEventForAggregate()
        {
            await _containerFixture.ExecuteScopeAsync(serviceProvider =>
            {
                var eventStore        = serviceProvider.GetService <IEventStore>();
                var fakeClock         = FakeClock.FromUtc(2019, 8, 20);
                fakeClock.AutoAdvance = Duration.FromSeconds(1);

                var aggregateId = "88E14BDE-9559-4A42-9535-0DF49CB9CBED";

                var testEvent = new TestEvent(fakeClock.GetCurrentInstant())
                {
                    SomeTestValue = "Test Value 1"
                };

                eventStore.SaveEvents(aggregateId, new[] { testEvent }, 0);

                var retrievedEvents = eventStore.GetEventsForAggregate(aggregateId);

                Assert.Equal(testEvent.SomeTestValue, (retrievedEvents[0] as TestEvent).SomeTestValue);

                return(Task.CompletedTask);
            });
        }
示例#29
0
        public async Task EventIdIsPersisted()
        {
            await _containerFixture.ExecuteScopeAsync(serviceProvider =>
            {
                var eventStore        = serviceProvider.GetService <IEventStore>();
                var fakeClock         = FakeClock.FromUtc(2019, 8, 20);
                fakeClock.AutoAdvance = Duration.FromSeconds(1);

                var aggregateId = "64DF4C71-FC0A-45B4-91FE-E5393A68E7F3";

                var testEvent = new TestEvent(fakeClock.GetCurrentInstant())
                {
                    SomeTestValue = "Test Value 1"
                };

                eventStore.SaveEvents(aggregateId, new[] { testEvent }, 0);

                var retrievedEvents = eventStore.GetEventsForAggregate(aggregateId);

                Assert.Equal(testEvent.EventId, (retrievedEvents[0] as TestEvent).EventId);

                return(Task.CompletedTask);
            });
        }
示例#30
0
        public SummaryTests()
        {
            clock = FakeClock.FromUtc(2020, 10, 20);

            noLabel = new DefaultSummary("noLabel", new SummaryOptions
            {
                Help = "help noLabels",
            }, clock);

            labeled = new DefaultSummary("labeled", new SummaryOptions
            {
                Help       = "help labeled",
                LabelNames = Labeled.SingleLabels
            }, clock);

            noLabelAndQuantiles = new DefaultSummary("no_labels_and_quantiles", new SummaryOptions
            {
                Help       = "help noLabelAndQuantiles",
                Objectives = new[] {
                    new SummaryObjective(0.5, 0.05),
                    new SummaryObjective(0.9, 0.01),
                    new SummaryObjective(0.99, 0.001)
                }
            }, clock);

            labelAndQuantiles = new DefaultSummary("labels_and_quantiles", new SummaryOptions
            {
                Help       = "help labelAndQuantiles",
                LabelNames = Labeled.SingleLabels,
                Objectives = new[] {
                    new SummaryObjective(0.5, 0.05),
                    new SummaryObjective(0.9, 0.01),
                    new SummaryObjective(0.99, 0.001)
                }
            }, clock);
        }