public PersonService(IContentObjectRepository aRepository) { _personRepository = aRepository; _simpleMapper = new SimpleMapper(); _simpleMapper.AddMapper<Data.Entities.Person, Person>((Data.Entities.Person aPerson) => new Person { Id = aPerson.Id, Name = aPerson.Name, Description = aPerson.Description, BirthDate = aPerson.BirthDate.ToShortDateString(), FirstName = aPerson.FirstName, LastName = aPerson.LastName, Gender = (Gender)aPerson.Gender, Type = "person" }); _simpleMapper.AddMapper((Person aPerson) => new Data.Entities.Person { Id = aPerson.Id, Name = aPerson.FirstName + " " + aPerson.LastName, Description = aPerson.Description, BirthDate = DateTime.Parse(aPerson.BirthDate), FirstName = aPerson.FirstName, LastName = aPerson.LastName, Gender = (int)aPerson.Gender }); }
public IniSectionConfiguration([NotNull] string section, [NotNull] SimpleMapper<IniContext> mapper, [NotNull] IIniSerializerConfiguration configuration, [NotNull] Type targeType) { _section = section; _mapper = mapper; _configuration = configuration; _targeType = targeType; }
public IniKeyConfiguration([NotNull] string section, [NotNull] IIniSerializerConfiguration configuration, [NotNull] SimpleMapper<IniContext> mapper, bool isSingle, [NotNull] Type targetType) { _section = section; _configuration = configuration; _mapper = mapper; _isSingle = isSingle; _targetType = targetType; }
public XmlAttributeConfiguration([NotNull] IXmlSerializerConfiguration config, [NotNull] XmlElementTarget rootTarget, [NotNull] XmlElementTarget target, [NotNull] SimpleMapper<XmlElementContext> mapper, [NotNull] Type targetType) { _config = config; _rootTarget = rootTarget; _target = target; _mapper = mapper; _targetType = targetType; }
public HeaderedFileKeyCofiguration([NotNull] IHeaderedFileSerializerConfiguration config, [NotNull] SimpleMapper<HeaderdFileContext> mapper, [NotNull] string keyName, MappingType mappingType, [NotNull] Type type) { _config = config; _mapper = mapper; _keyName = keyName; _mappingType = mappingType; _type = type; }
public void InvokeMappedOnly() { var mapper = new SimpleMapper<User>(); mapper.Add(x => x.FirstName, "first_name"); var customMapping = Substitute.For<IColumnMapping>(); customMapping.SetValue(Arg.Any<IDataRecord>(), Arg.Any<object>()); mapper.Add(customMapping); var record = Substitute.For<IDataRecord>(); record["first_name"].Returns("Jonas"); record["age"].Returns(10); var actual = mapper.Map(record); Assert.Equal("Jonas", actual.FirstName); Assert.Equal(0, actual.Id); customMapping.Received().SetValue(Arg.Any<IDataRecord>(), Arg.Any<object>()); }
public BookService(IContentObjectRepository aRepository) { _bookRepository = aRepository; _simpleMapper = new SimpleMapper(); _simpleMapper.AddMapper<Data.Entities.Book, Book>((aBook) => new Book { Id = aBook.Id, Name = aBook.Name, Description = aBook.Description, Author = _simpleMapper.Map<Data.Entities.Person, Person>(aBook.Author), Copyright = aBook.Copyright, Published = aBook.Published.ToShortDateString(), Type = "book" }); _simpleMapper.AddMapper<Book, Data.Entities.Book>((Book aBook) => new Data.Entities.Book { Id = aBook.Id, Name = aBook.Name, Description = aBook.Description, AuthorId = aBook.Author.Id, Author = _simpleMapper.Map<Person, Data.Entities.Person>(aBook.Author), Copyright = aBook.Copyright, Published = DateTime.Parse(aBook.Published), }); _simpleMapper.AddMapper<Data.Entities.Person, Person>((aPerson) => new Person { Id = aPerson.Id, Name = aPerson.Name, Description = aPerson.Description, BirthDate = aPerson.BirthDate.ToShortDateString(), FirstName = aPerson.FirstName, LastName = aPerson.LastName, Gender = (Gender)aPerson.Gender, Type = "person" }); _simpleMapper.AddMapper<Person, Data.Entities.Person>((Person aPerson) => new Data.Entities.Person { Id = aPerson.Id, Name = aPerson.Name, Description = aPerson.Description, BirthDate = DateTime.Parse(aPerson.BirthDate), FirstName = aPerson.FirstName, LastName = aPerson.LastName, Gender = (int)aPerson.Gender }); }
public ContentService(IContentObjectRepository aRepository) { _contentObjectRepository = aRepository; _simpleMapper = new SimpleMapper(); _simpleMapper.AddMapper<Data.Entities.ContentObject, Content>((aContentObject) => new Content { Id = aContentObject.Id, Name = aContentObject.Name, Description = aContentObject.Description, Type = aContentObject is Data.Entities.Book ? "book" : "person" }); _simpleMapper.AddMapper<Content, Data.Entities.ContentObject>((aContent) => new Data.Entities.ContentObject { Id = aContent.Id, Name = aContent.Name, Description = aContent.Description }); }
public RuleTriggerDto Visit(SchemaChangedTrigger trigger) { return(SimpleMapper.Map(trigger, new SchemaChangedRuleTriggerDto())); }
public void Delete(DeleteAsset command) { RaiseEvent(SimpleMapper.Map(command, new AssetDeleted { DeletedSize = Snapshot.TotalSize })); }
public RuleTriggerDto Visit(UsageTrigger trigger) { return(SimpleMapper.Map(trigger, new UsageRuleTriggerDto())); }
public static HistoryEventDto FromHistoryEvent(IHistoryEventEntity x) { return(SimpleMapper.Map(x, new HistoryEventDto())); }
protected void On(AppCreated @event) { Roles = Roles.CreateDefaults(@event.Name); SimpleMapper.Map(@event, this); }
public void ChangePlan(ChangePlan command) { RaiseEvent(SimpleMapper.Map(command, new AppPlanChanged())); }
private static void Map_is_called_with_properties_to_ignore(SimpleMapper simpleMapper, SourceContext context) { context.Expected.DecimalProperty = 0; simpleMapper.Map(context.Source, context.Destination, new Expression<Func<OutputClass, object>>[] { x => x.DecimalProperty }); }
public void AddLanguage(AddLanguage command) { RaiseEvent(SimpleMapper.Map(command, new AppLanguageAdded())); }
public void RemoveLanguage(RemoveLanguage command) { RaiseEvent(SimpleMapper.Map(command, new AppLanguageRemoved())); }
public void RevokeClient(RevokeClient command) { RaiseEvent(SimpleMapper.Map(command, new AppClientRevoked())); }
public void AttachClient(AttachClient command) { RaiseEvent(SimpleMapper.Map(command, new AppClientAttached())); }
public void RemoveContributor(RemoveContributor command) { RaiseEvent(SimpleMapper.Map(command, new AppContributorRemoved())); }
public void AssignContributor(AssignContributor command) { RaiseEvent(SimpleMapper.Map(command, new AppContributorAssigned())); }
public void AddPattern(AddPattern command) { RaiseEvent(SimpleMapper.Map(command, new AppPatternAdded())); }
private static void Map_is_called_with_custom_conversions(SimpleMapper obj, SourceContext context) { context.Source.Map() .WithCustomConversion((d1, d2) => d1 == typeof(decimal) && d2 == typeof(decimal), value => (decimal)value + 1) .WithCustomConverter(new DateTimeToNullableDateTimeConverter()) .WithCustomConverters(new IntToIntConverter(), new DateTimeToDateTimeConverter(), new StringToStringConverter()) .To(context.Destination); }
public void DeletePattern(DeletePattern command) { RaiseEvent(SimpleMapper.Map(command, new AppPatternDeleted())); }
private static void Not_change_the_destination_object(SimpleMapper obj, LowerCaseContext context) { var result = new MappingTester<OutputClassLowerCase>().Verify(context.Destination, context.Expected); result.IsValid.ShouldBeTrue(result.ToString()); }
public void UpdatePattern(UpdatePattern command) { RaiseEvent(SimpleMapper.Map(command, new AppPatternUpdated())); }
public static PlanDto FromPlan(IAppLimitsPlan plan) { return(SimpleMapper.Map(plan, new PlanDto())); }
public void ArchiveApp(ArchiveApp command) { RaiseEvent(SimpleMapper.Map(command, new AppArchived())); }
public void Move(MoveAsset command) { RaiseEvent(SimpleMapper.Map(command, new AssetMoved())); }
public override bool ApplyEvent(IEvent @event) { switch (@event) { case AppCreated e: { Id = e.AppId.Id; SimpleMapper.Map(e, this); return(true); } case AppUpdated e when Is.Change(Label, e.Label) || Is.Change(Description, e.Description): { SimpleMapper.Map(e, this); return(true); } case AppImageUploaded e: return(UpdateImage(e, ev => ev.Image)); case AppImageRemoved e when Image != null: return(UpdateImage(e, ev => null)); case AppPlanChanged e when Is.Change(Plan?.PlanId, e.PlanId): return(UpdatePlan(e, ev => ev.ToAppPlan())); case AppPlanReset e when Plan != null: return(UpdatePlan(e, ev => null)); case AppContributorAssigned e: return(UpdateContributors(e, (ev, c) => c.Assign(ev.ContributorId, ev.Role))); case AppContributorRemoved e: return(UpdateContributors(e, (ev, c) => c.Remove(ev.ContributorId))); case AppClientAttached e: return(UpdateClients(e, (ev, c) => c.Add(ev.Id, ev.Secret))); case AppClientUpdated e: return(UpdateClients(e, (ev, c) => c.Update(ev.Id, ev.Name, ev.Role, ev.ApiCallsLimit, ev.ApiTrafficLimit, ev.AllowAnonymous))); case AppClientRevoked e: return(UpdateClients(e, (ev, c) => c.Revoke(ev.Id))); case AppWorkflowAdded e: return(UpdateWorkflows(e, (ev, w) => w.Add(ev.WorkflowId, ev.Name))); case AppWorkflowUpdated e: return(UpdateWorkflows(e, (ev, w) => w.Update(ev.WorkflowId, ev.Workflow))); case AppWorkflowDeleted e: return(UpdateWorkflows(e, (ev, w) => w.Remove(ev.WorkflowId))); case AppPatternAdded e: return(UpdatePatterns(e, (ev, p) => p.Add(ev.PatternId, ev.Name, ev.Pattern, ev.Message))); case AppPatternDeleted e: return(UpdatePatterns(e, (ev, p) => p.Remove(ev.PatternId))); case AppPatternUpdated e: return(UpdatePatterns(e, (ev, p) => p.Update(ev.PatternId, ev.Name, ev.Pattern, ev.Message))); case AppRoleAdded e: return(UpdateRoles(e, (ev, r) => r.Add(ev.Name))); case AppRoleUpdated e: return(UpdateRoles(e, (ev, r) => r.Update(ev.Name, ev.ToPermissions(), ev.Properties))); case AppRoleDeleted e: return(UpdateRoles(e, (ev, r) => r.Remove(ev.Name))); case AppLanguageAdded e: return(UpdateLanguages(e, (ev, l) => l.Set(ev.Language))); case AppLanguageRemoved e: return(UpdateLanguages(e, (ev, l) => l.Remove(ev.Language))); case AppLanguageUpdated e: return(UpdateLanguages(e, (ev, l) => { l = l.Set(ev.Language, ev.IsOptional, ev.Fallback); if (ev.IsMaster) { l = Languages.MakeMaster(ev.Language); } return l; })); case AppArchived: { Plan = null; IsArchived = true; return(true); } } return(false); }
private void Raise <T, TEvent>(T command, TEvent @event) where T : class where TEvent : AppEvent { RaiseEvent(Envelope.Create(SimpleMapper.Map(command, @event))); }
private static void A_null_source(SimpleMapper obj, LowerCaseContext context) { context.Source = null; context.Destination = new OutputClassLowerCase(); context.Expected = new OutputClassLowerCase(); }
public void RegisterSimpleMapperTest1() { TransformerObserver observer = new TransformerObserver(); var mapper = new SimpleMapper<int?, int>(i => i.HasValue ? i.Value : 0); Assert.IsTrue(observer.RegisterMapper(mapper)); var res = observer.TryToMap<int?, int>(5); Assert.AreEqual(res, 5); var mapper1 = new SimpleMapper<KeyService, KeyServiceOther>( service => (KeyServiceOther)Enum.ToObject(typeof(KeyServiceOther), service)); Assert.IsTrue(observer.RegisterMapper(mapper1)); var res1 = observer.TryToMap<KeyService, KeyServiceOther>(KeyService.Type2); Assert.AreEqual(res1, KeyServiceOther.Type2); var res2 = observer.TryToMap<KeyService, KeyServiceOther>(KeyService.Type3); Assert.AreEqual(res2, KeyServiceOther.Type3); }
private static void Inputs_whose_property_names_have_different_casing(SimpleMapper obj, LowerCaseContext context) { context.Source = new ClassFiller<InputClass>().Source; context.Destination = new OutputClassLowerCase(); context.Expected = new OutputClassLowerCase { strIngPropErty = context.Source.StringProperty, }; // sanity check that the property names are different by case alone var inputPropertyName = Reflection.GetPropertyName((InputClass input) => input.StringProperty); var actualPropertyName = Reflection.GetPropertyName((OutputClassLowerCase x) => x.strIngPropErty); actualPropertyName.ShouldNotBeEqualTo(inputPropertyName); String.Compare(actualPropertyName, inputPropertyName, StringComparison.OrdinalIgnoreCase).ShouldBeEqualTo(0); }
public RuleTriggerDto Visit(ManualTrigger trigger) { return(SimpleMapper.Map(trigger, new ManualRuleTriggerDto())); }
private static void Map_is_called(SimpleMapper simpleMapper, DynamicDestinationContext context) { simpleMapper.Map(context.Source, context.Destination); }
public DeleteAsset ToCommand(DomainId id) { return(SimpleMapper.Map(this, new DeleteAsset { AssetId = id })); }
public void UpdateLanguage(UpdateLanguage command) { RaiseEvent(SimpleMapper.Map(command, new AppLanguageUpdated())); }
private static void A_null_destination(SimpleMapper arg1, ObjectSourceContext context) { context.Source = new ClassFiller<InputClass>().Source; context.Destination = null; }
public static NotificationSettingDto FromDomainObject(NotificationSetting source) { var result = SimpleMapper.Map(source, new NotificationSettingDto()); return(result); }
private static void Inputs_configured_for_custom_conversions(SimpleMapper obj, SourceContext context) { context.Source = new ClassFiller<InputClass>().Source; context.Destination = new OutputClass(); context.Expected = new OutputClass { BooleanProperty = context.Source.BooleanProperty, DateTimeProperty = context.Source.DateTimeProperty.AddDays(-1), DateTimeToNullable = context.Source.DateTimeToNullable.AddDays(1), DecimalProperty = context.Source.DecimalProperty + 1, IntegerProperty = context.Source.IntegerProperty + 1, StringProperty = context.Source.StringProperty + "!" }; }
public NotificationSetting ToDomainObject() { var result = SimpleMapper.Map(this, new NotificationSetting()); return(result); }
private static void Inputs_whose_property_names_have_different_spelling(SimpleMapper obj, AlternateNameContext context) { context.Source = new ClassFiller<InputClass>().Source; context.Destination = new OutputAlternativeNamesClass(); context.Expected = new OutputAlternativeNamesClass { BoolProperty = context.Source.BooleanProperty, DateProperty = context.Source.DateTimeProperty, NullableDateProperty = context.Source.DateTimeToNullable, DecProperty = context.Source.DecimalProperty, IntProperty = context.Source.IntegerProperty, StrProperty = context.Source.StringProperty, }; }
public IEvent Migrate() { var result = SimpleMapper.Map(this, new AppClientUpdatedV2()); return(result); }
private static void Map_is_called(SimpleMapper obj, LowerCaseContext context) { obj.Map(context.Source, context.Destination); }
private static ClaimTypeParam ToParam(ClaimTypeViewModel model) { return(SimpleMapper.From <ClaimTypeViewModel, ClaimTypeParam>(model)); }
private static void Map_is_called_with_custom_properties_to_link(SimpleMapper obj, AlternateNameContext context) { context.Source.Map() .WithLink<OutputAlternativeNamesClass>(x => x.BooleanProperty, x => x.BoolProperty) .WithLink(x => x.DateTimeProperty, x => x.DateProperty) .WithLink(x => x.DateTimeToNullable, x => x.NullableDateProperty) .WithLink(x => x.DecimalProperty, x => x.DecProperty) .WithLink(x => x.IntegerProperty, x => x.IntProperty) .WithLink(x => x.StringProperty, x => x.StrProperty) .To(context.Destination); }
public CreateComment ToCreateCommand(string commentsId) { return(SimpleMapper.Map(this, new CreateComment { CommentsId = commentsId })); }
private static void NHibernate_dynamic_proxy_as_destination(SimpleMapper obj, DynamicDestinationContext context) { var source = new ClassFiller<InputClass>().Source; context.Source = source; context.Expected = new OutputClass { BooleanProperty = source.BooleanProperty, IntegerProperty = source.IntegerProperty, StringProperty = source.StringProperty, DecimalProperty = source.DecimalProperty, DateTimeProperty = source.DateTimeProperty, DateTimeToNullable = source.DateTimeToNullable }; // ReSharper disable once RedundantCast context.Destination = new DynamicOutputClass(); }
public UpdateComment ToUpdateComment(string commentsId, string commentId) { return(SimpleMapper.Map(this, new UpdateComment { CommentsId = commentsId, CommentId = commentId })); }
private static void Source_passed_as_object_type(SimpleMapper obj, ObjectSourceContext context) { var source = new ClassFiller<InputClass>().Source; context.Source = source; context.Expected = new OutputClass { BooleanProperty = source.BooleanProperty, IntegerProperty = source.IntegerProperty, StringProperty = source.StringProperty, DecimalProperty = source.DecimalProperty, DateTimeProperty = source.DateTimeProperty, DateTimeToNullable = source.DateTimeToNullable }; context.Destination = new OutputClass(); }
public BulkUpdateContents ToCommand() { return(SimpleMapper.Map(this, new BulkUpdateContents())); }