public void Delete_Should_Remove_Item_By_Key(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var result = repository.Get(contact.ContactId); result.ShouldNotBeNull(); repository.Delete(contact.ContactId); result = repository.Get(contact.ContactId); result.ShouldBeNull(); }
public OrderShippingPartHandler( IRepository<OrderShippingPartRecord> repository, IRepository<OrderAddressRecord> orderAddressRepository) { Filters.Add(StorageFilter.For(repository)); OnActivated<OrderShippingPart>((context, part) => { part._shippingDetails.Loader(shippingDetails => { var orderPart = context.ContentItem.As<OrderPart>(); if (orderPart != null) { return orderPart.Details.Where(d => d.DetailType == "Shipping"); } else { return new List<OrderDetail>(); } }); part._shippingAddress.Loader(shippingAddress => orderAddressRepository.Get(part.ShippingAddressId)); }); OnCreated<OrderShippingPart>((context, part) => { part.ShippingAddressId = orderAddressRepository.CreateOrUpdate(part.ShippingAddress); }); OnUpdated<OrderShippingPart>((context, part) => { part.ShippingAddressId = orderAddressRepository.CreateOrUpdate(part.ShippingAddress); }); }
public GiveCampSettings() { repository = new EntityFrameworkRepository(); var settings = repository.Get<EventSetting>(x => x.Id == DefaultId); HttpRuntime.Cache.Insert("Settings", settings, null, DateTime.Now.AddMinutes(10d), System.Web.Caching.Cache.NoSlidingExpiration); }
public HasTagsHandler(IRepository<Tag> tagsRepository, IRepository<TagsContentItems> tagsContentItemsRepository) { OnLoading<HasTags>((context, tags) => { // provide names of all tags on demand tags._allTags.Loader(list => tagsRepository.Table.ToList()); // populate list of attached tags on demand tags._currentTags.Loader(list => { var tagsContentItems = tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id); foreach (var tagContentItem in tagsContentItems) { var tag = tagsRepository.Get(tagContentItem.TagId); list.Add(tag); } return list; }); }); OnRemoved<HasTags>((context, ht) => { tagsContentItemsRepository.Flush(); HasTags tags = context.ContentItem.As<HasTags>(); foreach (var tag in tags.CurrentTags) { if (!tagsContentItemsRepository.Fetch(x => x.ContentItemId == context.ContentItem.Id).Any()) { tagsRepository.Delete(tag); } } }); }
static async Task MainAsync(IRepository<SampleEntity> repo) { foreach (var s in await repo.GetAllAsync()) { Console.WriteLine("{0} | {1}", s.ID, s.Name); } // Paged Set // Console.WriteLine("\nPage = 2 - Page Size = 2 :"); var some = await repo.GetAsync(2, 2, s => s.ID); foreach (var s in some) { Console.WriteLine("{0} | {1}", s.ID, s.Name); } // Updating // var fox = await repo.FindAsync(e => e.Name == "Fox"); fox.Name = "Dog"; repo.Update(fox, fox.ID); // Deleting // Console.WriteLine("\n " + await repo.DeleteAsync(repo.Get(5)) + "\n"); foreach (var e in repo.GetAll()) Console.WriteLine(e.ID + " | " + e.Name); }
public void CombineDecisions(IAccessDecisionCombinator combinator, IRepository<Role> roleRepository) { if (_disabled) return; foreach (var roleId in _roles) { roleRepository.Get(roleId).CombineDecisions(combinator); } }
public void Update_Should_Save_Modified_Business_Name(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var contact2 = new Contact { Name = "Test User 2" }; repository.Add(contact2); contact.Name = "Test User - Updated"; repository.Update(contact); var updated = repository.Get(contact.ContactId); var notUpdated = repository.Get(contact2.ContactId); updated.Name.ShouldEqual("Test User - Updated"); notUpdated.Name.ShouldEqual("Test User 2"); }
public LowHealthUnitsWalkTogetherRule(ComponentService componentService, AIDto ai, IRepository<GameEnvironment> gameEnvironmentRepository, IVector2Service vector2Service, IEventStoreService eventStoreService) { _componentService = componentService; _ai = ai; _vector2Service = vector2Service; _eventStoreService = eventStoreService; _gameEnvironment = gameEnvironmentRepository.Get(); }
public void Get_With_String_Selector_Should_Return_Item_If_Item_Exists(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var result = repository.Get(contact.ContactId, c => c.Name); result.ShouldEqual("Test User"); }
private static void GetPushEventExample(IRepository<EventPushCampaign> eventPushRepo) { var e = eventPushRepo.Get(4251); Console.WriteLine("Fetched event: {0}", e.Id); Console.WriteLine("Channels: {0}", String.Join(", ", e.ChannelIds)); Console.WriteLine("Targets: {0}", String.Join(", ", e.Targets)); }
public PeopleViewModel(IRepository<Person> repository, IEventAggregator eventAggregator) { People = new ListCollectionView(repository.Get()); People.CurrentChanged += new EventHandler(OnSelectedItemChanged); this.eventAggregator = eventAggregator; }
public void Get_Should_Return_Item_If_Item_Exists(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User", ContactTypeId = 1 }; repository.Add(contact); var result = repository.Get(contact.ContactId); result.Name.ShouldEqual(contact.Name); result.ContactTypeId.ShouldEqual(contact.ContactTypeId); }
public void Get_With_Anonymous_Class_Selector_Should_Return_Item_If_Item_Exists(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User", ContactTypeId = 2 }; repository.Add(contact); var result = repository.Get(contact.ContactId, c => new { c.ContactTypeId, c.Name }); result.ContactTypeId.ShouldEqual(2); result.Name.ShouldEqual("Test User"); }
public BuildBarrackRule(ComponentService componentService, AIDto ai, IOrientationService orientationService, IVector2Service vector2Service, IRepository<GameEnvironment> gameEnvironmentRepository, IEventStoreService eventStoreService) { _componentService = componentService; _ai = ai; _orientationService = orientationService; _vector2Service = vector2Service; _eventStoreService = eventStoreService; _gameEnvironment = gameEnvironmentRepository.Get(); }
public void Using_TransactionScope_Without_Complete_Should_Not_Add(IRepository<Contact, string> repository) { repository.Get("test"); // used to create the SqlCe database before being inside the transaction scope since that throws an error using (var trans = new TransactionScope()) { repository.Add(new Contact {Name = "Contact 1"}); } repository.GetAll().Count().ShouldEqual(0); }
public JustEatModule(IRepository repository) { this.repository = repository; Get["/restaurants/{outcode}"] = parameters => { var outcode = parameters.outcode; var results = repository.Get(outcode).Result; return View["Finder", results]; }; Get["/restaurants/"] = parameters => { var results = repository.Get("").Result; return View["Finder", results]; }; }
private static Setting GetSetting(string settingName, IRepository repository) { var setting = repository.Get<Setting>(settingName.Encrypt()); if (setting == null) { setting = InitializeSetting(settingName, repository); } return setting; }
public void Delete_Should_Wait_To_Remove_Item_If_Item_Exists_In_BatchMode(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User" }; repository.Add(contact); var result = repository.Get(contact.ContactId); result.ShouldNotBeNull(); using (var batch = repository.BeginBatch()) { batch.Delete(contact); // not really delete until call Save, because in BatchMode result = repository.Get(contact.ContactId); result.ShouldNotBeNull(); batch.Commit(); // actually do the delete } result = repository.Get(contact.ContactId); result.ShouldBeNull(); }
public static void ListActions(IRepository repository, int gameId) { var game = repository.Get<Game>(gameId); foreach (Player player in game.Players) { Console.WriteLine(string.IsNullOrWhiteSpace(player.Name) ? string.Format("Player {0}:", player.Id) : player.Name + ": "); Console.WriteLine(string.Format("On {0}", player.SpaceId)); foreach (Haven.Action a in player.Actions) { Console.WriteLine(a.Id + ") " + a); } } }
public OrderPartHandler( IRepository<OrderPartRecord> repository, IContentManager contentManager, IRepository<OrderDetailRecord> orderDetailsRepository, IOrdersService ordersService, IRepository<OrderAddressRecord> orderAddressRepository) { _orderDetailsRepository = orderDetailsRepository; Filters.Add(StorageFilter.For(repository)); OnActivated<OrderPart>((context, part) => { // Details part._details.Loader(details => _orderDetailsRepository.Fetch(d => d.OrderId == part.Id) .Select(d => new OrderDetail(d)) .ToList()); // Order total part._orderTotal.Loader(orderTotal => BuildOrderTotal(part)); // BillingAddress part._billingAddress.Loader(shippingAddress => orderAddressRepository.Get(part.BillingAddressId)); }); OnLoading<OrderPart>((context, part) => { // Order total part._orderTotal.Loader(orderTotal => part.Retrieve(x => x.OrderTotal)); }); OnCreating<OrderPart>((context, part) => { if (String.IsNullOrWhiteSpace(part.Reference)) { part.Reference = ordersService.BuildOrderReference(); } }); OnCreated<OrderPart>((context, part) => { // Order total part.OrderTotal = BuildOrderTotal(part); SaveDetails(part); part.BillingAddressId = orderAddressRepository.CreateOrUpdate(part.BillingAddress); }); OnUpdated<OrderPart>((context, part) => { // Order total part.OrderTotal = BuildOrderTotal(part); SaveDetails(part); part.BillingAddressId = orderAddressRepository.CreateOrUpdate(part.BillingAddress); }); }
public PackageModule(IRepository<User> users) { Post["/Packages/GetPackage"] = parameters => { var dto = this.Bind<PDto>(); var user = users.Get(dto.UserId); var contractDto = Mapper.Map<Contract, ContractDto>(user.Contracts.First()); if(!contractDto.Packages.Any()) throw new Exception("No packages for contract"); return Response.AsJson(new { PackageId = contractDto.Packages.First().Key }); }; }
public static void PerformAction(IRepository repository, int gameId, int actionId) { Console.Write("Input: "); var input = Console.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { input = null; } var action = repository.Get<Haven.Action>(actionId); action.PerformAction(input); var latestMessage = action.Owner.Messages.First(); Console.WriteLine(latestMessage.Text); }
public static Comment CreateOrLoadComment( CommentModel comment, IRepository<Comment> commentRepository, DbUsersRepository usersRepository) { Comment commentEntity = commentRepository.Get(comment.ID); if (commentEntity != null) { return commentEntity; } Comment newComment = CommentsMapper.ToCommentEntity(comment, usersRepository); return newComment; }
public void GetContact_ContactExists_ContactReturned( TestIndexUtils contactIndex, IRepository<ElasticContact> repo, ElasticContact contact, ISystemContext ctx) { using (contactIndex) { repo.Save(contact, ctx); var res = repo.Get(contact.Id, ctx); res.Should().NotBeNull(); res.Id.Should().Be(contact.Id); } }
public static Mark CreateOrLoadMark(IRepository<Mark> repository, Mark entity) { Mark mark = repository.Get(entity.MarkId); if (mark != null) { return mark; } Mark newAlbum = repository.Add(new Mark() { Subject = entity.Subject, Value = entity.Value }); return newAlbum; }
public static Comment ToCommentEntity( CommentModel commentModel, DbUsersRepository usersRepository, IRepository<NewsArticle> newsArticlesRepository) { Comment commentEntity = new Comment() { Content = commentModel.Content, Date = commentModel.Date, Author = usersRepository.GetByNickname(commentModel.Author) }; NewsArticle newsArticle = newsArticlesRepository.Get(commentModel.ArticleID); newsArticle.Comments.Add(commentEntity); return commentEntity; }
public static Session Create(Guid competitionId, IRepository<Competition> competitionRepository) { var operationChecker = new OperationChecker(competitionRepository); if (!operationChecker.IsRunning(competitionId)) { throw new Exception("Cannot create session for non-running competition."); } var session = new Session(operationChecker) { CompetitionId = competitionId, Schedule = Schedule.Create(competitionRepository.Get(competitionId).GetOptions()), Outcomes = new List<Outcome>() }; return session; }
public static School CreateOrLoadSong(IRepository<School> repository, School entity) { School school = repository.Get(entity.SchoolId); if (school != null) { return school; } School newSchool = repository.Add(new School() { Name = entity.Name, Location = entity.Location, Students = entity.Students }); return newSchool; }
public static Song CreateOrLoadSong(IRepository<Song> repository, Song entity) { Song song = repository.Get(entity.SongId); if (song != null) { return song; } Song newSong = repository.Add(new Song() { Title = entity.Title, Year = entity.Year, Genre = entity.Genre, Album = entity.Album, Artist = entity.Artist }); return newSong; }
public static Artist CreateOrLoadArtist(IRepository<Artist> repository, Artist entity) { Artist artist = repository.Get(entity.ArtistId); if (artist != null) { return artist; } Artist newArtist = repository.Add(new Artist() { Name = entity.Name, Country = entity.Country, DateOfBirth = entity.DateOfBirth, Songs = entity.Songs, Albums = entity.Albums }); return newArtist; }