Esempio n. 1
0
        public void InternalHasValidationResult_SingleKeywordAlreadyInCorrectFormat()
        {
            const string keyword      = "https://pid.bayer.com/kos/19050#11111111-1111-1111-1111-111111111111";
            const string type         = COLID.Graph.Metadata.Constants.Keyword.Type;
            var          entityResult = new BaseEntityResultCTO()
            {
                Entity = new BaseEntityResultDTO()
                {
                    Id = keyword
                }
            };

            string createdKeywordId;

            // Arrange
            _entityServiceMock.Setup(m => m.CheckIfPropertyValueExists(_labelUri, It.IsAny <string>(), type, out createdKeywordId)).Returns(true).Verifiable();
            _entityServiceMock.Setup(m => m.CreateEntity(It.IsAny <BaseEntityRequestDTO>())).ReturnsAsync(entityResult).Verifiable();

            var resource         = CreateResourceWithKeyword(keyword);
            var validationFacade = new EntityValidationFacade(ResourceCrudAction.Create, resource, null, null, _metadata, null);

            // Act
            _validator.HasValidationResult(validationFacade, GetKeywordProperty(resource));

            // Assert
            Assert.Contains(Graph.Metadata.Constants.Resource.Keyword, validationFacade.RequestResource.Properties);
            Assert.Single(validationFacade.RequestResource.Properties[Graph.Metadata.Constants.Resource.Keyword]);
            Assert.Equal(keyword, validationFacade.RequestResource.Properties[Graph.Metadata.Constants.Resource.Keyword].First());
            Assert.Equal(0, validationFacade.ValidationResults.Count);

            _entityServiceMock.Verify(m => m.CheckIfPropertyValueExists(_labelUri, keyword, type, out createdKeywordId), Times.Never);
            _entityServiceMock.Verify(m => m.CreateEntity(It.IsAny <BaseEntityRequestDTO>()), Times.Never);
        }
Esempio n. 2
0
        public void InternalHasValidationResult_OneKeywordNotUrlFormatAndNotExists(string validKeywordId, string invalidKeywordId)
        {
            const string type = COLID.Graph.Metadata.Constants.Keyword.Type;

            var keywordList = new List <dynamic>()
            {
                validKeywordId, invalidKeywordId
            };
            string       existingKeywordId = string.Empty;
            const bool   keywordExists     = false;
            const string createdKeywordId  = "https://pid.bayer.com/kos/19050#44444444-4444-4444-4444-444444444444";
            var          entityResult      = new BaseEntityResultCTO()
            {
                Entity = new BaseEntityResultDTO()
                {
                    Id = createdKeywordId
                }
            };

            // Arrange
            _entityServiceMock.Setup(m => m.CheckIfPropertyValueExists(_labelUri, It.IsAny <string>(), type, out existingKeywordId)).Returns(keywordExists).Verifiable();
            _entityServiceMock.Setup(m => m.CreateEntity(It.IsAny <BaseEntityRequestDTO>())).ReturnsAsync(entityResult).Verifiable();

            var resource         = CreateResourceWithKeyword(keywordList);
            var validationFacade = new EntityValidationFacade(ResourceCrudAction.Create, resource, null, null, _metadata, null);

            // Act
            _validator.HasValidationResult(validationFacade, GetKeywordProperty(resource));

            // Assert
            Assert.Contains(Graph.Metadata.Constants.Resource.Keyword, validationFacade.RequestResource.Properties);
            Assert.Equal(2, validationFacade.RequestResource.Properties[Graph.Metadata.Constants.Resource.Keyword].Count);
            Assert.Contains(validKeywordId, validationFacade.RequestResource.Properties[Graph.Metadata.Constants.Resource.Keyword]);
            Assert.Contains(createdKeywordId, validationFacade.RequestResource.Properties[Graph.Metadata.Constants.Resource.Keyword]);
            Assert.DoesNotContain(invalidKeywordId, validationFacade.RequestResource.Properties[Graph.Metadata.Constants.Resource.Keyword]);
            Assert.Equal(0, validationFacade.ValidationResults.Count);

            string val;

            _entityServiceMock.Verify(m => m.CheckIfPropertyValueExists(_labelUri, validKeywordId, type, out val), Times.Never);
            _entityServiceMock.Verify(m => m.CheckIfPropertyValueExists(_labelUri, invalidKeywordId, type, out existingKeywordId), Times.Once);
            _entityServiceMock.Verify(m => m.CreateEntity(It.IsAny <BaseEntityRequestDTO>()), Times.Once);
        }