public async Task QueryBy_Complex() { //Arrange DateTime dateTime = new DateTime(2021, 1, 5, 21, 10, 23); IConnectionMultiplexer connectionMultiplexer = FakesFactory.CreateConnectionMultiplexerFake(); StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(connectionMultiplexer); StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); teslaEntity.IsActive = false; teslaEntity.CreatedDateTime = dateTime; await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); microsoftEntity.CreatedDateTime = dateTime.AddSeconds(60); await stubStockRepository.AddAsync(microsoftEntity); StockEntity rheinEnergyEntity = new StockEntity("Rhein Energy", StockSector.Energy, 294.21, 8.5); rheinEnergyEntity.CreatedDateTime = dateTime.AddSeconds(120); await stubStockRepository.AddAsync(rheinEnergyEntity); //Act QueryProvider provider = new RedisQueryProvider(connectionMultiplexer); RedisQuery <StockEntity> redisQuery = new RedisQuery <StockEntity>(provider); IQueryable <StockEntity> query = redisQuery.Where(s => (s.IsActive == false && s.FirstLetterOfName == 'T' && s.CreatedDateTime == dateTime && (s.LastByteOfName == (byte)'L' || s.LengthOfNameInt < 6)) || (s.CreatedDateTime > dateTime.AddSeconds(90) && s.LengthOfNameUlong == (ulong)"Rhein Energy".Length)); List <StockEntity> result = query.ToList(); //Assert Assert.Equal(2, result.Count); Assert.Equal(" {{StockEntity:IsActive-Boolean:False}} {{StockEntity:FirstLetterOfName-Int32:84:=}} {{Intersection}} {{StockEntity:CreatedDateTime-DateTime:637454778230000000:=}} {{Intersection}} {{StockEntity:LastByteOfName-Int32:76:=}} {{StockEntity:LengthOfNameInt-Int32:6:<}} {{Union}}{{Intersection}} {{StockEntity:CreatedDateTime-DateTime:637454779130000000:>}} {{StockEntity:LengthOfNameUlong-UInt64:12:=}} {{Intersection}}{{Union}}", query.ToString()); }
public async void HashSetHashGetAllAndConvertFromHashEntryList_HashSet_ReturnEntityWithValues() { //Arrange IDatabase fakeDatabase = FakesFactory.CreateDatabaseFake(); //Act StockMetaData metaData = new StockMetaData("USA", CurrencyCode.USD); StockEntity expectedTeslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5, metaData); await fakeDatabase.HashSetAsync(expectedTeslaEntity); HashEntry[] hashEntries = await fakeDatabase.HashGetAllAsync(expectedTeslaEntity.GetRedisKey()); StockEntity teslaEntity = hashEntries.ConvertFromHashEntryList <StockEntity>(); //Assert Assert.Equal(expectedTeslaEntity.Id, teslaEntity.Id); Assert.Equal(expectedTeslaEntity.Name, teslaEntity.Name); Assert.Equal(expectedTeslaEntity.Symbol, teslaEntity.Symbol); Assert.Equal(expectedTeslaEntity.Sector, teslaEntity.Sector); Assert.Equal(expectedTeslaEntity.Price, teslaEntity.Price); Assert.Equal(expectedTeslaEntity.PriceChangeRate, teslaEntity.PriceChangeRate); Assert.Equal(expectedTeslaEntity.CreatedDateTime, teslaEntity.CreatedDateTime); Assert.Equal(expectedTeslaEntity.IsActive, teslaEntity.IsActive); Assert.Equal(expectedTeslaEntity.MetaData.Country, teslaEntity.MetaData.Country); Assert.Equal(expectedTeslaEntity.MetaData.Currency, teslaEntity.MetaData.Currency); Assert.Equal(expectedTeslaEntity.MetaData.UpdateDateTime, teslaEntity.MetaData.UpdateDateTime); }
public async Task QueryBy_Boolean() { //Arrange IConnectionMultiplexer connectionMultiplexer = FakesFactory.CreateConnectionMultiplexerFake(); StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(connectionMultiplexer); StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); teslaEntity.IsActive = false; await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); await stubStockRepository.AddAsync(appleEntity); //Act QueryProvider provider = new RedisQueryProvider(connectionMultiplexer); RedisQuery <StockEntity> redisQuery = new RedisQuery <StockEntity>(provider); IQueryable <StockEntity> query = redisQuery.Where(s => (s.IsActive == true)); List <StockEntity> result = query.ToList(); //Assert Assert.Equal(2, result.Count); }
public async void AddCountEntity_AddEnttiy_ReturnCountByBranch() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sectorBranch = new RedisBranch <StockEntity>(); sectorBranch.SetBranchId("BRANCH_SECTOR"); sectorBranch.FilterBy(i => i.IsActive).GroupBy("Sector"); stubStockRepository.AddBranch(sectorBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); await stubStockRepository.AddAsync(appleEntity); long actualCount = await stubStockRepository.CountAsync("BRANCH_SECTOR", "Technology"); //Assert Assert.Equal(3, actualCount); }
public async void AddGetEntity_AddEnttiy_ReturnEntityByIdAndClassProperty() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); //Act StockMetaData metaData = new StockMetaData("USA", CurrencyCode.USD); StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5, metaData); string dummyString = teslaEntity.DummyString; string entityId = teslaEntity.Id; await stubStockRepository.AddAsync(teslaEntity); StockEntity expectedEntity = await stubStockRepository.GetByIdAsync(entityId); //Assert Assert.NotNull(expectedEntity); Assert.Equal(expectedEntity.Id, teslaEntity.Id); Assert.Equal(expectedEntity.Name, teslaEntity.Name); Assert.Equal(expectedEntity.Sector, teslaEntity.Sector); Assert.Equal(expectedEntity.Price, teslaEntity.Price); Assert.Equal(expectedEntity.PriceChangeRate, teslaEntity.PriceChangeRate); Assert.Equal(expectedEntity.CreatedDateTime, teslaEntity.CreatedDateTime); Assert.Equal(expectedEntity.IsActive, teslaEntity.IsActive); Assert.NotNull(dummyString); Assert.True(expectedEntity.DummyString == default); Assert.Equal(expectedEntity.MetaData.Currency, metaData.Currency); Assert.Equal(expectedEntity.MetaData.Country, metaData.Country); Assert.Equal(expectedEntity.MetaData.UpdateDateTime, metaData.UpdateDateTime); }
public void AddLayoutValue_WithSameFieldInDifferentDatabases_AddsEntriesForBoth() { // Arrange var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings()) { Enabled = true }; cache.Clear(); var id = new ID(); var masterField = MasterFakesFactory.CreateFakeLayoutField(id); Field webField; using (var webDb = new Db("web")) { var webFakesFactory = new FakesFactory(webDb); webField = webFakesFactory.CreateFakeLayoutField(id); } // Act cache.AddLayoutValue(masterField.Item, masterField.Value); cache.AddLayoutValue(webField.Item, webField.Value); // Assert Assert.Equal(2, cache.InnerCache.Count); }
public async void AddGetEntity_AddEnttiy_ReturnEntityByPropertyGroupBranch() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sectorBranch = new RedisBranch <StockEntity>(); sectorBranch.SetBranchId("BRANCH_SECTOR"); sectorBranch.FilterBy(i => i.IsActive).GroupBy("Sector"); stubStockRepository.AddBranch(sectorBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); IEnumerable <StockEntity> expectedEntities = await stubStockRepository.GetAsync("BRANCH_SECTOR", "Technology"); //Assert Assert.Single(expectedEntities); Assert.Equal(expectedEntities.ElementAt(0).Id, teslaEntity.Id); Assert.Equal(expectedEntities.ElementAt(0).Name, teslaEntity.Name); Assert.Equal(expectedEntities.ElementAt(0).Sector, teslaEntity.Sector); Assert.Equal(expectedEntities.ElementAt(0).Price, teslaEntity.Price); Assert.Equal(expectedEntities.ElementAt(0).PriceChangeRate, teslaEntity.PriceChangeRate); Assert.Equal(expectedEntities.ElementAt(0).CreatedDateTime, teslaEntity.CreatedDateTime); Assert.Equal(expectedEntities.ElementAt(0).IsActive, teslaEntity.IsActive); }
public void ProcessItemUpdate_WithEntriesInDifferentDatabases_OnlyRemovesEntryForMatchingDatabase() { // Arrange var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings(new[] { "master" })) { Enabled = true }; cache.Clear(); var id = new ID(); var masterField = MasterFakesFactory.CreateFakeLayoutField(id); Field webField; using (var webDb = new Db("web")) { var webFakesFactory = new FakesFactory(webDb); webField = webFakesFactory.CreateFakeLayoutField(id); } cache.AddLayoutValue(masterField.Item, masterField.Value); cache.AddLayoutValue(webField.Item, webField.Value); // Act cache.ProcessItemUpdate(masterField.Item); // Assert Assert.Null(cache.GetLayoutValue(masterField.Item)); Assert.Equal(1, cache.InnerCache.Count); }
public async void AddGetEntity_AddEnttiy_ReturnEntityByIdAndNullForIgnoreDataMemberProperty() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); string dummyString = teslaEntity.DummyString; string entityId = teslaEntity.Id; await stubStockRepository.AddAsync(teslaEntity); StockEntity expectedEnty = await stubStockRepository.GetByIdAsync(entityId); //Assert Assert.NotNull(expectedEnty); Assert.Equal(expectedEnty.Id, teslaEntity.Id); Assert.Equal(expectedEnty.Name, teslaEntity.Name); Assert.Equal(expectedEnty.Sector, teslaEntity.Sector); Assert.Equal(expectedEnty.Price, teslaEntity.Price); Assert.Equal(expectedEnty.PriceChangeRate, teslaEntity.PriceChangeRate); Assert.Equal(expectedEnty.CreatedDateTime, teslaEntity.CreatedDateTime); Assert.Equal(expectedEnty.IsActive, teslaEntity.IsActive); Assert.NotNull(dummyString); Assert.True(expectedEnty.DummyString == default); }
public async void AddGetEntity_AddEnttiy_ReturnEntityById() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> allBranch = new RedisBranch <StockEntity>(); allBranch.SetBranchId("BRANCH_ALL"); allBranch.FilterBy(i => i.IsActive).GroupBy("All", i => "All"); stubStockRepository.AddBranch(allBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); StockEntity expectedTeslaEntity = await stubStockRepository.GetByIdAsync(teslaEntity.Id); //Assert Assert.Equal(expectedTeslaEntity.Id, teslaEntity.Id); Assert.Equal(expectedTeslaEntity.Name, teslaEntity.Name); Assert.Equal(expectedTeslaEntity.Sector, teslaEntity.Sector); Assert.Equal(expectedTeslaEntity.Price, teslaEntity.Price); Assert.Equal(expectedTeslaEntity.PriceChangeRate, teslaEntity.PriceChangeRate); Assert.Equal(expectedTeslaEntity.CreatedDateTime, teslaEntity.CreatedDateTime); Assert.Equal(expectedTeslaEntity.IsActive, teslaEntity.IsActive); }
public async Task QueryBy_DateTime() { //Arrange DateTime dateTime = new DateTime(2021, 1, 5, 21, 10, 23); IConnectionMultiplexer connectionMultiplexer = FakesFactory.CreateConnectionMultiplexerFake(); StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(connectionMultiplexer); StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); teslaEntity.CreatedDateTime = dateTime; await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); microsoftEntity.CreatedDateTime = dateTime.AddSeconds(60); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); appleEntity.CreatedDateTime = dateTime.AddSeconds(120); await stubStockRepository.AddAsync(appleEntity); //Act QueryProvider provider = new RedisQueryProvider(connectionMultiplexer); RedisQuery <StockEntity> redisQuery = new RedisQuery <StockEntity>(provider); IQueryable <StockEntity> query = redisQuery.Where(s => (s.CreatedDateTime < dateTime.AddSeconds(90))); List <StockEntity> result = query.ToList(); //Assert Assert.Equal(2, result.Count); }
public async void AddCountEntity_AddEnttiy_ReturnCountBySortedBranch() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sectorAndSortedCreatedDateTimeBranch = new RedisBranch <StockEntity>(); sectorAndSortedCreatedDateTimeBranch.SetBranchId("BRANCH_SECTOR_SORT_PRICE"); sectorAndSortedCreatedDateTimeBranch.FilterBy(i => i.IsActive).GroupBy("Sector").SortBy("Price"); stubStockRepository.AddBranch(sectorAndSortedCreatedDateTimeBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); teslaEntity.CreatedDateTime = DateTimeOffset.UtcNow.AddSeconds(-15).DateTime; await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); await stubStockRepository.AddAsync(appleEntity); long actualCount = await stubStockRepository.CountAsync("BRANCH_SECTOR_SORT_PRICE", 210, 250, "Technology"); //Assert Assert.Equal(1, actualCount); }
public void SetUp() { _sources = FakesFactory.CreateFakeEventProviders(); _targets = FakesFactory.CreateFakeTargets(); _smsProviderConfig = new FakeSmsNotificationProviderConfig(); _notificationProvider = new SmsNotificationProvider(_smsProviderConfig); _service = new NotificationService(); }
public void AddBranch_AddSingleBranch_ReturnCreatedBranchAndDefaultDataBranch() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); //Act IBranch <StockEntity> allBranch = new RedisBranch <StockEntity>(); allBranch.SetBranchId("BRANCH_ALL"); allBranch.FilterBy(i => i.IsActive).GroupBy("All", i => "All"); stubStockRepository.AddBranch(allBranch); //Assert Assert.Equal(20, stubStockRepository.GetBranches().Count()); }
public void GroupBy_GroupByNotExistProperty_ThrowsArgumentException() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> technologyBranch = new RedisBranch <StockEntity>(); technologyBranch.SetBranchId("BRANCH_NOTVALID"); //Act Action act = () => technologyBranch.GroupBy("NotExist"); //Assert ArgumentException exception = Assert.Throws <ArgumentException>(act); Assert.Equal($"NotExist is not member of {typeof(StockEntity).Name}.", exception.Message); }
public void GroupBy_GroupByInvalidProperty_ThrowsArgumentException() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> technologyBranch = new RedisBranch <StockEntity>(); technologyBranch.SetBranchId("BRANCH_NOTVALID"); //Act Action act = () => technologyBranch.GroupBy("MetaData"); //Assert ArgumentException exception = Assert.Throws <ArgumentException>(act); Assert.Equal($"MetaData is StockMetaData. GroupByProperty only applied on value types and string.", exception.Message); }
public async Task DatabaseFixture_EFInMemoryLoggingEnabled_LogsPopulated() { var person = FakesFactory.Create <Person>(); await _DatabaseFixture.PerformDatabaseOperation(async context => { context.Persons.Add(person); await context.SaveChangesAsync(); }); var logger = _DatabaseFixture .GetInMemoryLoggers()["Microsoft.EntityFrameworkCore.Database.Command"]; Assert.NotEmpty(logger.Logs); Assert.NotEqual(0, logger.Logs.First().EventId); }
public void AddRedisBranch_AddBranchesToServiceCollection_ReturnRedisBranch() { //Arrange IServiceCollection services = new ServiceCollection(); services.AddSingleton <IConnectionMultiplexer>(sp => { return(FakesFactory.CreateConnectionMultiplexerFake()); }); //Act services.AddRedisBranch(Assembly.GetExecutingAssembly()); //Assert //Connection Multiplexer and StockRepository Assert.Equal(2, services.Count); }
public void AddRedisBranch_AddBranchesToServiceCollectionAndBuildProvider_GetRedisBranch() { //Arrange IServiceCollection services = new ServiceCollection(); services.AddSingleton <IConnectionMultiplexer>(sp => { return(FakesFactory.CreateConnectionMultiplexerFake()); }); //Act services.AddRedisBranch(Assembly.GetExecutingAssembly()); ServiceProvider provider = services.BuildServiceProvider(); IRedisRepository <StockEntity> notNullStockEntity = provider.GetRequiredService <IRedisRepository <StockEntity> >(); //Assert Assert.NotNull(notNullStockEntity); }
public async void AddGetEntity_AddEnttiy_ReturnEntityByFunctionSortBranch() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sectorAndSortedCreatedDateTimeBranch = new RedisBranch <StockEntity>(); sectorAndSortedCreatedDateTimeBranch.SetBranchId("BRANCH_SECTOR_SORT_CREATED_DATETIME"); sectorAndSortedCreatedDateTimeBranch.FilterBy(i => i.IsActive).GroupBy("Sector").SortBy("CreatedDateTimeSort", x => x.CreatedDateTime.Ticks); stubStockRepository.AddBranch(sectorAndSortedCreatedDateTimeBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); teslaEntity.CreatedDateTime = DateTimeOffset.UtcNow.AddSeconds(-15).DateTime; await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); await stubStockRepository.AddAsync(appleEntity); IEnumerable <StockEntity> expectedEntities = await stubStockRepository.GetAsync("BRANCH_SECTOR_SORT_CREATED_DATETIME", DateTimeOffset.UtcNow.AddSeconds(-10).Ticks, StockSector.Technology.ToString()); //Assert Assert.Equal(2, expectedEntities.Count()); Assert.Equal(expectedEntities.ElementAt(0).Id, microsoftEntity.Id); Assert.Equal(expectedEntities.ElementAt(0).Name, microsoftEntity.Name); Assert.Equal(expectedEntities.ElementAt(0).Sector, microsoftEntity.Sector); Assert.Equal(expectedEntities.ElementAt(0).Price, microsoftEntity.Price); Assert.Equal(expectedEntities.ElementAt(0).PriceChangeRate, microsoftEntity.PriceChangeRate); Assert.Equal(expectedEntities.ElementAt(0).CreatedDateTime, microsoftEntity.CreatedDateTime); Assert.Equal(expectedEntities.ElementAt(0).IsActive, microsoftEntity.IsActive); Assert.Equal(expectedEntities.ElementAt(1).Id, appleEntity.Id); Assert.Equal(expectedEntities.ElementAt(1).Name, appleEntity.Name); Assert.Equal(expectedEntities.ElementAt(1).Sector, appleEntity.Sector); Assert.Equal(expectedEntities.ElementAt(1).Price, appleEntity.Price); Assert.Equal(expectedEntities.ElementAt(1).PriceChangeRate, appleEntity.PriceChangeRate); Assert.Equal(expectedEntities.ElementAt(1).CreatedDateTime, appleEntity.CreatedDateTime); Assert.Equal(expectedEntities.ElementAt(1).IsActive, appleEntity.IsActive); }
public void ProcessItemUpdate_WithStandardValuesItem_RemovesAllEntriesForMatchingDatabase() { // Arrange var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings(new[] { "master" })) { Enabled = true }; cache.Clear(); for (var i = 0; i < 3; i++) { var masterField = MasterFakesFactory.CreateFakeLayoutField(); cache.AddLayoutValue(masterField.Item, masterField.Value); } using (var webDb = new Db("web")) { var webFakesFactory = new FakesFactory(webDb); for (var i = 0; i < 3; i++) { var webField = webFakesFactory.CreateFakeLayoutField(); cache.AddLayoutValue(webField.Item, webField.Value); } } var tid = new ID(); MasterDb.Add(new DbTemplate("Test", tid) { Fields = { { "Title", "$name" } }, Children = { new DbItem("__Standard Values", new ID(), tid) } }); var standardValues = MasterDb.GetItem("/sitecore/templates/Test/__Standard Values"); // Act cache.ProcessItemUpdate(standardValues); // Assert Assert.Equal(3, cache.InnerCache.Count); Assert.Equal(0, cache.InnerCache.GetCacheKeys("master:").Count); }
public async Task DatabaseFixture_ExplicitlyCallInclude_NavigationPropertyIncludedProperly() { var person = FakesFactory.Create <Person>(); await _DatabaseFixture.PerformDatabaseOperation(async context => { context.Persons.Add(person); await context.SaveChangesAsync(); }); var blogPosts = Enumerable.Range(0, 5) .Select(x => { var blogPost = FakesFactory.Create <BlogPost>(); blogPost.PersonId = person.PersonId; return(blogPost); }); await _DatabaseFixture.PerformDatabaseOperation(async context => { context.BlogPosts.AddRange(blogPosts); await context.SaveChangesAsync(); }); List <Person> persons = null; await _DatabaseFixture.PerformDatabaseOperation(context => { persons = context .Persons .Include(x => x.BlogPosts) .Select(x => x) .ToList(); return(Task.CompletedTask); }); Assert.All(persons, curPerson => { Assert.NotNull(curPerson.BlogPosts); }); }
public async void AddUpdateGetEntity_AddUpdateEntiy_ReturnEntityByIdWithUpdatedValues() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); //Act StockMetaData metaData = new StockMetaData("USA", CurrencyCode.USD); StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5, metaData); string entityId = teslaEntity.Id; await stubStockRepository.AddAsync(teslaEntity); StockEntity updatedEntity = await stubStockRepository.GetByIdAsync(entityId); updatedEntity.Sector = StockSector.Energy; updatedEntity.Name = "Rhein Energy"; updatedEntity.CreatedDateTime = DateTime.UtcNow.AddDays(-1); updatedEntity.Price = 119.00; updatedEntity.PriceChangeRate = 2.7; updatedEntity.MetaData.Country = "Germany"; updatedEntity.MetaData.Currency = CurrencyCode.EURO; updatedEntity.MetaData.UpdateDateTime = DateTime.UtcNow; await stubStockRepository.UpdateAsync(updatedEntity); StockEntity reEntity = await stubStockRepository.GetByIdAsync(entityId); //Assert Assert.NotNull(reEntity); Assert.Equal(updatedEntity.Id, reEntity.Id); Assert.Equal(updatedEntity.Name, reEntity.Name); Assert.Equal(updatedEntity.Sector, reEntity.Sector); Assert.Equal(updatedEntity.Price, reEntity.Price); Assert.Equal(updatedEntity.PriceChangeRate, reEntity.PriceChangeRate); Assert.Equal(updatedEntity.CreatedDateTime, reEntity.CreatedDateTime); Assert.Equal(updatedEntity.IsActive, reEntity.IsActive); Assert.True(updatedEntity.DummyString == default); Assert.Equal(updatedEntity.MetaData.Currency, reEntity.MetaData.Currency); Assert.Equal(updatedEntity.MetaData.Country, reEntity.MetaData.Country); Assert.Equal(updatedEntity.MetaData.UpdateDateTime, reEntity.MetaData.UpdateDateTime); }
public async void AddGetEntity_AddEnttiy_ReturnEntityByPropertySortBranch() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sortByPriceChangeRateBranch = new RedisBranch <StockEntity>(); sortByPriceChangeRateBranch.SetBranchId("BRANCH_SORT_PRICE_CHANGE_RATE"); sortByPriceChangeRateBranch.FilterBy(i => i.IsActive).SortBy("PriceChangeRate"); stubStockRepository.AddBranch(sortByPriceChangeRateBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); await stubStockRepository.AddAsync(appleEntity); IEnumerable <StockEntity> expectedEntities = await stubStockRepository.GetAsync("BRANCH_SORT_PRICE_CHANGE_RATE", (long)9.5); //Assert Assert.Equal(2, expectedEntities.Count()); Assert.Equal(expectedEntities.ElementAt(0).Id, microsoftEntity.Id); Assert.Equal(expectedEntities.ElementAt(0).Name, microsoftEntity.Name); Assert.Equal(expectedEntities.ElementAt(0).Sector, microsoftEntity.Sector); Assert.Equal(expectedEntities.ElementAt(0).Price, microsoftEntity.Price); Assert.Equal(expectedEntities.ElementAt(0).PriceChangeRate, microsoftEntity.PriceChangeRate); Assert.Equal(expectedEntities.ElementAt(0).CreatedDateTime, microsoftEntity.CreatedDateTime); Assert.Equal(expectedEntities.ElementAt(0).IsActive, microsoftEntity.IsActive); Assert.Equal(expectedEntities.ElementAt(1).Id, teslaEntity.Id); Assert.Equal(expectedEntities.ElementAt(1).Name, teslaEntity.Name); Assert.Equal(expectedEntities.ElementAt(1).Sector, teslaEntity.Sector); Assert.Equal(expectedEntities.ElementAt(1).Price, teslaEntity.Price); Assert.Equal(expectedEntities.ElementAt(1).PriceChangeRate, teslaEntity.PriceChangeRate); Assert.Equal(expectedEntities.ElementAt(1).CreatedDateTime, teslaEntity.CreatedDateTime); Assert.Equal(expectedEntities.ElementAt(1).IsActive, teslaEntity.IsActive); }
public async void AddDeleteGetEntity_AddDeleteEntiy_ReturnEntityByIdWithNull() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); //Act StockMetaData metaData = new StockMetaData("USA", CurrencyCode.USD); StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5, metaData); string entityId = teslaEntity.Id; await stubStockRepository.AddAsync(teslaEntity); StockEntity savedEntity = await stubStockRepository.GetByIdAsync(entityId); await stubStockRepository.DeleteAsync(savedEntity); StockEntity deletedEntity = await stubStockRepository.GetByIdAsync(entityId); //Assert Assert.Null(deletedEntity); }
public void AddLayoutValue_WithSameFieldInDifferentDatabases_AddsEntriesForBoth() { // Arrange var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings()) {Enabled = true}; cache.Clear(); var id = new ID(); var masterField = MasterFakesFactory.CreateFakeLayoutField(id); Field webField; using (var webDb = new Db("web")) { var webFakesFactory = new FakesFactory(webDb); webField = webFakesFactory.CreateFakeLayoutField(id); } // Act cache.AddLayoutValue(masterField.Item, masterField.Value); cache.AddLayoutValue(webField.Item, webField.Value); // Assert Assert.Equal(2, cache.InnerCache.Count); }
public async Task DatabaseFixture_CanPerformDatabaseOperation() { var person = FakesFactory.Create <Person>(); await _DatabaseFixture.PerformDatabaseOperation(async context => { context.Persons.Add(person); await context.SaveChangesAsync(); }); await _DatabaseFixture.PerformDatabaseOperation(context => { var personInDatabase = context.Persons.SingleOrDefault(x => x.PersonId == person.PersonId); Assert.NotNull(personInDatabase); Assert.Equal(person.Age, personInDatabase.Age); Assert.Equal(person.Name, personInDatabase.Name); return(Task.CompletedTask); }); }
public async void AddCountEntity_AddEnttiy_ReturnCountBySortedBranch_ThrowsKeyNotFoundException() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sortByPriceChangeRateBranch = new RedisBranch <StockEntity>(); sortByPriceChangeRateBranch.SetBranchId("BRANCH_SORT_PRICE_CHANGE_RATE"); sortByPriceChangeRateBranch.FilterBy(i => i.IsActive).SortBy("PriceChangeRate"); stubStockRepository.AddBranch(sortByPriceChangeRateBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); Func <Task> act = async() => await stubStockRepository.CountAsync("NotExist", ""); //Assert KeyNotFoundException exception = await Assert.ThrowsAsync <KeyNotFoundException>(act); Assert.StartsWith("branchId not found: NotExist.", exception.Message); }
public async void AddGetEntity_AddEntiy_ReturnEntityByPropertyInvalidBranchId_ThrowsKeyNotFoundException() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sectorBranch = new RedisBranch <StockEntity>(); sectorBranch.SetBranchId("BRANCH_SECTOR"); sectorBranch.FilterBy(i => i.IsActive).GroupBy("Sector"); stubStockRepository.AddBranch(sectorBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); Func <Task> act = async() => await stubStockRepository.GetAsync("NotExist", ""); //Assert KeyNotFoundException exception = await Assert.ThrowsAsync <KeyNotFoundException>(act); Assert.StartsWith("branchId not found: NotExist.", exception.Message); }
public async Task DatabaseFixture_WriteAndRetrieveObjectWithNoCaching_NoIncludedNavigationProperties() { var person = FakesFactory.Create <Person>(); await _DatabaseFixture.PerformDatabaseOperation(async context => { context.Persons.Add(person); await context.SaveChangesAsync(); }); var blogPosts = Enumerable.Range(0, 5) .Select(x => { var blogPost = FakesFactory.Create <BlogPost>(); blogPost.PersonId = person.PersonId; return(blogPost); }); await _DatabaseFixture.PerformDatabaseOperation(async context => { context.BlogPosts.AddRange(blogPosts); await context.SaveChangesAsync(); }); List <Person> persons = null; await _DatabaseFixture.PerformDatabaseOperation(context => { persons = context.Persons.Select(x => x).ToList(); return(Task.CompletedTask); }); Assert.All(persons, curPerson => { Assert.Null(curPerson.BlogPosts); }); }
public async Task QueryBy_Char() { //Arrange IConnectionMultiplexer connectionMultiplexer = FakesFactory.CreateConnectionMultiplexerFake(); StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(connectionMultiplexer); StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); await stubStockRepository.AddAsync(appleEntity); //Act QueryProvider provider = new RedisQueryProvider(connectionMultiplexer); RedisQuery <StockEntity> redisQuery = new RedisQuery <StockEntity>(provider); IQueryable <StockEntity> query = redisQuery.Where(s => (s.FirstLetterOfName == 'T')); List <StockEntity> result = query.ToList(); //Assert Assert.Single(result); }
public void ProcessItemUpdate_WithEntriesInDifferentDatabases_OnlyRemovesEntryForMatchingDatabase() { // Arrange var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings(new[] {"master"})) {Enabled = true}; cache.Clear(); var id = new ID(); var masterField = MasterFakesFactory.CreateFakeLayoutField(id); Field webField; using (var webDb = new Db("web")) { var webFakesFactory = new FakesFactory(webDb); webField = webFakesFactory.CreateFakeLayoutField(id); } cache.AddLayoutValue(masterField.Item, masterField.Value); cache.AddLayoutValue(webField.Item, webField.Value); // Act cache.ProcessItemUpdate(masterField.Item); // Assert Assert.Null(cache.GetLayoutValue(masterField.Item)); Assert.Equal(1, cache.InnerCache.Count); }
public void ProcessItemUpdate_WithStandardValuesItem_RemovesAllEntriesForMatchingDatabase() { // Arrange var cache = new BaseLayoutValueCache(TestUtil.CreateFakeSettings(new[] {"master"})) {Enabled = true}; cache.Clear(); for (var i = 0; i < 3; i++) { var masterField = MasterFakesFactory.CreateFakeLayoutField(); cache.AddLayoutValue(masterField.Item, masterField.Value); } using (var webDb = new Db("web")) { var webFakesFactory = new FakesFactory(webDb); for (var i = 0; i < 3; i++) { var webField = webFakesFactory.CreateFakeLayoutField(); cache.AddLayoutValue(webField.Item, webField.Value); } } var tid = new ID(); MasterDb.Add(new DbTemplate("Test", tid) { Fields = {{"Title", "$name"}}, Children = {new DbItem("__Standard Values", new ID(), tid)} }); var standardValues = MasterDb.GetItem("/sitecore/templates/Test/__Standard Values"); // Act cache.ProcessItemUpdate(standardValues); // Assert Assert.Equal(3, cache.InnerCache.Count); Assert.Equal(0, cache.InnerCache.GetCacheKeys("master:").Count); }