Example #1
0
        public void GetDTO_ObjectProp_Test()
        {
            var dataType = new ERModel.DataType()
            {
                Id       = new Guid("3FD6B018-C30A-470A-A4B5-0470366ACAB6"),
                TypeName = "INTEGER"
            };

            var attr = new ERModel.Attribute()
            {
                Id            = new Guid("1814BE78-4065-4F64-BD32-1A3FE588D3EA"),
                AttributeName = "FirstName",
                IsRequired    = true,

                DataType = dataType                 // !Important
            };

            var asm = new Assembler();

            RESTModel.Attribute dto = asm.GetDTO(attr) as RESTModel.Attribute;

            Assert.AreEqual(attr.Id, dto.Id);
            Assert.AreEqual(attr.AttributeName, dto.AttributeName);
            Assert.AreEqual(attr.IsRequired, dto.IsRequired);

            Assert.AreEqual(attr.DataType.Id, dto.DataTypeId);
        }
Example #2
0
        public void GetDTO_ParentProp_Test()
        {
            var entity = new ERModel.Entity()
            {
                Id         = new Guid("A81DD7C9-3B6B-41D7-95E9-72ECEE645F05"),
                SchemaName = "dbo",
                EntityName = "Author"
            };

            var dataType = new ERModel.DataType()
            {
                Id       = new Guid("3FD6B018-C30A-470A-A4B5-0470366ACAB6"),
                TypeName = "INTEGER"
            };

            var attr = new ERModel.Attribute()
            {
                Id            = new Guid("1814BE78-4065-4F64-BD32-1A3FE588D3EA"),
                AttributeName = "FirstName",
                IsRequired    = true,
                DataType      = dataType,

                Entity = entity                 // !important
            };

            var asm = new Assembler();

            RESTModel.Attribute dto = asm.GetDTO(attr) as RESTModel.Attribute;

            Assert.AreEqual(attr.Id, dto.Id);
            Assert.AreEqual(attr.AttributeName, dto.AttributeName);
            Assert.AreEqual(attr.IsRequired, dto.IsRequired);

            Assert.AreEqual(attr.Entity.Id, dto.EntityId);
        }
Example #3
0
        public static RESTModel.Attribute RetrieveAttribute(this ApiController apiController, HttpRequestMessage request, Guid id, Entity entity)
        {
            var getAttribute = new GetObject <RESTModel.Attribute>();

            RESTModel.Attribute attribute = getAttribute.Execute(id);

            if (attribute == null)
            {
                var response = request.CreateErrorResponse(HttpStatusCode.NotFound, String.Format("Attribute with id '{0}' does not exist", id));
                throw new HttpResponseException(response);
            }

            if (attribute.EntityId != entity.Id)
            {
                var response = request.CreateErrorResponse(
                    HttpStatusCode.BadRequest,
                    String.Format("Attribute with id '{0}' does not belong to the entity with id '{1}'", attribute.Id, entity.Id));
                throw new HttpResponseException(response);
            }

            return(attribute);
        }