Exemple #1
0
        public void Is_DataDefinition_Not_Valid()
        {
            // Arrange
            DataItemDefinitionModel dataItemDefinition =
                new DataItemDefinitionModel()
            {
                EncodingFormat = String.Empty,
                Culture        = String.Empty,
                ItemProperties = new List <DataItemPropertyModel>()
                {
                }
            };     // A data item definition with no properties

            // Act

            // Assert
            Assert.False(dataItemDefinition.IsValid); // Is this model not valid?
        }
Exemple #2
0
        public void Is_DataDefinition_Valid()
        {
            // Arrange
            DataItemDefinitionModel dataItemDefinition =
                new DataItemDefinitionModel()
            {
                EncodingFormat = "UTF8",
                Culture        = "en-GB",
                ItemProperties =
                    new List <DataItemPropertyModel>()
                {
                    new DataItemPropertyModel()
                    {
                    } // No need to set any values, just that there are some
                }
            };        // A data item definition with no properties

            // Act

            // Assert
            Assert.True(dataItemDefinition.IsValid); // Is this model valid?
        }
        public ApiResponse <DataItemDefinitionModel> Post([FromRoute] Guid packageId, [FromBody] DataItemDefinitionModel request)
        {
            // Create the response object
            ApiResponse <DataItemDefinitionModel> response = new ApiResponse <DataItemDefinitionModel>();

            // Map the model to a domain object type
            DataItemDefinition savedDataItemDefinition = mapper.Map <DataItemDefinition>(request);

            // Did the mapping work ok?
            if (savedDataItemDefinition != null)
            {
                // Did we find a package?
                Package package = SessionHandler.PackageRepository.Get(packageId);
                if (package != null)
                {
                    // Get the repository to save the package for us
                    savedDataItemDefinition = package.Save <DataItemDefinition>(savedDataItemDefinition);
                }

                // Saved ok?
                if (savedDataItemDefinition != null)
                {
                    // Map the data definition back to a model type and send it back to the user
                    response.Data = mapper.Map <DataItemDefinitionModel>(savedDataItemDefinition);
                }

                // Nothing died .. Success
                response.Success = true;
            }

            // Send the response back
            return(response);
        }
Exemple #4
0
        public ApiResponse <DataItemModel> Sample([FromRoute] Guid packageId, [FromRoute] Guid id, [FromBody] DataItemDefinitionModel request)
        {
            // Create the response object
            ApiResponse <DataItemModel> result = new ApiResponse <DataItemModel>()
            {
                Success = false
            };

            // Did we find a package?
            Package package = SessionHandler.PackageRepository.Get(packageId);

            if (package != null)
            {
                // Get the connection from the current package by the id given
                DataConnection connection = package.DataConnection(id);

                // Get the definition from the model provided
                if ((Boolean)(request?.IsValid))
                {
                    DataItemDefinition dataDefinition = mapper.Map <DataItemDefinition>(request);

                    // Get the sample result
                    result = SampleConnection(package, connection, dataDefinition, 10);
                }
                else
                {
                    result.Success = false;
                }
            }

            return(result);
        }