public void SetUp() { objectRepository = new Dictionary <string, object>(); ReflectionOptimizer.Enable(); var apiCtx = BuildRoutine.Context() .AsClientApplication( codingStyle = BuildRoutine.CodingStyle() .FromBasic() .AddCommonSystemTypes() .AddTypes(GetType().Assembly, t => t.Namespace?.StartsWith("Routine.Test.Performance.Domain") == true) .Use(p => p.ParseableValueTypePattern()) .Initializers.Add(c => c.PublicConstructors().When(type.of <BusinessPerformanceInput>())) .Datas.Add(c => c.Properties(m => !m.IsInherited(true, true))) .DataFetchedEagerly.Set(true) .Operations.Add(c => c.Methods(o => !o.IsInherited(true, true))) .IdExtractor.Set(c => c.IdByProperty(m => m.Returns <int>("Id"))) .Locator.Set(c => c.Locator(l => l.SingleBy(id => objectRepository[id]))) .ValueExtractor.Set(c => c.Value(e => e.By(o => $"{o}"))) ); objectService = apiCtx.ObjectService; rapp = apiCtx.Application; var _ = objectService.ApplicationModel; }
public void Refreshes_added_types_within_coding_style_when_a_new_type_is_added_so_that_old_IType_instances_are_not_stored() { var codingStyle = BuildRoutine.CodingStyle().FromBasic() .AddTypes(typeof(CachedBusiness)) .IdExtractor.Set(c => c.IdByProperty(m => m.Returns <string>("Id"))) .Locator.Set(c => c.Locator(l => l.Constant(null))) .ValueExtractor.Set(c => c.Value(e => e.By(obj => $"{obj}"))); var testing = new DefaultCoreContext(codingStyle, new DictionaryCache()); testing.GetDomainTypes(); var expected = testing.GetDomainType(type.of <CachedBusiness>()); codingStyle.AddTypes(typeof(LaterAddedType)); testing = new DefaultCoreContext(codingStyle, new DictionaryCache()); testing.GetDomainTypes(); var actual = testing.GetDomainType(type.of <CachedBusiness>()); Assert.AreNotSame(expected.Type, actual.Type); }
public override void SetUp() { base.SetUp(); objectRepository = new Dictionary <string, object>(); codingStyle = BuildRoutine.CodingStyle().FromBasic() .AddTypes(GetType().Assembly, t => t.IsPublic && t.Namespace != null && t.Namespace.StartsWith(RootNamespace)) .Initializers.Add(c => c.Constructors().When(t => t.IsValueType && t.Namespace?.StartsWith(RootNamespace) == true)) .Datas.Add(c => c.PublicProperties(m => !m.IsInherited()).When(t => t.Namespace?.StartsWith(RootNamespace) == true)) .Operations.Add(c => c.PublicMethods(m => !m.IsInherited()).When(t => t.Namespace?.StartsWith(RootNamespace) == true)) .IdExtractor.Set(c => c.IdByProperty(p => p.Returns <string>("Id")).When(t => t.Namespace != null && t.Namespace.StartsWith(RootNamespace))) .Locator.Set(c => c.Locator(l => l.SingleBy(id => objectRepository[id])).When(t => t.Namespace != null && t.Namespace.StartsWith(RootNamespace) && t.Properties.Any(m => m.Returns <string>("Id")))) .NextLayer() ; var cache = new DictionaryCache(); ctx = new DefaultCoreContext(codingStyle, cache); testing = new ObjectService(ctx, cache); }
public static IServiceContext AsServiceApplication( this ContextBuilder source, Func <ServiceConfigurationBuilder, IServiceConfiguration> serviceConfiguration, Func <CodingStyleBuilder, ICodingStyle> codingStyle ) => source.AsServiceApplication( serviceConfiguration(BuildRoutine.ServiceConfig()), codingStyle(BuildRoutine.CodingStyle()) );
public void When_an_interface_has_a_default_method__it_can_be_an_operation_of_its_view_model() { var testing = BuildRoutine.CodingStyle().FromBasic(); testing.AddTypes(typeof(IAnInterface), typeof(AClass)); testing.Operations.Add(c => c.PublicMethods().When(type.of <IAnInterface>())); var operations = ((ICodingStyle)testing).GetOperations(type.of <IAnInterface>()); Assert.AreEqual(1, operations.Count); Assert.AreEqual(nameof(IAnInterface.DefaultMethodOp), operations[0].Name); }
public void When_configuring_nullable_types__type_and_module_names_come_from_the_type_that_is_nullable() { var testing = BuildRoutine.CodingStyle().FromBasic() as ICodingStyle; Assert.AreEqual("Int32?", testing.GetName(type.of <int?>())); Assert.AreEqual("System", testing.GetModule(type.of <int?>())); Assert.AreEqual("DateTime?", testing.GetName(type.of <DateTime?>())); Assert.AreEqual("System", testing.GetModule(type.of <DateTime?>())); Assert.AreEqual("Text?", testing.GetName(type.of <Text?>())); Assert.AreEqual("Routine.Test", testing.GetModule(type.of <Text?>())); }
public void A_nullable_reference_type_is_treated_just_like_a_not_nullable_one() { var testing = BuildRoutine.CodingStyle().FromBasic(); testing.AddTypes(typeof(AClassWithNullableReferenceType)); testing.Datas.Add(c => c.PublicProperties()); var datas = ((ICodingStyle)testing).GetDatas(type.of <AClassWithNullableReferenceType>()); Assert.AreEqual(2, datas.Count); Assert.AreEqual(nameof(AClassWithNullableReferenceType.NullableString), datas[0].Name); Assert.AreEqual("System.String", datas[0].ReturnType.FullName); Assert.AreEqual(nameof(AClassWithNullableReferenceType.NotNullableString), datas[1].Name); Assert.AreEqual("System.String", datas[1].ReturnType.FullName); }
public void Caches_domain_types_by_object_model_id() { ICodingStyle codingStyle = BuildRoutine.CodingStyle().FromBasic() .AddTypes(GetType().Assembly, t => !string.IsNullOrEmpty(t.Namespace) && t.Namespace.StartsWith("Routine.Test.Engine.Context.Domain")) .IdExtractor.Set(c => c.IdByProperty(m => m.Returns <string>("Id"))) .Locator.Set(c => c.Locator(l => l.Constant(null))) .ValueExtractor.Set(c => c.Value(e => e.By(obj => $"{obj}"))); var testing = new DefaultCoreContext(codingStyle, new DictionaryCache()); testing.GetDomainTypes(); var domainType = testing.GetDomainType(type.of <CachedBusiness>()); var expected = testing.GetDomainType(domainType.Id); var actual = testing.GetDomainType(domainType.Id); Assert.AreSame(expected, actual); }
public void When_a_record_is_added__it_can_be_configured_like_any_other_class() { var testing = BuildRoutine.CodingStyle().FromBasic(); testing.AddTypes(typeof(ARecord)); testing.Initializers.Add(c => c.PublicConstructors().When(type.of <ARecord>())); testing.Datas.Add(c => c.PublicProperties().When(type.of <ARecord>())); var initializers = ((ICodingStyle)testing).GetInitializers(type.of <ARecord>()); var datas = ((ICodingStyle)testing).GetDatas(type.of <ARecord>()); Assert.AreEqual(1, initializers.Count); Assert.AreEqual(1, initializers[0].Parameters.Count); Assert.AreEqual(nameof(ARecord.Data), initializers[0].Parameters[0].Name); Assert.AreEqual(type.of <string>(), initializers[0].Parameters[0].ParameterType); Assert.AreEqual(1, datas.Count); Assert.AreEqual(nameof(ARecord.Data), datas[0].Name); Assert.AreEqual(type.of <string>(), datas[0].ReturnType); }
public void When_a_ref_struct_is_added__it_is_ignored_automatically() { var testing = BuildRoutine.CodingStyle().FromBasic().AddTypes(typeof(ARefStruct)) as ICodingStyle; Assert.IsFalse(testing.ContainsType(TypeInfo.Get(typeof(ARefStruct)))); }
public void When_adding_a_value_type__nullable_version_is_added_automatically() { var testing = BuildRoutine.CodingStyle().FromBasic().AddTypes(typeof(int)) as ICodingStyle; Assert.IsTrue(testing.ContainsType(type.of <int?>())); }
public static IClientContext AsClientApplication( this ContextBuilder source, Func <CodingStyleBuilder, ICodingStyle> codingStyle ) => source.AsClientApplication( codingStyle(BuildRoutine.CodingStyle()) );