Beispiel #1
0
        public void DeleteDatastoreObject(string store, TransportDataset dataset)
        {
            // TODO: Think about deleting with id
            var datasetController = new DatasetController();

            datasetController.DeleteDataset(dataset.GetDataset());
        }
Beispiel #2
0
        public void Should_AssignDatasetSchema_NoPermissions_Failure()
        {
            AssignDatasetSchemaUpdateViewModel data = Builder <AssignDatasetSchemaUpdateViewModel> .CreateNew().Build();

            _mockDatasetApiClient.Setup(x =>
                                        x.CreateRelationship(It.IsAny <CreateDefinitionSpecificationRelationshipModel>()))
            .ReturnsAsync(() => new ApiResponse <DefinitionSpecificationRelationship>(HttpStatusCode.OK,
                                                                                      Builder <DefinitionSpecificationRelationship> .CreateNew().Build()));
            _mockDatasetApiClient.Setup(x =>
                                        x.GetRelationshipBySpecificationIdAndName(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(() =>
                                                                                                                                          new ApiResponse <DefinitionSpecificationRelationship>(HttpStatusCode.OK,
                                                                                                                                                                                                Builder <DefinitionSpecificationRelationship> .CreateNew().Build())
                                                                                                                                          );
            _mockDatasetApiClient.Setup(x =>
                                        x.GetDatasetDefinitions()).ReturnsAsync(() =>
                                                                                new ApiResponse <IEnumerable <DatasetDefinition> >(HttpStatusCode.OK,
                                                                                                                                   Builder <DatasetDefinition> .CreateListOfSize(10).Build().AsEnumerable())
                                                                                );
            _mockSpecificationApiClient.Setup(x => x.GetSpecificationSummaryById(It.IsAny <string>()))
            .ReturnsAsync(() => new ApiResponse <SpecificationSummary>(HttpStatusCode.OK, Builder <SpecificationSummary> .CreateNew().Build())
                          );
            _mockAuthorisationHelper.Setup(x => x.DoesUserHavePermission(It.IsAny <ClaimsPrincipal>(),
                                                                         It.IsAny <string>(), It.IsAny <SpecificationActionTypes>())).ReturnsAsync(false);
            ; _sut = new DatasetController(_mockDatasetApiClient.Object, _mockLogger.Object, _mockMapper.Object, _mockSpecificationApiClient.Object, _mockAuthorisationHelper.Object);
            _mockMapper.Setup(x => x.Map <CreateDefinitionSpecificationRelationshipModel>(data))
            .Returns(Builder <CreateDefinitionSpecificationRelationshipModel> .CreateNew().Build());

            var actual = _sut.AssignDatasetSchema(data, "XZY098");

            actual.Should().NotBeNull();
            actual.Result.Should().BeOfType <ForbidResult>();
        }
Beispiel #3
0
 public DatasetControllerTests()
 {
     AutoMapperConfig.Initialize();
     _datasetMockRepository    = new Mock <IDatasetRepository>();
     _friendshipMockRepository = new Mock <IFriendshipRepository>();
     _datasetController        = new DatasetController(_friendshipMockRepository.Object, _datasetMockRepository.Object);
 }
Beispiel #4
0
        public TransportDataset GetDatastoreObject(string store, string number)
        {
            var datasetController = new DatasetController();
            var dataset           = datasetController.GetDataset(store, "PersonNumber", number).FirstOrDefault();

            return(new TransportPerson(dataset as Person));
        }
Beispiel #5
0
        public void DatasetControllerTest()
        {
            DatasetController controller = new DatasetController();

            if (controller == null)
            {
                Assert.Fail("Controller did not initialize");
            }
        }
Beispiel #6
0
        public void SetUp()
        {
            _specifications      = new Mock <ISpecificationsApiClient>();
            _authorisationHelper = new Mock <IAuthorizationHelper>();
            _logger    = Substitute.For <ILogger>();
            _apiClient = Substitute.For <IDatasetsApiClient>();

            _controller = CreateController(_apiClient, _logger);
        }
Beispiel #7
0
        public void SetUp()
        {
            _mockDatasetApiClient        = new Mock <IDatasetsApiClient>();
            _mockSpecificationsApiClient = new Mock <ISpecificationsApiClient>();
            _mockAuthorisationHelper     = new Mock <IAuthorizationHelper>();
            _mockLogger = new Mock <ILogger>();
            _mockMapper = new Mock <IMapper>();

            _sut = new DatasetController(_mockDatasetApiClient.Object, _mockLogger.Object, _mockMapper.Object, _mockSpecificationsApiClient.Object, _mockAuthorisationHelper.Object);
        }
        public async Task Get()
        {
            var controller = new DatasetController(datasetRepository);

            var result = await controller.Get();

            var okResult = Assert.IsType <OkObjectResult>(result);

            Assert.NotNull(okResult);
            Assert.Single((okResult.Value as List <Dataset>));
            Assert.Equal(200, okResult.StatusCode);
        }
Beispiel #9
0
        public void CalculatePriceDifferenceIncorrectRowItemsTest()
        {
            //Try an incorrect one with wrong row amount of items
            Dataset ds = new Dataset(2, 2);

            int[]   conversionFactors = new[] { 2 };
            int[]   itemFactor1       = new[] { 1, 1 };
            int[][] itemFactors       = new[] { itemFactor1 };

            //create the controller and pass everything to it
            DatasetController controller = new DatasetController();

            controller.CalculatePriceDifference(ds, conversionFactors, itemFactors);
        }
Beispiel #10
0
        public void CalculatePriceDifferenceIncorrectConversionTest()
        {
            //Now check with bad values for conversionFactors
            Dataset ds = new Dataset(2, 2);

            int[]   conversionFactors = new[] { 2, 2 };
            int[]   itemFactor1       = new[] { 1, 1 };
            int[][] itemFactors       = new[] { itemFactor1, itemFactor1 };

            //create the controller and pass everything to it
            DatasetController controller = new DatasetController();

            //if throws error it worked
            controller.CalculatePriceDifference(ds, conversionFactors, itemFactors);
        }
        public async Task Post()
        {
            var controller = new DatasetController(datasetRepository);

            var datasetModel = new DatasetModel()
            {
                Name = "dataset",
                File = GetMockFile(),
            };
            var result = await controller.Post(datasetModel);

            var okResult = Assert.IsType <OkResult>(result);

            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
        }
Beispiel #12
0
        public List <TransportDataset> GetDatastoreObjects(string store)
        {
            var datasetController = new DatasetController();
            var datasets          = datasetController.GetDatasets(store);

            var result = new List <TransportDataset>();

            foreach (var dataset in datasets)
            {
                if (dataset is Person)
                {
                    result.Add(new TransportPerson(dataset as Person));
                }
            }

            return(result);
        }
Beispiel #13
0
        public void CalculatePriceDifferenceTest()
        {
            //Try a correct one
            Dataset ds = new Dataset(2, 2);

            int[]   conversionFactors = { 2 };
            int[]   itemFactor1       = { 1, 1 };
            int[][] itemFactors       = { itemFactor1, itemFactor1 };

            //create the controller and pass everything to it
            DatasetController controller = new DatasetController();

            if (controller.CalculatePriceDifference(ds, conversionFactors, itemFactors) != 1)
            {
                Assert.Fail("Calculated price was expected to be 1");
            }
        }
Beispiel #14
0
 public static IMapper GetMapper(this DatasetController account)
 {
     return((new MapperConfiguration(cfg =>
     {
         cfg.CreateMap <FieldDTO, FieldViewModel>();
         cfg.CreateMap <FieldViewModel, FieldDTO>();
         cfg.CreateMap <FieldItemDTO, FieldItemViewModel>();
         cfg.CreateMap <FieldItemViewModel, FieldItemDTO>();
         cfg.CreateMap <DocumentFieldViewModel, DocumentFieldDTO>();
         cfg.CreateMap <DocumentFieldDTO, DocumentFieldViewModel>();
         cfg.CreateMap <DocumentDTO, DocumentViewModel>();
         cfg.CreateMap <DocumentViewModel, DocumentDTO>();
         cfg.CreateMap <SearchDTO, SearchViewModel>();
         cfg.CreateMap <SearchViewModel, SearchDTO>();
         cfg.CreateMap <UpdateDocumentDTO, DocumentViewModel>();
         cfg.CreateMap <DocumentViewModel, UpdateDocumentDTO>();
         cfg.CreateMap <FieldDatasetViewModel, DatasetFieldDTO>();
         cfg.CreateMap <DatasetFieldDTO, FieldDatasetViewModel>();
         cfg.CreateMap <DocumentDatasetFieldDTO, DocumentDatasetFieldViewModel>();
         cfg.CreateMap <DocumentDatasetFieldViewModel, DocumentDatasetFieldDTO>();
         cfg.CreateMap <DatasetDTO, DatasetViewModel>();
         cfg.CreateMap <DatasetViewModel, DatasetDTO>();
     })).CreateMapper());
 }
Beispiel #15
0
        public void SaveDatastoreObject(string store, TransportDataset dataset)
        {
            var datasetController = new DatasetController();

            datasetController.SaveDataset(dataset.GetDataset());
        }