Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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();
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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}"));
        }
Exemple #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);
        }
Exemple #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"));
        }
Exemple #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");
        }
Exemple #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");
        }