Exemplo n.º 1
0
        public void RawKeyValuesMustBePopulated()
        {
            Action callWithNullRawKey = () => KeyFinder.FindAndUseKeysFromRelatedSegment(
                null,
                new List <IEdmStructuralProperty>()
            {
                ModelBuildingHelpers.BuildValidPrimitiveProperty(),
                ModelBuildingHelpers.BuildValidPrimitiveProperty(),
                ModelBuildingHelpers.BuildValidPrimitiveProperty()
            },
                ModelBuildingHelpers.BuildValidNavigationProperty(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >(),
                    ModelBuildingHelpers.BuildValidEntityType(),
                    null));

            Assert.Throws <ArgumentNullException>("rawKeyValuesFromUri", callWithNullRawKey);
        }
Exemplo n.º 2
0
        public void RawKeyValuesMustBePopulated()
        {
            Action callWithNullRawKey = () => KeyFinder.FindAndUseKeysFromRelatedSegment(
                null,
                new List <IEdmStructuralProperty>()
            {
                ModelBuildingHelpers.BuildValidPrimitiveProperty(),
                ModelBuildingHelpers.BuildValidPrimitiveProperty(),
                ModelBuildingHelpers.BuildValidPrimitiveProperty()
            },
                ModelBuildingHelpers.BuildValidNavigationProperty(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >(),
                    ModelBuildingHelpers.BuildValidEntityType(),
                    null));

            callWithNullRawKey.ShouldThrow <ArgumentNullException>().WithMessage("rawKeyValues", ComparisonMode.EquivalentSubstring);
        }
Exemplo n.º 3
0
        public void RawKeyWithMoreThanOnePositionalValueIsUnchanged()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("0,1", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                ModelBuildingHelpers.BuildValidPrimitiveProperty(),
                ModelBuildingHelpers.BuildValidPrimitiveProperty(),
                ModelBuildingHelpers.BuildValidPrimitiveProperty()
            },
                ModelBuildingHelpers.BuildValidNavigationProperty(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >(),
                    ModelBuildingHelpers.BuildValidEntityType(),
                    null));

            newKey.Should().Be(key);
        }
Exemplo n.º 4
0
        public void CurrentNavigaitionPropertyMustBePopulated()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("0,1", out key, false);
            Action callWithNullNavProp = () => KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                ModelBuildingHelpers.BuildValidPrimitiveProperty(),
                ModelBuildingHelpers.BuildValidPrimitiveProperty(),
                ModelBuildingHelpers.BuildValidPrimitiveProperty()
            },
                null,
                new KeySegment(
                    new List <KeyValuePair <string, object> >(),
                    ModelBuildingHelpers.BuildValidEntityType(),
                    null));

            callWithNullNavProp.ShouldThrow <ArgumentNullException>().WithMessage("currentNavigationProperty", ComparisonMode.EquivalentSubstring);
        }
Exemplo n.º 5
0
        public void IfNoReferentialIntegrityConstraintExistsOnPartnerKeyIsUnchanged()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetDogIdProp()
            },
                HardCodedTestModel.GetEmployeeOfficeDogNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            newKey.Should().Be(key);
        }
Exemplo n.º 6
0
        public void IfNoKeyExistsOnNavPropAndNoPartnerExistsKeyIsUnchanged()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetDogIdProp()
            },
                HardCodedTestModel.GetPersonMyDogNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            Assert.Same(key, newKey);
        }
Exemplo n.º 7
0
        public void IfValueExistsInTargetPropertiesAndNotExistingKeysItIsNotWritten()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("0", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId1Property(),
                HardCodedTestModel.GetLionId2Property(),
            },
                HardCodedTestModel.GetPersonMyLionsNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("Name", "Stuff")
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            newKey.Should().Be(key);
        }
Exemplo n.º 8
0
        public void AreValuesNamedIsAlwaysSet()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("6", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId1Property(),
                HardCodedTestModel.GetLionId2Property()
            },
                HardCodedTestModel.GetPersonMyLionsNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            newKey.AreValuesNamed.Should().BeTrue();
        }
Exemplo n.º 9
0
        public void PositionalValuesArrayIsCleared()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("6", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId1Property(),
                HardCodedTestModel.GetLionId2Property()
            },
                HardCodedTestModel.GetPersonMyLionsNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            Assert.Empty(newKey.PositionalValues);
        }
Exemplo n.º 10
0
        public void IfValueExistsinExistingKeysButNotTargetPropertiesItIsNotWritten()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("0", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId2Property(),
                HardCodedTestModel.GetLionAttackDatesProp()
            },
                HardCodedTestModel.GetPersonMyLionsNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            Assert.Same(key, newKey);
        }
Exemplo n.º 11
0
        public void LookForKeysOnBothCurrentNavPropAndPartnerIfItExistsWorksForTemplate()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("{6}", out key, true);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId1Property(),
                HardCodedTestModel.GetLionId2Property()
            },
                HardCodedTestModel.GetDogLionWhoAteMeNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            newKey.NamedValues.Should().Contain(new KeyValuePair <string, string>("ID1", "32"))
            .And.Contain(new KeyValuePair <string, string>("ID2", "{6}"));
        }
Exemplo n.º 12
0
        public void PositionalValueNotAddedIfMoreThanOneMissingValueExists()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("6", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId1Property(),
                HardCodedTestModel.GetLionId2Property(),
                HardCodedTestModel.GetLionAttackDatesProp()
            },
                HardCodedTestModel.GetPersonMyLionsNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            newKey.Should().Be(key);
        }
Exemplo n.º 13
0
        public void PositionalValueAddedAsMissingValueIfOnlyOneMissingValueExists()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("6", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId1Property(),
                HardCodedTestModel.GetLionId2Property()
            },
                HardCodedTestModel.GetPersonMyLionsNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            newKey.NamedValues.Should().Contain(new KeyValuePair <string, string>("ID1", "32"))
            .And.Contain(new KeyValuePair <string, string>("ID2", "6"));
        }
Exemplo n.º 14
0
        public void IfValueAlreadySpecifiedInRawKeyItIsNotOverwritten()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("ID1=6", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId1Property(),
                HardCodedTestModel.GetLionId2Property()
            },
                HardCodedTestModel.GetPersonMyLionsNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            newKey.NamedValues.Should().ContainKey("ID1")
            .And.ContainValue("6");
        }
Exemplo n.º 15
0
        public void LookForKeysOnBothCurrentNavPropAndPartnerIfItExists()
        {
            SegmentArgumentParser key;

            SegmentArgumentParser.TryParseKeysFromUri("6", out key, false);
            var newKey = KeyFinder.FindAndUseKeysFromRelatedSegment(
                key,
                new List <IEdmStructuralProperty>()
            {
                HardCodedTestModel.GetLionId1Property(),
                HardCodedTestModel.GetLionId2Property()
            },
                HardCodedTestModel.GetDogLionWhoAteMeNavProp(),
                new KeySegment(
                    new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("ID", 32)
            },
                    HardCodedTestModel.GetPersonType(),
                    HardCodedTestModel.GetPeopleSet()));

            Assert.Contains(newKey.NamedValues, kvp => kvp.Key == "ID1" && kvp.Value == "32");
            Assert.Contains(newKey.NamedValues, kvp => kvp.Key == "ID2" && kvp.Value == "6");
        }