public void TestIdentityMapperMappingViaExpressionForBaseProperty() { // Derived 1 // Setup IdentityMapper.Add <IdentityMapperTestDerivedClass1>(e => e.ColumnId); // Act var actual = IdentityMapper.Get <IdentityMapperTestDerivedClass1>(); var expected = "ColumnId"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); // Derived 2 // Setup IdentityMapper.Add <IdentityMapperTestDerivedClass2>(e => e.ColumnId); // Act actual = IdentityMapper.Get <IdentityMapperTestDerivedClass2>(); expected = "ColumnId"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); }
public async Task <Model.Identity> GetIdentityByID(Guid id) { var param = new DynamicParameters(); param.Add("@ID", id); var mapper = new IdentityMapper(); return((await SqlMapper.QueryAsync(_unitOfWork.Connection, "GetIdentityByID", new[] { typeof(Model.Identity), typeof(RequestType?), typeof(Cluster), typeof(string), typeof(Log) }, obj => { var identity = obj[0] as Model.Identity; var requestType = obj[1] as RequestType?; var cluster = obj[2] as Cluster; var node = obj[3] as string; var log = obj[4] as Log; return mapper.Map(identity, requestType, cluster, node, log); }, param, splitOn: "ID,RequestType,ClusterID,Node,LogID", commandType: CommandType.StoredProcedure, transaction: _unitOfWork.Transaction)).FirstOrDefault()); }
public LiquidService(string connectionString) : base(connectionString) { lineageMapper = new MapperConfiguration(cfg => { cfg.CreateMap <Lineage, LineageDTO>().BeforeMap((l, ldto) => { ldto.ModifiedByClient = IdentityMapper.GetClientById(l.ModifiedBy); ldto.CreatedByClient = IdentityMapper.GetClientById(l.CreatedBy); }); cfg.CreateMap <LineageDTO, Lineage>().BeforeMap((ldto, l) => { l.ModifiedBy = ldto.ModifiedByClient.Id; l.CreatedBy = ldto.CreatedByClient.Id; }); }).CreateMapper(); liquidMapper = new MapperConfiguration(cfg => { cfg.CreateMap <Liquid, LiquidDTO>().BeforeMap((l, ldto) => { ldto.ModifiedByClient = IdentityMapper.GetClientById(l.ModifiedBy); ldto.CreatedByClient = IdentityMapper.GetClientById(l.CreatedBy); ldto.Lineage = lineageMapper.Map <LineageDTO>(Database.Lineages.FindById(l.LineageId)); }); cfg.CreateMap <LiquidDTO, Liquid>().BeforeMap((ldto, l) => { l.ModifiedBy = ldto.ModifiedByClient.Id; l.CreatedBy = ldto.CreatedByClient.Id; l.LineageId = ldto.Lineage.Id; }); }).CreateMapper(); }
public void Logout() { if (Client == null) { return; } Client.Token = null; Database.Clients.Update(IdentityMapper.Map(Client)); }
public void TestClassMapIdentityMappingWithMapAttribute() { // Act var actual = IdentityMapper.Get <ClassMapperTestWithAttributesClass>(); var expected = "Id"; // Assert Assert.AreEqual(expected, actual.GetMappedName()); }
public ClientDTO Authenticate(string token) { var client = Database.Clients.FindByToken(token); Client = null; if (client != null) { Client = IdentityMapper.MapToDTO(client); } return(Client); }
public override void Given() { Instance = new IdentityMapper( new MockIdentityManagementService(new Dictionary <string, ITeamFoundationIdentity> { { "alias", new MockTeamFoundationIdentity("An Alias", "alias") }, { "other", new MockTeamFoundationIdentity("AnOther Alias", "other") } }), "tenant", "domain"); base.Given(); }
public void TestClassMapIdentityMappingOverride() { // Setup IdentityMapper.Add <ClassMapperTestClass>(e => e.RowId, true); // Act var actual = IdentityCache.Get <ClassMapperTestClass>(); var expected = "RowId"; // Assert Assert.AreEqual(expected, actual.GetMappedName()); }
public void TestIdentityMapperMappingViaExpression() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(e => e.ColumnInt); // Act var actual = IdentityMapper.Get <IdentityMapperTestClass>(); var expected = "ColumnInt"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); }
public void TestIdentityMapperMappingViaFieldOverride() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(new Field("ColumnInt")); IdentityMapper.Add <IdentityMapperTestClass>(new Field("ColumnString"), true); // Act var actual = IdentityMapper.Get <IdentityMapperTestClass>(); var expected = "ColumnString"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); }
public ProducerService(string connectionString) : base(connectionString) { producerMapper = new MapperConfiguration(cfg => { cfg.CreateMap <Producer, ProducerDTO>().AfterMap((p, pdto) => { pdto.ModifiedByClient = IdentityMapper.GetClientById(p.ModifiedBy); pdto.CreatedByClient = IdentityMapper.GetClientById(p.CreatedBy); }); cfg.CreateMap <ProducerDTO, Producer>().AfterMap((pdto, p) => { p.ModifiedBy = pdto.ModifiedByClient.Id; p.CreatedBy = pdto.CreatedByClient.Id; }); }).CreateMapper(); }
public ComponentTypeService(string connectionString) : base(connectionString) { componentTypeMapper = new MapperConfiguration(cfg => { cfg.CreateMap <ComponentType, ComponentTypeDTO>().AfterMap((c, cdto) => { cdto.ModifiedByClient = IdentityMapper.GetClientById(c.ModifiedBy); cdto.CreatedByClient = IdentityMapper.GetClientById(c.CreatedBy); }); cfg.CreateMap <ComponentTypeDTO, ComponentType>().AfterMap((cdto, c) => { c.ModifiedBy = cdto.ModifiedByClient.Id; c.CreatedBy = cdto.CreatedByClient.Id; }); }).CreateMapper(); }
/// <summary> /// Resolves the identity <see cref="ClassProperty"/> of the data entity type. /// </summary> /// <param name="entityType">The type of the data entity.</param> /// <returns>The instance of the identity <see cref="ClassProperty"/> object.</returns> public ClassProperty Resolve(Type entityType) { var properties = PropertyCache.Get(entityType); // Get the first entry with Identity attribute var property = properties? .FirstOrDefault(p => p.GetIdentityAttribute() != null); // Get from the implicit mapping if (property == null) { property = IdentityMapper.Get(entityType); } // Return the instance return(property); }
public LiquidComponentService(string connection) : base(connection) { componentTypeMapper = new MapperConfiguration(cfg => { cfg.CreateMap <ComponentType, ComponentTypeDTO>().AfterMap((c, cdto) => { cdto.ModifiedByClient = IdentityMapper.GetClientById(c.ModifiedBy); cdto.CreatedByClient = IdentityMapper.GetClientById(c.CreatedBy); }); cfg.CreateMap <ComponentTypeDTO, ComponentType>().AfterMap((cdto, c) => { c.ModifiedBy = cdto.ModifiedByClient.Id; c.CreatedBy = cdto.CreatedByClient.Id; }); }).CreateMapper(); producerMapper = new MapperConfiguration(cfg => { cfg.CreateMap <Producer, ProducerDTO>().AfterMap((p, pdto) => { pdto.ModifiedByClient = IdentityMapper.GetClientById(p.ModifiedBy); pdto.CreatedByClient = IdentityMapper.GetClientById(p.CreatedBy); }); cfg.CreateMap <ProducerDTO, Producer>().AfterMap((pdto, p) => { p.ModifiedBy = pdto.ModifiedByClient.Id; p.CreatedBy = pdto.CreatedByClient.Id; }); }).CreateMapper(); componentMapper = new MapperConfiguration(cfg => { cfg.CreateMap <LiquidComponent, ComponentDTO>().AfterMap((c, cdto) => { cdto.ModifiedByClient = IdentityMapper.GetClientById(c.ModifiedBy); cdto.CreatedByClient = IdentityMapper.GetClientById(c.CreatedBy); cdto.Producer = producerMapper.Map <ProducerDTO>(Database.Lineages.FindById(c.ProducerId)); cdto.ComponentType = componentTypeMapper.Map <ComponentTypeDTO>(Database.Lineages.FindById(c.TypeId)); }); cfg.CreateMap <ComponentDTO, LiquidComponent>().AfterMap((cdto, c) => { c.ModifiedBy = cdto.ModifiedByClient.Id; c.CreatedBy = cdto.CreatedByClient.Id; c.ProducerId = cdto.Producer.Id; c.TypeId = cdto.ComponentType.Id; }); }).CreateMapper(); }
public void Cleanup() { ClassMapper.Clear(); PropertyMapper.Clear(); PrimaryMapper.Clear(); IdentityMapper.Clear(); TypeMapper.Clear(); //PropertyHandlerMapper.Clear(); PropertyValueAttributeMapper.Clear(); ClassMappedNameCache.Flush(); PropertyCache.Flush(); PrimaryCache.Flush(); IdentityCache.Flush(); TypeMapCache.Flush(); //PropertyHandlerMapper.Clear(); PropertyValueAttributeCache.Flush(); }
private void Login(Client client) { if (client == null) { Client = null; return; } var now = DateTime.Now; Client = IdentityMapper.MapToDTO(client); Client.Token = CreateToken(Client, now.ToLongTimeString() + now.ToLongDateString()); Client.LoginDate = now; if (Database.Clients.FindById(client.Id) == null) { Database.Clients.Insert(IdentityMapper.Map(Client)); } else { Database.Clients.Update(IdentityMapper.Map(Client)); } }
public void TestIdentityMapperMappingViaFieldWithMapAttribute() { // Setup IdentityMapper.Add <IdentityMapperTestWithAttributeClass>(new Field("ColumnInt")); // Act var actual = IdentityMapper.Get <IdentityMapperTestWithAttributeClass>(); var expected = "ColumnInt"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); // Act actual = IdentityCache.Get <IdentityMapperTestWithAttributeClass>(); expected = "ColumnString"; // Assert Assert.IsTrue(actual?.IsIdentity() == true); Assert.AreEqual(expected, actual?.GetMappedName()); }
public async Task <List <Model.Identity> > GetAllIdentityDetails(long id) { var param = new DynamicParameters(); param.Add("@ID", id); var mapper = new IdentityMapper(); return((await SqlMapper.QueryAsync( _unitOfWork.Connection, "GetAllIdentity", new[] { typeof(Model.Identity) }, obj => { var A = obj[0] as Model.Identity; return mapper.Map(A); }, param, commandType: CommandType.StoredProcedure, transaction: _unitOfWork.Transaction)).ToList()); }
public void ThrowExceptionOnClassMapIdentityMappingThatIsAlreadyExisting() { // Setup IdentityMapper.Add <ClassMapperTestClass>(e => e.RowId); }
public void ThrowExceptionOnIdentityMapperViaFieldThatIsIsMissing() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(new Field("Whatever")); }
public void ThrowExceptionOnIdentityMapperViaFieldThatIsAlreadyExisting() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(new Field("ColumnInt")); IdentityMapper.Add <IdentityMapperTestClass>(new Field("ColumnString")); }
public void ThrowExceptionOnIdentityMapperViaPropertyNameThatIsEmptySpaces() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(propertyName: " "); }
public void ThrowExceptionOnIdentityMapperViaExpressionThatIsNull() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(expression: null); }
public void ThrowExceptionOnIdentityMapperViaFieldThatIsNull() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(field: null); }
public void ThrowExceptionOnIdentityMapperViaExpressionThatIsAlreadyExisting() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(e => e.ColumnInt); IdentityMapper.Add <IdentityMapperTestClass>(e => e.ColumnString); }
public Application(TokenClient tokenClient, IdentityMapper identityMapper) { this.tokenClient = tokenClient; this.identityMapper = identityMapper; }
public void Cleanup() { IdentityCache.Flush(); IdentityMapper.Clear(); }
public void ThrowExceptionOnIdentityMapperViaFieldThatIsEmptySpaces() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(field: new Field(" ")); }
public void ThrowExceptionOnIdentityMapperViaPropertyNameThatIsNull() { // Setup IdentityMapper.Add <IdentityMapperTestClass>(propertyName: null); }
public void ThrowExceptionOnIdentityMapperViaPropertyNameThatIsMissing() { // Setup IdentityMapper.Add <IdentityMapperTestClass>("Whatever"); }