예제 #1
0
        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());
        }
예제 #2
0
        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());
        }
예제 #3
0
 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();
 }
예제 #4
0
 public void Logout()
 {
     if (Client == null)
     {
         return;
     }
     Client.Token = null;
     Database.Clients.Update(IdentityMapper.Map(Client));
 }
예제 #5
0
        public void TestClassMapIdentityMappingWithMapAttribute()
        {
            // Act
            var actual   = IdentityMapper.Get <ClassMapperTestWithAttributesClass>();
            var expected = "Id";

            // Assert
            Assert.AreEqual(expected, actual.GetMappedName());
        }
예제 #6
0
        public ClientDTO Authenticate(string token)
        {
            var client = Database.Clients.FindByToken(token);

            Client = null;
            if (client != null)
            {
                Client = IdentityMapper.MapToDTO(client);
            }
            return(Client);
        }
예제 #7
0
        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();
        }
예제 #8
0
        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());
        }
예제 #9
0
        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());
        }
예제 #10
0
        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());
        }
예제 #11
0
 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();
 }
예제 #12
0
 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();
 }
예제 #13
0
        /// <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);
        }
예제 #14
0
 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();
 }
예제 #15
0
        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();
        }
예제 #16
0
        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));
            }
        }
예제 #17
0
        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());
        }
예제 #18
0
        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());
        }
예제 #19
0
 public void ThrowExceptionOnClassMapIdentityMappingThatIsAlreadyExisting()
 {
     // Setup
     IdentityMapper.Add <ClassMapperTestClass>(e => e.RowId);
 }
예제 #20
0
 public void ThrowExceptionOnIdentityMapperViaFieldThatIsIsMissing()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>(new Field("Whatever"));
 }
예제 #21
0
 public void ThrowExceptionOnIdentityMapperViaFieldThatIsAlreadyExisting()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>(new Field("ColumnInt"));
     IdentityMapper.Add <IdentityMapperTestClass>(new Field("ColumnString"));
 }
예제 #22
0
 public void ThrowExceptionOnIdentityMapperViaPropertyNameThatIsEmptySpaces()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>(propertyName: "  ");
 }
예제 #23
0
 public void ThrowExceptionOnIdentityMapperViaExpressionThatIsNull()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>(expression: null);
 }
예제 #24
0
 public void ThrowExceptionOnIdentityMapperViaFieldThatIsNull()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>(field: null);
 }
예제 #25
0
 public void ThrowExceptionOnIdentityMapperViaExpressionThatIsAlreadyExisting()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>(e => e.ColumnInt);
     IdentityMapper.Add <IdentityMapperTestClass>(e => e.ColumnString);
 }
예제 #26
0
 public Application(TokenClient tokenClient, IdentityMapper identityMapper)
 {
     this.tokenClient    = tokenClient;
     this.identityMapper = identityMapper;
 }
예제 #27
0
 public void Cleanup()
 {
     IdentityCache.Flush();
     IdentityMapper.Clear();
 }
예제 #28
0
 public void ThrowExceptionOnIdentityMapperViaFieldThatIsEmptySpaces()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>(field: new Field("  "));
 }
예제 #29
0
 public void ThrowExceptionOnIdentityMapperViaPropertyNameThatIsNull()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>(propertyName: null);
 }
예제 #30
0
 public void ThrowExceptionOnIdentityMapperViaPropertyNameThatIsMissing()
 {
     // Setup
     IdentityMapper.Add <IdentityMapperTestClass>("Whatever");
 }