public When_saving_two_aggregates_in_parallel() { _testStore = new TestInMemoryEventStore(); _rep1 = new CacheRepository(new Repository(_testStore), _testStore, new MemoryCache()); _aggregate1 = new TestAggregate(Guid.NewGuid()); _aggregate2 = new TestAggregate(Guid.NewGuid()); _rep1.Save(_aggregate1); _rep1.Save(_aggregate2); var t1 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate1.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); var t2 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate2.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); t1.Start(); t2.Start(); Task.WaitAll(t1, t2); }
public When_saving_aggregate() { _testRep = new TestRepository(); _rep = new CacheRepository(_testRep, new TestInMemoryEventStore(), new CqrsMemoryCache()); _aggregate = _testRep.Get<TestAggregate>(Guid.NewGuid()); _aggregate.DoSomething(); _rep.Save(_aggregate, -1); }
public void Setup() { _testRep = new TestRepository(); _rep = new CacheRepository(_testRep, new TestInMemoryEventStore()); _aggregate = _testRep.Get<TestAggregate>(Guid.NewGuid()); _aggregate.DoSomething(); _rep.Save(_aggregate,-1); }
public void Should_get_same_aggregate_from_different_cache_repository() { var rep = new CacheRepository(new TestRepository(), new TestInMemoryEventStore(), _memoryCache); var aggregate = rep.Get<TestAggregate>(_aggregate.Id); Assert.Equal(_aggregate.DidSomethingCount, aggregate.DidSomethingCount); Assert.Equal(_aggregate.Id, aggregate.Id); Assert.Equal(_aggregate.Version, aggregate.Version); }
private static CacheRepository InitializeSut() { var jsonSerializer = new JsonContractSerializer(); innerRepository = new FakeRepository(jsonSerializer); var memCache = new InMemoryCacheProvider(); var sut = new CacheRepository(innerRepository, memCache); return sut; }
public When_saving_fails() { _memoryCache = new MemoryCache(); _testRep = new TestRepository(); _rep = new CacheRepository(_testRep, new TestInMemoryEventStore(), _memoryCache); _aggregate = _testRep.Get<TestAggregate>(Guid.NewGuid()); _aggregate.DoSomething(); try { _rep.Save(_aggregate, 100); } catch (Exception) { } }
public void Test() { var repository = new MockRepository<Person>(); var cacheRepository = new CacheRepository<Person>(); var people = repository.Get(); Assert.IsTrue(people.Count() == 3); var cachedPeople = cacheRepository.Get(); Assert.IsTrue(cachedPeople.Count() == 3); }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { window = new UIWindow (UIScreen.MainScreen.Bounds); var repo = new CacheRepository (new HttpRepository ("127.0.0.1")); var channel = new ChannelViewController ("monotouch", repo); window.RootViewController = new UINavigationController (channel); window.MakeKeyAndVisible (); return true; }
public void Setup() { // This will clear the cache between runs. var cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList(); foreach (var cacheKey in cacheKeys) MemoryCache.Default.Remove(cacheKey); _testStore = new TestInMemoryEventStore(); _rep1 = new CacheRepository(new Repository(_testStore,new TestEventPublisher()), _testStore); _rep2 = new CacheRepository(new Repository(_testStore,new TestEventPublisher()), _testStore); _aggregate = new TestAggregate(Guid.NewGuid()); _rep1.Save(_aggregate); var t1 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); var t2 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep2.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep2.Save(aggregate); } }); var t3 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep2.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep2.Save(aggregate); } }); t1.Start(); t2.Start(); t3.Start(); Task.WaitAll(t1, t2, t3); }
public When_saving_same_aggregate_in_parallel() { // New up a new Cache for each run var memoryCache = new CqrsMemoryCache(); _testStore = new TestInMemoryEventStore(); _rep1 = new CacheRepository(new Repository(_testStore, new TestEventPublisher()), _testStore, memoryCache); _rep2 = new CacheRepository(new Repository(_testStore, new TestEventPublisher()), _testStore, memoryCache); _aggregate = new TestAggregate(Guid.NewGuid()); _rep1.Save(_aggregate); var t1 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); var t2 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep2.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep2.Save(aggregate); } }); var t3 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep2.Get<TestAggregate>(_aggregate.Id); aggregate.DoSomething(); _rep2.Save(aggregate); } }); t1.Start(); t2.Start(); t3.Start(); Task.WaitAll(t1, t2, t3); }
public CacheRepositoryTests() { Database.SetInitializer(new TestStorageInitializer()); sampleAnswer = new Answer { Sort = 1, AnswerId = 8203291, QuestionId = 8203265, QuestionTitle = "First" }; anotherAnswer = new Answer { Sort = 2, AnswerId = 8203291, QuestionId = 8203265, QuestionTitle = "Second" }; testContext = new TestContext(); assertContext = new TestContext(); repo = new CacheRepository(testContext, new JsonSofuService()); }
public When_saving_two_aggregates_in_parallel() { // This will clear the cache between runs. var memoryCache = new CqrsMemoryCache(); _testStore = new TestInMemoryEventStore(); _rep1 = new CacheRepository(new Repository(_testStore, new TestEventPublisher()), _testStore, memoryCache); _aggregate1 = new TestAggregate(Guid.NewGuid()); _aggregate2 = new TestAggregate(Guid.NewGuid()); _rep1.Save(_aggregate1); _rep1.Save(_aggregate2); var t1 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate1.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); var t2 = new Task(() => { for (var i = 0; i < 100; i++) { var aggregate = _rep1.Get<TestAggregate>(_aggregate2.Id); aggregate.DoSomething(); _rep1.Save(aggregate); } }); t1.Start(); t2.Start(); Task.WaitAll(new[] { t1, t2 }); }
public When_getting_aggregate() { _memoryCache = new MemoryCache(); _rep = new CacheRepository(new TestRepository(), new TestEventStore(), _memoryCache); _aggregate = _rep.Get<TestAggregate>(Guid.NewGuid()); }
public void Should_get_same_aggregate_from_different_cache_repository() { var rep = new CacheRepository(new TestRepository(), new TestInMemoryEventStore()); var aggregate = rep.Get<TestAggregate>(_aggregate.Id); Assert.That(aggregate, Is.EqualTo(_aggregate)); }
public SearchCommandHandler(CacheRepository repository) { _repository = repository; }
public void Setup() { _rep = new CacheRepository(new TestRepository(), new TestEventStore()); _aggregate = _rep.Get<TestAggregate>(Guid.NewGuid()); }
public ManageUsersController(CacheRepository repo) { _repo = repo; }
public ActionResult Create(Product p, HttpPostedFileBase file) { //upload image related to product on the bucket try { if (file != null) { #region Uploading file on Cloud Storage var storage = StorageClient.Create(); string link = ""; using (var f = file.InputStream) { var filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var storageObject = storage.UploadObject("pfct001", filename, null, f); link = "https://storage.cloud.google.com/pfct001/" + file.FileName; if (null == storageObject.Acl) { storageObject.Acl = new List <ObjectAccessControl>(); } storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "pfct001", Entity = $"user-" + "*****@*****.**", //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "OWNER", //READER }); storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "pfct001", Entity = $"user-" + "*****@*****.**", //whereas [email protected] has to be replaced by a gmail email address who you want to have access granted Role = "READER", //READER }); var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() { // Avoid race conditions. IfMetagenerationMatch = storageObject.Metageneration, }); } //store details in a relational db including the filename/link #endregion } #region Storing details of product in db [INCOMPLETE] p.OwnerFk = "*****@*****.**"; //User.Identity.Name ProductsRepository pr = new ProductsRepository(); //pr.AddProduct(p); #endregion #region Updating Cache with latest list of Products from db //enable: after you switch on db CacheRepository cr = new CacheRepository(); //cr.UpdateCache(pr.GetProducts()); #endregion PubSubRepository psr = new PubSubRepository(); //psr.AddToEmailQueue(p); //adding it to queue to be sent as an email later on. ViewBag.Message = "Product created successfully"; } catch (Exception ex) { ViewBag.Error = "Product failed to be created; " + ex.Message; } return(View()); }
public async Task ProcessHashTagsAsync(List <TweetModel> tweets) { List <string> listOfHashtags = new List <string>(); try { await Task.Run(() => { if (tweets != null && tweets.Count > 0) { List <string> listOfTweetTexts = tweets.Select(x => x.FullText).ToList(); listOfHashtags.AddRange(this.HashtagProcessor.GetListOfHashtags(tweets)); Dictionary <string, int> hashTagsWithCount = CacheRepository.Get <Dictionary <string, int> >("HashtagsWithCount") != null ? CacheRepository.Get <Dictionary <string, int> >("HashtagsWithCount") : new Dictionary <string, int>(); int tweetsWithHashtags = CacheRepository.Get <int>("TweetsWithHashTags"); hashTagsWithCount = this.HashtagProcessor.GetHashtagsWithCount(hashTagsWithCount, listOfHashtags); if (hashTagsWithCount == null) { hashTagsWithCount = new Dictionary <string, int>(); } Dictionary <string, int> topHashtags = hashTagsWithCount.OrderByDescending(x => x.Value).Take(25).ToDictionary(x => x.Key, x => x.Value); tweetsWithHashtags += this.HashtagProcessor.GetNumberOfTweetsWithHashTags(tweets); CacheRepository.Set <Dictionary <string, int> >("HashtagsWithCount", hashTagsWithCount, 9999); CacheRepository.Set <Dictionary <string, int> >("TopHashtags", topHashtags, 9999); CacheRepository.Set <Dictionary <string, int> >("TweetsWithHashTags", topHashtags, 9999); CacheRepository.Set <int>("TweetsWithHashTags", tweetsWithHashtags, 9999); } } ); } catch (Exception ex) { Logger.LogError(ex, "Error at ProcessEmojis", null); } }
public When_getting_wrong_events_from_event_store() { _memoryCache = new CqrsMemoryCache(); _rep = new CacheRepository(new TestRepository(), new TestEventStoreWithBugs(), _memoryCache); _aggregate = _rep.Get<TestAggregate>(Guid.NewGuid()); }
public When_getting_aggregate() { _cache = new MemoryCache(); _rep = new CacheRepository(new TestRepository(), new TestEventStore(), _cache); _aggregate = _rep.Get <TestAggregate>(Guid.NewGuid()).Result; }
public When_getting_earlier_than_expected_events_from_event_store() { _cache = new MemoryCache(); _rep = new CacheRepository(new TestRepository(), new TestEventStoreWithBugs(), _cache); _aggregate = _rep.Get <TestAggregate>(Guid.NewGuid()).Result; }
public void Setup() { _rep = new CacheRepository <ISingleSignOnToken>(new TestAggregateRepository(), new TestEventStoreWithBugs()); _aggregate = _rep.Get <TestAggregate>(Guid.NewGuid()); }
public ActionResult Create(Models.File p, HttpPostedFileBase file) { //upload image related to product on the bucket try { string link = ""; var filename = ""; if (file != null) { #region Uploading file on Cloud Storage var storage = StorageClient.Create(); using (var f = file.InputStream) { filename = Guid.NewGuid() + System.IO.Path.GetExtension(file.FileName); var storageObject = storage.UploadObject("programming-for-the-cloud", filename, null, f); //link = storageObject.MediaLink; link = "https://storage.cloud.google.com/programming-for-the-cloud" + "/" + filename; if (null == storageObject.Acl) { storageObject.Acl = new List <ObjectAccessControl>(); } storageObject.Acl.Add(new ObjectAccessControl() { Bucket = "programming-for-the-cloud", Entity = $"user-" + "*****@*****.**", Role = "READER", //READER }); var updatedObject = storage.UpdateObject(storageObject, new UpdateObjectOptions() { // Avoid race conditions. IfMetagenerationMatch = storageObject.Metageneration, }); } //store details in a relational db including the filename/link #endregion } #region Storing details of product in db [INCOMPLETE] p.OwnerFk = User.Identity.Name; //"*****@*****.**"; ServiceAccountCredential credential; using (var stream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "//jurgen-cloud-project-5f077f2e1ba1.json", FileMode.Open, FileAccess.Read)) { credential = GoogleCredential.FromStream(stream).UnderlyingCredential as ServiceAccountCredential; } UrlSigner urlSigner = UrlSigner.FromServiceAccountCredential(credential); //https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Storage.V1/index.html string signedUrl = urlSigner.Sign("programming-for-the-cloud", filename, TimeSpan.FromDays(365)); p.Link = signedUrl; //p.Link = link; FilesRepository pr = new FilesRepository(); pr.AddFile(p.Name, p.Description, p.OwnerFk, p.Link); #endregion #region Updating Cache with latest list of Products from db //enable: after you switch on db CacheRepository cr = new CacheRepository(); cr.UpdateCache(pr.GetFiles(User.Identity.Name)); #endregion new LoggingRepository().Logging("File Uploaded By: " + User.Identity.Name + " At: " + DateTime.Now); //PubSubRepository psr = new PubSubRepository(); //psr.AddToEmailQueue(p); //adding it to queue to be sent as an email later on. //ViewBag.Message = "Product created successfully"; } catch (Exception ex) { new LoggingRepository().ErrorLogging(ex); ViewBag.Error = "Product failed to be created; " + ex.Message; } return(RedirectToAction("Index")); }
public void DeleteFile(int id) { FileRepository.Delete(id); CacheRepository.Delete($"{FileCache}-{id}"); UnitOfWork.Save(); }