public static void ShowLeftJoin() { var characters = CharactersRepository.GetCharacters(); var stories = StoriesRepository.GetStories(); var leftjoinResult = from character in characters join story in stories on character.StoryId equals story.Id select new { character.FirstName, character.LastName, character.Gender, character.Age, StoryID = story.Id }; Console.WriteLine("linq left join character,story"); foreach (var item in leftjoinResult) { Console.WriteLine( $"FirstName:{item.FirstName}, LastName: {item.LastName}, Gender: {item.Gender}, ID: {item.StoryID}"); } }
public void SelectCharacter(Client sender, params object[] args) { if (Guid.TryParse(args[0].ToString(), out Guid userGuid) && int.TryParse(args[1].ToString(), out int accountId) && int.TryParse(args[2].ToString(), out int characterIndex)) { if (EntityHelper.GetAccounts().All(account => account.DbModel.Id != accountId)) { RoleplayContext ctx = Singletons.RoleplayContextFactory.Create(); using (AccountsRepository accountsRepository = new AccountsRepository(ctx)) using (CharactersRepository charactersRepository = new CharactersRepository(ctx)) { AccountModel accountModel = accountsRepository.Get(accountId); AccountEntity accountEntity = new AccountEntity(accountModel, sender); accountEntity.Login(userGuid); int characterId = accountEntity.DbModel.Characters.Where(character => character.IsAlive).ToList()[characterIndex].Id; CharacterModel characterModel = charactersRepository.Get(characterId); CharacterEntity characterEntity = new CharacterEntity(accountEntity, characterModel); accountEntity.SelectCharacter(characterEntity); } } } else { sender.Kick("Nie udało się zalogować. Skontaktuj się z administratorem."); } }
public Character Get(string firstName) { List <Character> characters = new CharactersRepository().GetCharacters(); Character ch = characters.FirstOrDefault(c => c.FirstName == firstName); return(ch); }
public HitPointsService(CharactersRepository repo, IDiceService diceService, IDamageService damageService, IHealService healService) { _repo = repo; _diceService = diceService; _damageService = damageService; _healService = healService; }
public DungeonMaster() { this.charackterFactory = new CharackterFactory(); this.charactersRepository = new CharactersRepository(); this.itemFactory = new ItemFactory(); this.itemRepository = new ItemRepository(); }
public static void ShowWhereWithExtensionSyntax() { var characters = CharactersRepository.GetCharacters(); var persons = characters.Where(character => character.FirstName.StartsWith("A") || character.LastName.Length == 5); foreach (var person in persons) { Console.WriteLine(person.ToString()); } }
protected async Task <ICollection <Character> > ValidateCharactersList(int projectId, IReadOnlyCollection <int> characterIds) { var characters = await CharactersRepository.GetCharacters(projectId, characterIds); if (characters.Count != characterIds.Distinct().Count()) { throw new DbEntityValidationException(); } return(characters.ToArray()); }
public static void OrderByExtensionSyntax() { var characters = CharactersRepository.GetCharacters(); var adults = characters.Where(x => x.Age > 20).OrderByDescending(x => x.Gender).ThenBy(x => x.FirstName); foreach (var adult in adults) { Console.WriteLine(adult.ToString()); } }
public void Verify_Get_ByKey_Should_ReturnTheCorrectCharacter() { // Arrange Mock <IDbSet <Character> > mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); // Act var characters = repository.Get("KING-STEPHEN"); // Assert Assert.Equal("/TEST/KING-STEPHEN", characters.ApiDetailUrl); }
public void Verify_Add_Should_AddTheEntityToTheContext() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(false, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var characters = new Character { Active = true, CustomKey = "SALVATORE-RAA", }; // Act repository.Add(characters); // Assert mockSetCharacters.Verify(x => x.Add(characters), Times.Once); }
public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var characters = repository.Get(1); // Act repository.Deactivate(characters); // Assert Assert.Equal(false, characters.Active); }
public static void ShowOrderBy() { var characters = CharactersRepository.GetCharacters(); var adults = from character in characters orderby character.FirstName descending select character; foreach (var adult in adults) { Console.WriteLine(adult.ToString()); } }
public static void ShowWhereWithMultipleBoolOperands() { var characters = CharactersRepository.GetCharacters(); var persons = characters.Where(character => (character.FirstName.StartsWith("A") || character.LastName.Length == 5) && character.LastName == "Wrynn"); foreach (var person in persons) { Console.WriteLine(person.ToString()); } }
public static void SelectCharactersWithSameFirstAndLastNameLenth() { var characters = CharactersRepository.GetCharacters(); var adults = from character in characters where character.FirstName.Length == character.LastName.Length select character; foreach (var adult in adults) { Console.WriteLine(adult.ToString()); } }
public static void ShowConditionWithGender() { var characters = CharactersRepository.GetCharacters(); var adults = from character in characters where character.Gender == true select character; foreach (var adult in adults) { Console.WriteLine(adult.ToString()); } }
public void Verify_Remove_Should_RemoveTheEntityFromTheContext() { // Arrange Mock <IDbSet <Character> > mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var characters = repository.Get(1); // Act repository.Remove(characters); // Assert mockSetCharacters.Verify(x => x.Remove((Character)characters), Times.Once); }
public static void AddCharactersToDb() { var dbContext = new CharactersDbContext(); var characters = CharactersRepository.GetCharacters(); foreach (var character in characters) { dbContext.Characters.Add(character); } dbContext.SaveChanges(); Console.WriteLine("Characters added"); }
public static void ShowBasicSyntaxLinq() { var characters = CharactersRepository.GetCharacters(); var adults = from character in characters where character.Age > 20 select character; foreach (var adult in adults) { Console.WriteLine(adult.ToString()); } }
public static void ShowWhereWithBasicSyntax() { var characters = CharactersRepository.GetCharacters(); var persons = from character in characters where character.FirstName.StartsWith("A") && !character.LastName.StartsWith("S") select character; foreach (var person in persons) { Console.WriteLine(person.ToString()); } }
public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity() { // Arrange Mock <IDbSet <Character> > mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var characters = repository.Get(1); // Act repository.Deactivate(characters); // Assert Assert.Equal(false, characters.Active); }
public void Verify_Update_Should_SetTheEntityStateToModified() { // Arrange Mock <IDbSet <Character> > mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var characters = repository.Get(1); characters.ApiDetailUrl = "/TEST"; // Act repository.Update(characters); // Assert mockContext.Verify(x => x.SetModified(It.IsAny <object>()), Times.Once); }
public static void GroupByExtensionSyntax() { var characters = CharactersRepository.GetCharacters(); var groups = characters.GroupBy(x => x.Gender); foreach (var group in groups) { foreach (var person in group) { Console.WriteLine(person.ToString()); } } }
public static void DefferedExecution() { var characters = CharactersRepository.GetCharacters().ToList(); var adults = characters.Where(character => character.FirstName.StartsWith("A")); characters.Add(new Character("Andrew", "Harlan", true, 37, 2)); //Запрос выполняется в момент его использования foreach (var adult in adults) { Console.WriteLine(adult.ToString()); } }
public static void ShowExplicitSelect() { var characters = CharactersRepository.GetCharacters(); var names = from character in characters select character.FirstName; //var names = characters.Select(x => x.FirstName); foreach (var name in names) { Console.WriteLine(name); } }
public static void Exercise1() { var characters = CharactersRepository.GetCharacters(); var results = from character in characters select new { PersonDescription = character.ToString() }; foreach (var result in results) { Console.WriteLine(result.PersonDescription); } }
public static void ShowExtensionMethodSyntax() { var characters = CharactersRepository.GetCharacters(); var adults = characters.Where(character => character.Age > 20); //var adults = from character in characters // where character.Age > 20 // select character; foreach (var adult in adults) { Console.WriteLine(adult.ToString()); } }
public void Verify_Add_Should_AddTheEntityToTheContext() { // Arrange Mock <IDbSet <Character> > mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(false, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var characters = new Character { Active = true, CustomKey = "SALVATORE-RAA", }; // Act repository.Add(characters); // Assert mockSetCharacters.Verify(x => x.Add(characters), Times.Once); }
public static void ShowGroupBy() { var characters = CharactersRepository.GetCharacters(); var groups = from character in characters group character by character.Gender; foreach (var group in groups) { foreach (var person in group) { Console.WriteLine(person.ToString()); } } }
public void Verify_Search_WithSelectStatement_Should_ReturnAListOfDynamicObjects() { // Arrange Mock <IDbSet <Character> > mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters, true); var repository = new CharactersRepository(mockContext.Object); var searchModel = new Mock <ICharacterSearchModel>(); // Act var characters = repository.Search(searchModel.Object, i => new { i.Id, MyApiDetailUrl = i.ApiDetailUrl }).ToArray(); // Assert Assert.Equal(1, characters.Length); Assert.Equal(2, characters[0].Id); Assert.Equal("/TEST/NIVEN-LARRY", characters[0].MyApiDetailUrl); // Stephen King was filtered out because he was Inactive }
public void Verify_List_Should_ReturnAListOfCharactersWithData() { // Arrange Mock <IDbSet <Character> > mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); // Act var characters = repository.List.ToArray(); // Assert Assert.Equal(2, characters.Length); Assert.Equal(1, characters[0].Id); Assert.Equal("/TEST/KING-STEPHEN", characters[0].ApiDetailUrl); Assert.Equal(2, characters[1].Id); Assert.Equal("/TEST/NIVEN-LARRY", characters[1].ApiDetailUrl); }
public static void OneRunCondition() { var characters = CharactersRepository.GetCharacters(); // string PersonDescription; var _queryLINQ = from character in characters select new { PersonDescription = character.FirstName + " " + character.LastName + " " + character.Gender + " " + character.Age + " " + character.StoryId + " " + character.StoryName }; foreach (var item in _queryLINQ) { Console.WriteLine(item.PersonDescription); } }
public static void SelectAnonymousType() { var characters = CharactersRepository.GetCharacters(); var persons = from character in characters select new { character.FirstName, character.Age }; //var persons = characters.Select(x => new { x.FirstName, x.Age }); foreach (var person in persons) { Console.WriteLine($"FirstName: {person.FirstName}, \tAge: {person.Age}"); } }
public void Verify_List_Should_ReturnAListOfCharactersWithData() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); // Act var characters = repository.List.ToArray(); // Assert Assert.Equal(2, characters.Length); Assert.Equal(1, characters[0].Id); Assert.Equal("/TEST/KING-STEPHEN", characters[0].ApiDetailUrl); Assert.Equal(2, characters[1].Id); Assert.Equal("/TEST/NIVEN-LARRY", characters[1].ApiDetailUrl); }
public void Verify_Remove_Should_RemoveTheEntityFromTheContext() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var characters = repository.Get(1); // Act repository.Remove(characters); // Assert mockSetCharacters.Verify(x => x.Remove((Character)characters), Times.Once); }
public void Verify_Search_WithModifiedSince_Should_ReturnAListOfCharactersWithDataMatchingSearchParameters() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters, true); var repository = new CharactersRepository(mockContext.Object); var createDate = new System.DateTime(2015, 05, 28, 10, 45, 00).AddDays(1).AddMinutes(-1); //var searchModel = new Mock<ICharacterSearchModel>(); //searchModel.Setup(m => m.ModifiedSince).Returns(() => createDate); var searchModel = new CharacterSearchModel { ModifiedSince = createDate }; // Act var characters = repository.Search(searchModel/*.Object*/).ToArray(); // Assert Assert.Equal(1, characters.Length); Assert.Equal(2, characters[0].Id); Assert.Equal("/TEST/NIVEN-LARRY", characters[0].ApiDetailUrl); // Stephen King was filtered out because he was created before the modified since date }
public void Verify_Search_WithPaging_Should_ReturnAListOfCharactersWithDataMatchingSearchParameters() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var searchModel = new CharacterSearchModel { Paging = new Paging { Skip = 1, Take = 1 } }; // Act var characters = repository.Search(searchModel/*.Object*/).ToArray(); // Assert Assert.Equal(1, characters.Length); Assert.Equal(2, characters[0].Id); Assert.Equal("/TEST/NIVEN-LARRY", characters[0].ApiDetailUrl); // Stephen King was filtered out because he was Skipped }
public void Verify_Search_WithSelectStatement_Should_ReturnAListOfDynamicObjects() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters, true); var repository = new CharactersRepository(mockContext.Object); var searchModel = new Mock<ICharacterSearchModel>(); // Act var characters = repository.Search(searchModel.Object, i => new { i.Id, MyApiDetailUrl = i.ApiDetailUrl }).ToArray(); // Assert Assert.Equal(1, characters.Length); Assert.Equal(2, characters[0].Id); Assert.Equal("/TEST/NIVEN-LARRY", characters[0].MyApiDetailUrl); // Stephen King was filtered out because he was Inactive }
public void Verify_Update_Should_SetTheEntityStateToModified() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); var characters = repository.Get(1); characters.ApiDetailUrl = "/TEST"; // Act repository.Update(characters); // Assert mockContext.Verify(x => x.SetModified(It.IsAny<object>()), Times.Once); }
public void Verify_Get_ByID_Should_ReturnTheCorrectCharacter() { // Arrange Mock<IDbSet<Character>> mockSetCharacters; var mockContext = CharactersMockingSetup.DoMockingSetupForContext(true, out mockSetCharacters); var repository = new CharactersRepository(mockContext.Object); // Act var characters = repository.Get(1); // Assert Assert.Equal("/TEST/KING-STEPHEN", characters.ApiDetailUrl); }