public async Task ShouldReturnGames(IGameRepository repository) { GameDomainService sut = new GameDomainService(repository); System.Collections.Generic.IEnumerable <Game> result = sut.GetAll(); await repository.Received().GetAll(); result.Should().NotBeNull(); result.Should().HaveCountGreaterOrEqualTo(0); }
public void GetDataFromMarketWithSpecialChar() { IExchangeAPI api = ExchangeAPI.GetExchangeAPIAsync("Bitfinex").Result; string marketTicker = "DOGE:USD"; DateTime start = new DateTime(2021, 12, 1); DateTime end = DateTime.Today; System.Collections.Generic.IEnumerable <MarketCandle> result = api.GetCandlesAsync(marketTicker, 86400, start, end, 1000).Result; result.Should().HaveCountGreaterThan(0, "Returned data"); }
public async ValueTask WorkWithCachedSpecification() { const string dbName = "FakeDatabase"; using (TrainingDb dbContext = this.testFixture.CreateInMemoryDbContext(dbName)) { dbContext.Database.EnsureCreated(); IOptions <MemoryCacheOptions> memCacheOptions = Options.Create <MemoryCacheOptions>(new MemoryCacheOptions()); var memoryCache = new MemoryCache(memCacheOptions); IReadonlyRepository <Login> repo = new CachedRepository <Login, TrainingDb>(dbContext, memoryCache); ISpecification <Login> spec = this.specificationFactories.For <Login>() .Where(l => l.Id == 1) .Include(l => l.Student) .Not() .AsCached(TimeSpan.FromHours(12), 1); System.Collections.Generic.IEnumerable <Login> logins = await repo.ListAsync(spec); logins.Should().HaveCount(2); logins.Select(l => l.Student).Should().NotBeNull(); // Let's create a new repository instance with the same cache // I would expect in this case that the repository returns the same instances // if they have been retrieved from the cache. repo = new CachedRepository <Login, TrainingDb>(dbContext, memoryCache); System.Collections.Generic.IEnumerable <Login> cachedLogins = await repo.ListAsync(spec); cachedLogins.Should().HaveCount(2); cachedLogins.Should().BeSameAs(logins); } }
public async ValueTask WorkWithAndExpression() { const string dbName = "FakeDatabase"; using TrainingDb dbContext = this.testFixture.CreateInMemoryDbContext(dbName); dbContext.Database.EnsureCreated(); IReadonlyRepository <Login> repo = new Repository <Login, TrainingDb>(dbContext); ISpecification <Login> spec = this.specificationFactories.For <Login>().Where(l => l.Id >= 1) .And(l2 => l2.Id <= 2) .Include(l => l.Student); System.Collections.Generic.IEnumerable <Login> logins = await repo.ListAsync(spec); logins.Should().HaveCount(2); logins.Select(l => l.Student).Should().NotBeNull(); }
public async ValueTask ReturnAllStudentsSpecificationWithIncludesToLoginAndSessionAndCourse() { const string dbName = "FakeDatabase"; using (TrainingDb dbContext = this.testFixture.CreateInMemoryDbContext(dbName)) { dbContext.Database.EnsureCreated(); var repo = new StudentRepository(dbContext); var specification = new AllStudentsSpecification(); System.Collections.Generic.IEnumerable <Student> allStudents = await repo.ListAsync(specification .Including(st => st.Login)); allStudents.All(student => specification.Test(student)).Should().BeTrue(); allStudents.Should().HaveCount(3); allStudents.Select(st => st.Login) .Should().NotBeNull(); allStudents.Select(st => st.Sessions) .Should().NotBeNull(); allStudents.SelectMany(st => st.Sessions) .Select(ss => ss.Session) .Select(s => s.Course).Should().NotBeNull(); foreach (Student student in allStudents) { student.Login.Should().NotBeNull(); student.Sessions.Should().NotBeNull(); foreach (StudentSession session in student.Sessions) { session.Session.Should().NotBeNull(); session.Session.Course.Should().NotBeNull(); } } } }
private static void VerifyMatchNotInCollection(System.Collections.Generic.IEnumerable <Match> matchCollection, Match match) { matchCollection.Should().NotContain(x => MatchIsEquivalent(match, x)); }