Esempio n. 1
0
 public TestClassBuilder() : base(new TestClass())
 {
     DefaultValues = new Dictionary <string, Func <dynamic> >
     {
         { GenericExtensions.GetPropertyName <TestClass, TestClass>(tc => tc.MeToo), () => new TestClass() }
     };
 }
 public EnvironmentalWorldDataBuilder() : base(new EnvironmentalWorldData())
 {
     DefaultValues = new Dictionary <string, Func <dynamic> >
     {
         { GenericExtensions.GetPropertyName <EnvironmentalWorldData, EnvironmentalCellGrid>(wd => wd.Grid), () => new EnvironmentalCellGrid(0) },
         { GenericExtensions.GetPropertyName <EnvironmentalWorldData, SeasonalTime>(wd => wd.Season), () => SeasonalTime.Spring }
     };
 }
Esempio n. 3
0
 public StandardWorldBuilder() : base(new StandardWorld())
 {
     DefaultValues = new Dictionary <string, Func <dynamic> >
     {
         { GenericExtensions.GetPropertyName <StandardWorld, StandardWorldData>(w => w.Data), () => new StandardWorldData() },
         { GenericExtensions.GetPropertyName <StandardWorld, IFindNeighbours <StandardCell, StandardCellGrid> >(w => w.NeighbourFinder), () => new OpenNeighbourFinder <StandardCell, StandardCellGrid>() },
         { GenericExtensions.GetPropertyName <StandardWorld, ICalculateCell <StandardCell, StandardCellGrid, StandardWorldData> >(w => w.CellCalculator), () => new StandardCellCalculator() },
         { GenericExtensions.GetPropertyName <StandardWorld, IGenerateWorld <StandardCell, StandardCellGrid, StandardWorldData, StandardWorld> >(w => w.WorldGenerator), () => new StandardWorldGenerator() }
     };
 }
Esempio n. 4
0
        public static void SkipIfContainsNestedProperties <T, TReturn>(this ModelStateDictionary modelState, Expression <Func <T, TReturn> > expression)
        {
            var propName = GenericExtensions.GetPropertyName(expression);

            modelState
            .Keys
            .Where(x => x.Contains(propName) && !x.Equals(propName))
            .ToList()
            .ForEach(key => modelState[key].Errors.Clear());
        }
 public EnvironmentalWorldBuilder() : base(new EnvironmentalWorld())
 {
     DefaultValues = new Dictionary <string, Func <dynamic> >
     {
         { GenericExtensions.GetPropertyName <EnvironmentalWorld, EnvironmentalWorldData>(w => w.Data), () => new StandardWorldData() },
         { GenericExtensions.GetPropertyName <EnvironmentalWorld, IFindNeighbours <EnvironmentalCell, EnvironmentalCellGrid> >(w => w.NeighbourFinder), () => new OpenNeighbourFinder <EnvironmentalCell, EnvironmentalCellGrid>() },
         { GenericExtensions.GetPropertyName <EnvironmentalWorld, ICalculateCell <EnvironmentalCell, EnvironmentalCellGrid, EnvironmentalWorldData> >(w => w.CellCalculator), () => new EnvironmentalCellCalculator(new Random()) },
         { GenericExtensions.GetPropertyName <EnvironmentalWorld, IGenerateWorld <EnvironmentalCell, EnvironmentalCellGrid, EnvironmentalWorldData, EnvironmentalWorld> >(w => w.WorldGenerator), () => new EnvironmentalWorldGenerator() },
         { GenericExtensions.GetPropertyName <EnvironmentalWorld, ICalculateSeason>(w => w.SeasonCalculator), () => new NoSeasonCalculator() }
     };
 }
        public void GetPropertyName_Field_IsName()
        {
            // arrange
            const string expected = nameof(TestClass.IAmMostDefinitelyNotAProperty);

            // act
            var result = GenericExtensions.GetPropertyName <TestClass, string>(tc => tc.IAmMostDefinitelyNotAProperty);

            // assert
            Assert.AreEqual(expected, result);
        }
        public void GetPropertyName_ComplexProperty_IsName()
        {
            // arrange
            const string expected = nameof(TestClass.MeToo);

            // act
            var result = GenericExtensions.GetPropertyName <TestClass, TestClass>(tc => tc.MeToo);

            // assert
            Assert.AreEqual(expected, result);
        }
        public void GetPropertyName_PrimitiveProperty_IsName()
        {
            // arrange
            const string expected = nameof(TestClass.IAmAProperty);

            // act
            var result = GenericExtensions.GetPropertyName <TestClass, int>(tc => tc.IAmAProperty);

            // assert
            Assert.AreEqual(expected, result);
        }