public void WalkThroughDoor(GameObject fixture /*Tile tile*/) { //Fixture fixture = GetFixtureInTile(tile); //if (fixture == null) // return; //if (fixture.GetType() != typeof(Door)) // return; if (goToFxMap.ContainsKey(fixture) == false) { Debug.LogError("WalkThroughDoor: No GameOject in gameOjectFixtureMap"); return; } Fixture f = goToFxMap[fixture]; if (f.GetType() == typeof(Door)) { if ((f as Door).LinkToArea != area.Place) { AreaController.nextAreaDoor = (f as Door).LinkToDoor; controller.NextArea((f as Door).LinkToArea); } else { Door nextDoor = area.GetDoor((f as Door).LinkToDoor); area.hero.Move(nextDoor.ExitX, nextDoor.ExitY); } } }
public void ShouldImplementInterfaceIHandEvaluator() { //Arrange var sut = new Fixture().Create <BlackJackHandEvaluator>(); //Act var sutType = sut.GetType(); //Assert sutType.Should().Implement <IHandEvaluator>(); }
public void SensorClear(GameObject fixture) { if (goToFxMap.ContainsKey(fixture) == false) { Debug.LogError("TripSensor: No GameOject in gameOjectFixtureMap"); return; } Fixture f = goToFxMap[fixture]; if (f.GetType() == typeof(Door)) { (f as Door).SensorState = false; } }
public void CreateConvertExpression_MultipleCases_ConvertsCorrectly( Type sourceType, Type targetType, string sourcePropertyName, string targetPropertyName, object sourcePropertyValue) { var target = new PropertyConverter(); var fixture = new Fixture(); var createMethod = fixture.GetType().GetMethod("CreateAnonymous"); var sourceObject = Activator.CreateInstance(sourceType); var targetObject = Activator.CreateInstance(targetType); var sourceParam = Expression.Parameter(sourceType); var targetParam = Expression.Parameter(targetType); var sourceProp = sourceType.GetProperty(sourcePropertyName); var targetProp = targetType.GetProperty(targetPropertyName); if (sourcePropertyValue != null) { sourceProp.SetValue(sourceObject, sourcePropertyValue, null); } var expr = target.CreateConvertExpression( sourceProp, targetProp, sourceParam, targetParam); var actionType = typeof(MappingAction <,>).MakeGenericType(sourceType, targetType); var lambda = Expression.Lambda(actionType, expr, sourceParam, targetParam); var action = lambda.Compile(); action.DynamicInvoke(sourceObject, targetObject); var resultProp = targetProp.GetValue(targetObject, null); resultProp.ShouldBe(sourcePropertyValue); }
public void CreateConvertExpression_MultipleCases_ConvertsCorrectly( Type sourceType, Type targetType, string sourcePropertyName, string targetPropertyName, object sourcePropertyValue) { var target = new PropertyConverter(); var fixture = new Fixture(); MethodInfo createMethod = fixture.GetType().GetMethod("CreateAnonymous"); object sourceObject = Activator.CreateInstance(sourceType); object targetObject = Activator.CreateInstance(targetType); ParameterExpression sourceParam = Expression.Parameter(sourceType); ParameterExpression targetParam = Expression.Parameter(targetType); PropertyInfo sourceProp = sourceType.GetProperty(sourcePropertyName); PropertyInfo targetProp = targetType.GetProperty(targetPropertyName); if (sourcePropertyValue != null) { sourceProp.SetValue(sourceObject, sourcePropertyValue, null); } var expr = target.CreateConvertExpression( sourceProp, targetProp, sourceParam, targetParam); var actionType = typeof (MappingAction<,>).MakeGenericType(sourceType, targetType); var lambda = Expression.Lambda(actionType, expr, sourceParam, targetParam); var action = lambda.Compile(); action.DynamicInvoke(sourceObject, targetObject); var resultProp = targetProp.GetValue(targetObject, null); resultProp.ShouldBe(sourcePropertyValue); }
private async Task <List <Fixture> > ParseCompetitionData(string[] data, Competition competition) { List <Fixture> fixtures = null; // Check if we have more than one entry (excluding the csv header) if (data.Length > 1) { fixtures = new List <Fixture>(); List <Lookup> teamFieldsMap = await _context.Lookups.Where(l => l.SetName.Equals("CSVHeader")).ToListAsync(); Dictionary <string, Team> teams = await _context.Teams.ToDictionaryAsync(t => t.AltName, t => t); Dictionary <string, int> headerCodes = data[0].Split(',') .Select((val, idx) => new { val, idx }) .ToDictionary(p => p.val, p => p.idx); for (int i = 1; i < data.Length; i++) { string[] fixtureData = data[i].Split(','); Fixture fixture = new Fixture(); Type type = fixture.GetType(); foreach (Lookup l in teamFieldsMap) { PropertyInfo prop = type.GetProperty(l.Value); int idx = -1; if (headerCodes.ContainsKey(l.Code)) { idx = headerCodes[l.Code]; } if (idx >= 0 && !(prop is null)) { switch (l.ShortValue) { case "Competition": prop.SetValue(fixture, competition); break; case "Team": if (teams.ContainsKey(fixtureData[idx])) { prop.SetValue(fixture, teams[fixtureData[idx]]); } else { // Team doesn't exist in Db, create a new one Team t = new Team() { Name = fixtureData[idx], AltName = fixtureData[idx], Country = competition.Country }; if (t.CompetitionTeams is null) { t.CompetitionTeams = new List <CompetitionTeam>(); } t.CompetitionTeams.Add(new CompetitionTeam() { Competition = competition, Team = t }); _context.Teams.Add(t); await _context.SaveChangesAsync(); t = await _context.Teams.Where(t => t.AltName.Equals(fixtureData[idx])).FirstOrDefaultAsync(); teams.Add(t.AltName, t); prop.SetValue(fixture, teams[fixtureData[idx]]); } break; case "DateTime": prop.SetValue(fixture, DateTime.ParseExact(fixtureData[idx], "dd/MM/yyyy", CultureInfo.InvariantCulture)); break; case "TimeSpan": prop.SetValue(fixture, Convert.ToDateTime(fixtureData[idx]).TimeOfDay); break; case "int": prop.SetValue(fixture, Convert.ToInt32(fixtureData[idx])); break; default: prop.SetValue(fixture, fixtureData[idx]); break; } } } fixtures.Add(fixture); } } return(fixtures); }
private object?[] GetSampleData(Fixture?fixture) => fixture?.GetType().GetProperty("SampleData", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(fixture) as object?[] ?? Array.Empty <object?>();