public void Simple() { var builder = new ObjectBuilder <User>(new TypeTreeCache(new TypeTreeBuilder()), AllValueTypesProvider.ValueTypes); var patches = new List <Patch> { new Patch() { Operation = "replace", Path = "/Name", Value = "Niclas" }, // new Patch() {Operation = "replace", Path = "/Address/Street", Value = "My street"} }; var test = builder.Build(patches); var watch = new Stopwatch(); watch.Start(); for (var i = 0; i < 500000; i++) { var user = builder.Build(patches); } watch.Stop(); Trace.WriteLine(watch.ElapsedMilliseconds); }
/// <summary> /// Mapp application to context /// </summary> /// <param name="applicationType"></param> private void MapApplicationContext(Type applicationType) { Debug.Assert(applicationType != null); object[] runRules = applicationType.GetCustomAttributes(typeof(RunRuleAttribute), true); if (runRules != null && runRules.Length > 0) { // Create new context IContext appContext = _runtime.CreateContext(); appContext.BindCondition(new ValueBoundCondition(true), true); // Add rules to context foreach (RunRuleAttribute runRule in runRules) { IContextRule rule = appContext.BindRule(ObjectBuilder.Build <IRule>(runRule.Rule)); // Add actions if (runRule.FaultActions != null && runRule.FaultActions.Length > 0) { foreach (Type action in runRule.FaultActions) { rule.FaultActions.Add(ObjectBuilder.Build <IAction>(action)); } } } } }
public void TestConverterException() { IDictionary <String, EntityProperty> testEntities = new Dictionary <string, EntityProperty>(); testEntities.Add("CharValue", new EntityProperty("X")); Assert.ThrowsException <ConverterException>(() => ObjectBuilder.Build <UnsupportedTypePoco>(testEntities)); }
public object?Run() { var source = Source ?? new ILake[0]; var objBuilder = new ObjectBuilder(classExtensionType, source); var instance = (IExtension)objBuilder.Build(Args); return(instance.Main(Args ?? new Dictionary <string, object>())); }
static SchoolLogic() { _schoolService = ObjectBuilder <SchoolService> .Build(); _gradeService = ObjectBuilder <GradeService> .Build(); _mapper = MapBuilder.Build(); }
public ILibrarian BuildLibrarian(Assembly assembly) { var builder = new ObjectBuilder(typeof(AssemblyLibrarian), Lake); var librarian = (AssemblyLibrarian)builder.Build(); librarian.ManagedAssembly = assembly ?? throw new ArgumentNullException(nameof(assembly)); return(librarian); }
public void TestPocoWithInitializedArray() { SimplePocoWithArray spwa = SimplePocoWithArray.CreateFilledSimplePocoWithArray(); IDictionary <String, EntityProperty> allEntities = ObjectSerializer.Serialize(spwa); SimplePocoWithArray build = ObjectBuilder.Build <SimplePocoWithArray>(allEntities); Assert.AreEqual(3, allEntities.Count); CollectionAssert.AreEqual(build.DateTimeArray, spwa.DateTimeArray); }
public void TestPocoWithEmptyArray() { SimplePocoWithArray spwa = SimplePocoWithArray.CreateEmptySimplePocoWithArray(); IDictionary <String, EntityProperty> allEntities = ObjectSerializer.Serialize(spwa); SimplePocoWithArray build = ObjectBuilder.Build <SimplePocoWithArray>(allEntities); Assert.AreEqual(0, allEntities.Count); Assert.IsNull(build.DateTimeArray); }
public void CommandFactoryResolutionTest() { var factory = ObjectBuilder.Build <IWorkItemCommandFactory>(typeof(HotelWorkItem).Name); Assert.IsTrue(factory is HotelWorkItemCommandFactory); factory = ObjectBuilder.Build <IWorkItemCommandFactory>(typeof(MasterWorkItem).Name); Assert.IsTrue(factory is MasterWorkItemCommandFactory); }
public void should_set_field_value_when_call_with_method() { var objectBuilder = new ObjectBuilder <Person>(); objectBuilder.With(_ => _.Age, 18); var actualPerson = objectBuilder.Build(); Assert.Equal(18, actualPerson.Age); }
public void should_set_property_value_when_call_with_method() { var objectBuilder = new ObjectBuilder <Person>(); objectBuilder.With(_ => _.Name, "John Smith"); var actualPerson = objectBuilder.Build(); Assert.Equal("John Smith", actualPerson.Name); }
public void ListTest() { var builder = new ObjectBuilder <ObjectWithList>(new TypeTreeCache(new TypeTreeBuilder()), AllValueTypesProvider.ValueTypes); var patches = new List <Patch> { new Patch() { Operation = "add", Path = "/Addresses/0", Value = "" }, new Patch() { Operation = "add", Path = "/Addresses/1", Value = "" }, new Patch() { Operation = "add", Path = "/Addresses/0/Users/0", Value = "" }, new Patch() { Operation = "add", Path = "/Addresses/0/Users/1", Value = "" }, //new Patch() {Operation = "replace", Path = "/Addresses/0/Street", Value = "1234"}, //new Patch() {Operation = "replace", Path = "/Addresses/0/Users/0/Name", Value = "1234"}, new Patch() { Operation = "remove", Path = "/Addresses/0/Users/0", Value = "" } }; var watch = new Stopwatch(); watch.Start(); for (var i = 0; i < 100000; i++) { var user = builder.Build(patches); } watch.Stop(); Trace.WriteLine(watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); for (var i = 0; i < 100000; i++) { var user = new User(); user.Addresses.Add(new Address()); user.Addresses[0].Street = "1234"; user.Addresses[0].Users.Add(new User()); user.Addresses[0].Users[0].Name = "1234"; user.Addresses[0].Users.RemoveAt(0); } watch.Stop(); Trace.WriteLine(watch.ElapsedMilliseconds); }
public void AppacitiveModuleResolutionTest() { var syncDb = ObjectBuilder.Build <ISyncDb>(); Assert.IsTrue(syncDb is SyncDb); var hotelWorkItemDb = ObjectBuilder.Build <IHotelWorkItemDb>(); Assert.IsTrue(hotelWorkItemDb is WorkItemDb); }
public ILibrarian BuildLibrarian(Assembly assembly) { if (assembly == null) { throw new ArgumentNullException(nameof(assembly)); } var builder = new ObjectBuilder(typeof(AssemblyLibrarian), Lake); return((AssemblyLibrarian)builder.Build()); }
public async Task Do(CancellationToken cancellationToken) { // Specification // Each task will build the specific command that is required to execute it. // and delegate the execution the the command. var factory = ObjectBuilder.Build <IWorkItemCommandFactory>(this.GetType().Name); var command = factory.BuildCommand(this); await command.Execute(this, cancellationToken); }
public ILibrarian BuildLibrarian(Type libType) { if (libType == null) { throw new ArgumentNullException(nameof(libType)); } var builder = new ObjectBuilder(libType, Lake); return((ILibrarian)builder.Build()); }
public void TestListObjects() { PocoWihtListChildren pwlc = PocoWihtListChildren.CreateInitializdedPWLC(); IDictionary <string, EntityProperty> allEntities = ObjectSerializer.Serialize(pwlc); PocoWihtListChildren build = ObjectBuilder.Build <PocoWihtListChildren>(allEntities); Assert.AreEqual(2, allEntities.Count); Assert.AreEqual(3, build.Children.Count); CollectionAssert.AreEqual(build.Children, pwlc.Children); }
public void TestBuildAllEnitiesFromParentPoco() { ParentPoco pp = ParentPoco.CreateParentWithChild(); IDictionary <String, EntityProperty> allEntities = ObjectSerializer.Serialize(pp); Assert.AreEqual(12, allEntities.Count); ParentPoco build = ObjectBuilder.Build <ParentPoco>(allEntities); Assert.IsNotNull(build); Assert.IsInstanceOfType(build, typeof(ParentPoco)); }
public EnemyInstance(MonsterModel model) : base(model.HealthPoint, 0, 0, model.Img, model.Element) { this._monsterModel = model; this._cards = new ListenableList <MonsterCardInstance>(); this._cardQueue = new ListenableList <MonsterCardInstance>(); ObjectBuilder builder = new ObjectBuilder(model.Strategy.Name); foreach (JKeyValuePair pair in model.Strategy.Properties) { builder.SetProperty(pair.Key, pair.Value); } Debug.Log("strategyr: " + builder.Build().ToString()); this._strategy = (IAIStrategy)builder.Build(); foreach (JMonsterCardProperties cardData in model.MonsterCards) { this._cards.AddItem(new MonsterCardInstance(Constants.language_zh_tw, cardData)); } }
public void TestBuildAllEnitiesFromMainWithParent() { MainWithParent mwp = MainWithParent.CreateMainWithParent(); IDictionary <String, EntityProperty> allEntities = ObjectSerializer.Serialize(mwp); Assert.AreEqual(24, allEntities.Count); Assert.IsTrue(allEntities.ContainsKey("Id")); MainWithParent build = ObjectBuilder.Build <MainWithParent>(allEntities); Assert.IsNotNull(build); Assert.IsInstanceOfType(build, typeof(MainWithParent)); }
public void TestBuildAllEnitiesFromSimplePocoWithNullId() { SimplePoco spo = SimplePoco.CreatePocoWithoutID(); IDictionary <String, EntityProperty> allEntities = ObjectSerializer.Serialize(spo); Assert.AreEqual(10, allEntities.Count); Assert.IsFalse(allEntities.ContainsKey("Id")); SimplePoco build = ObjectBuilder.Build <SimplePoco>(allEntities); Assert.IsNotNull(build); Assert.IsNull(build.Id); }
static AccountLogic() { userService = ObjectBuilder <UserService> .Build(); userGradesService = ObjectBuilder <UserGradesService> .Build(); gradeService = ObjectBuilder <GradeService> .Build(); studentInfoService = ObjectBuilder <StudentInfoService> .Build(); mapper = MapBuilder.Build(); }
public static async Task <T> GetByIdAsync <T>(this CloudTable cloudTable, String id, string partition) { TableOperation retrive = TableOperation.Retrieve <DynamicTableEntity>(partition, id); TableResult result = await cloudTable.ExecuteAsync(retrive); DynamicTableEntity dte = result.Result as DynamicTableEntity; if (dte == null) { return(default(T)); } return(ObjectBuilder.Build <T>(dte.Properties)); }
public void TestBuildAllEntitesFromBooleanAndByte() { ByteAndBooleanPoco spo = ByteAndBooleanPoco.Create(); IDictionary <String, EntityProperty> allEntities = ObjectSerializer.Serialize(spo); Assert.AreEqual(3, allEntities.Count); ByteAndBooleanPoco build = ObjectBuilder.Build <ByteAndBooleanPoco>(allEntities); Assert.IsNotNull(build); Assert.AreEqual(spo.BoolValue, build.BoolValue); Assert.AreEqual(spo.BooleanValue, build.BooleanValue); Assert.AreEqual(spo.ByteValue, build.ByteValue); }
public void missing_constructor_value() { var values = new Dictionary <string, string> { { "a", "1" } }; var builder = new ObjectBuilder(); var result = builder.Build(new BuildObjectContext(typeof(ConstructorExample), values)); result.HasErrors().ShouldBeTrue(); result.Result.ShouldBeNull(); }
void NewObjects() { if (_cursize < _maxsize) { for (int i = 0; i < _initialsize; ++i) { T t = _builder.Build <T>(_original); t.gameObject.SetActive(false); _stored.Enqueue(t); } _cursize += _initialsize; } }
public void Simple() { var builder = new ObjectBuilder<User>(new TypeTreeCache(new TypeTreeBuilder()), AllValueTypesProvider.ValueTypes); var patches = new List<Patch> { new Patch() {Operation = "replace", Path = "/Name", Value = "Niclas"}, // new Patch() {Operation = "replace", Path = "/Address/Street", Value = "My street"} }; var test = builder.Build(patches); var watch = new Stopwatch(); watch.Start(); for (var i = 0; i < 500000; i++) { var user = builder.Build(patches); } watch.Stop(); Trace.WriteLine(watch.ElapsedMilliseconds); }
public static async Task <List <T> > GetAllByQueryAsync <T>(this CloudTable cloudTable, TableQuery <DynamicTableEntity> query) { TableContinuationToken token = null; List <DynamicTableEntity> resultTE = new List <DynamicTableEntity>(); do { TableQuerySegment <DynamicTableEntity> segment = await cloudTable.ExecuteQuerySegmentedAsync <DynamicTableEntity>(query, null); token = segment.ContinuationToken; resultTE.AddRange(segment.Results); } while(token != null); return(resultTE.Select(dte => ObjectBuilder.Build <T>(dte.Properties)).ToList()); }
public object?Run() { try { var source = Source ?? LakeExtension.Empty; var objBuilder = new ObjectBuilder(classExtensionType, source); var instance = (IExtension)objBuilder.Build(Args); return(instance.Main(Args ?? new Dictionary <string, object>())); } catch (TargetInvocationException e) { throw e.InnerException ?? e; } }
public void missing_properties_has_no_errors() { var values = new Dictionary <string, string> { { "b", "2" } }; var builder = new ObjectBuilder(); var result = builder.Build(new BuildObjectContext(typeof(PropertyExample), values)); result.HasErrors().ShouldBeFalse(); var example = result.Result.As <PropertyExample>(); example.A.ShouldBeNull(); example.B.ShouldEqual("2"); }
public void happy_path_through_default_constructor_and_properties() { var values = new Dictionary <string, string> { { "a", "1" }, { "b", "2" } }; var builder = new ObjectBuilder(); var result = builder.Build(new BuildObjectContext(typeof(PropertyExample), values)); result.HasErrors().ShouldBeFalse(); var example = result.Result.As <PropertyExample>(); example.A.ShouldEqual("1"); example.B.ShouldEqual("2"); }
public void ListTest() { var builder = new ObjectBuilder<ObjectWithList>(new TypeTreeCache(new TypeTreeBuilder()), AllValueTypesProvider.ValueTypes); var patches = new List<Patch> { new Patch() {Operation = "add", Path = "/Addresses/0", Value = ""}, new Patch() {Operation = "add", Path = "/Addresses/1", Value = ""}, new Patch() {Operation = "add", Path = "/Addresses/0/Users/0", Value = ""}, new Patch() {Operation = "add", Path = "/Addresses/0/Users/1", Value = ""}, //new Patch() {Operation = "replace", Path = "/Addresses/0/Street", Value = "1234"}, //new Patch() {Operation = "replace", Path = "/Addresses/0/Users/0/Name", Value = "1234"}, new Patch() {Operation = "remove", Path = "/Addresses/0/Users/0", Value = ""} }; var watch = new Stopwatch(); watch.Start(); for (var i = 0; i < 100000; i++) { var user = builder.Build(patches); } watch.Stop(); Trace.WriteLine(watch.ElapsedMilliseconds); watch.Reset(); watch.Start(); for (var i = 0; i < 100000; i++) { var user = new User(); user.Addresses.Add(new Address()); user.Addresses[0].Street = "1234"; user.Addresses[0].Users.Add(new User()); user.Addresses[0].Users[0].Name = "1234"; user.Addresses[0].Users.RemoveAt(0); } watch.Stop(); Trace.WriteLine(watch.ElapsedMilliseconds); }