Exemple #1
0
        public void GetFields_UnknownEnum_ReturnsEmptyString()
        {
            Assert.False(Enum.IsDefined(typeof(FieldResolutionMethod), Int32.MaxValue));

            IPartialResponseConfig partialReponseConfig = GetMockResponseConfig((FieldResolutionMethod)Int32.MaxValue);
            var reqContextMock = MockRepository.GenerateStub <IRequestContext>();

            Assert.Equal(string.Empty, FieldsRetriever.GetFields(reqContextMock, partialReponseConfig));
        }
Exemple #2
0
        public void FieldsFromQueryString_NoFields_ReturnsEmptyString()
        {
            var request = MockRepository.GenerateStub <IRequest>();

            Assert.Equal(
                string.Empty,
                FieldsRetriever.FieldsFromQueryString(
                    request, new DefaultPartialResponseConfig().FieldsQueryStringName));
        }
Exemple #3
0
        public void FieldsFromHeader_NoFields_ReturnsEmptyString()
        {
            var reqContextMock = MockRepository.GenerateStub <IRequestContext>();

            Assert.Equal(
                string.Empty,
                FieldsRetriever.FieldsFromHeader(
                    reqContextMock, new DefaultPartialResponseConfig().FieldsHeaderName));
        }
Exemple #4
0
        public void FieldsFromQueryString_EmptyFields_ReturnsEmptyString()
        {
            var             partialReponseConfig = new DefaultPartialResponseConfig();
            IRequestContext reqContextMock       = GenerateRequestMockWithQueryString(
                partialReponseConfig.FieldsQueryStringName, string.Empty);

            Assert.Equal(
                string.Empty,
                FieldsRetriever.FieldsFromQueryString(reqContextMock, partialReponseConfig.FieldsQueryStringName));
        }
Exemple #5
0
        public void FieldsFromHeader_EmptyFields_ReturnsEmptyString()
        {
            var partialReponseConfig = new DefaultPartialResponseConfig();
            var reqContextMock       = MockRepository.GenerateStub <IRequestContext>();

            reqContextMock.Expect(x => x.GetHeader(partialReponseConfig.FieldsHeaderName)).Return(string.Empty);

            Assert.Equal(
                string.Empty, FieldsRetriever.FieldsFromHeader(reqContextMock, partialReponseConfig.FieldsHeaderName));
        }
Exemple #6
0
        public void GetFields_HeaderOnlyQueryStringSet_ReturnsEmptyString()
        {
            IPartialResponseConfig partialReponseConfig = GetMockResponseConfig(FieldResolutionMethod.HeaderOnly);

            const string IdField = "id";
            var          request = MockRepository.GenerateStub <IRequest>();

            StubQueryString(request, partialReponseConfig.FieldsQueryStringName, IdField);

            Assert.Equal(string.Empty, FieldsRetriever.GetFields(request, partialReponseConfig));
        }
Exemple #7
0
        public void FieldsFromHeader_OneField_OneFieldReturned()
        {
            var          partialReponseConfig = new DefaultPartialResponseConfig();
            const string IdField        = "id";
            var          reqContextMock = MockRepository.GenerateStub <IRequestContext>();

            reqContextMock.Expect(x => x.GetHeader(partialReponseConfig.FieldsHeaderName)).Return(IdField);

            Assert.Equal(
                IdField, FieldsRetriever.FieldsFromHeader(reqContextMock, partialReponseConfig.FieldsHeaderName));
        }
Exemple #8
0
        public void FieldsFromHeader_OneField_OneFieldReturned()
        {
            var          partialReponseConfig = new DefaultPartialResponseConfig();
            const string IdField = "id";
            var          request = MockRepository.GenerateStub <IRequest>();

            StubHeaders(request, partialReponseConfig.FieldsHeaderName, IdField);

            Assert.Equal(
                IdField, FieldsRetriever.FieldsFromHeader(request, partialReponseConfig.FieldsHeaderName));
        }
Exemple #9
0
        public void FieldsFromQueryString_OneField_OneFieldReturned()
        {
            var             partialReponseConfig = new DefaultPartialResponseConfig();
            const string    IdField        = "id";
            IRequestContext reqContextMock =
                GenerateRequestMockWithQueryString(partialReponseConfig.FieldsQueryStringName, IdField);

            Assert.Equal(
                IdField,
                FieldsRetriever.FieldsFromQueryString(reqContextMock, partialReponseConfig.FieldsQueryStringName));
        }
Exemple #10
0
        public void FieldsFromQueryString_NoFields_ReturnsEmptyString()
        {
            var mockRequestContext = MockRepository.GenerateStub <IRequestContext>();
            var mockHttpRequest    = MockRepository.GenerateStub <IHttpRequest>();

            mockRequestContext.Expect(x => x.Get <IHttpRequest>()).Return(mockHttpRequest);

            Assert.Equal(
                string.Empty,
                FieldsRetriever.FieldsFromQueryString(
                    mockRequestContext, new DefaultPartialResponseConfig().FieldsQueryStringName));
        }
Exemple #11
0
        public void GetFields_HeaderOnlyOneFieldSet_RetrunsOneField()
        {
            IPartialResponseConfig partialReponseConfig = GetMockResponseConfig(FieldResolutionMethod.HeaderOnly);

            const string IdField = "id";
            var          request = MockRepository.GenerateStub <IRequest>();

            StubHeaders(request, partialReponseConfig.FieldsHeaderName, IdField);

            Assert.Equal(
                IdField,
                FieldsRetriever.GetFields(request, partialReponseConfig));
        }
Exemple #12
0
        public void GetFields_QueryStringOnlyHeaderSet_RetrunsEmptyString()
        {
            IPartialResponseConfig partialReponseConfig = GetMockResponseConfig(FieldResolutionMethod.QueryStringOnly);

            const string IdField          = "id";
            var          reqContextMock   = MockRepository.GenerateStub <IRequestContext>();
            var          httpRequesttMock = MockRepository.GenerateStub <IHttpRequest>();

            reqContextMock.Expect(x => x.Get <IHttpRequest>()).Return(httpRequesttMock);
            reqContextMock.Expect(x => x.GetHeader(partialReponseConfig.FieldsHeaderName)).Return(IdField);

            Assert.Equal(string.Empty, FieldsRetriever.GetFields(reqContextMock, partialReponseConfig));
        }
Exemple #13
0
        public void GetFields_HeaderOnlyOneFieldSet_RetrunsOneField()
        {
            IPartialResponseConfig partialReponseConfig = GetMockResponseConfig(FieldResolutionMethod.HeaderOnly);

            const string IdField        = "id";
            var          reqContextMock = MockRepository.GenerateStub <IRequestContext>();

            reqContextMock.Expect(x => x.GetHeader(partialReponseConfig.FieldsHeaderName)).Return(IdField);

            Assert.Equal(
                IdField,
                FieldsRetriever.GetFields(reqContextMock, partialReponseConfig));
        }
Exemple #14
0
        public void FieldsFromQueryString_TwoFields_TwoFieldReturned()
        {
            var          partialReponseConfig = new DefaultPartialResponseConfig();
            const string IdField   = "id";
            const string NameField = "name";
            var          request   = MockRepository.GenerateStub <IRequest>();

            StubQueryString(request, partialReponseConfig.FieldsQueryStringName, IdField, NameField);

            Assert.Equal(
                string.Join(FieldSelectorConstants.MultipleFieldSeparator.ToString(), IdField, NameField),
                FieldsRetriever.FieldsFromQueryString(request, partialReponseConfig.FieldsQueryStringName));
        }
Exemple #15
0
        public void FieldsFromHeader_TwoFields_TwoFieldReturned()
        {
            var          partialReponseConfig = new DefaultPartialResponseConfig();
            const string IdField            = "id";
            const string NameField          = "name";
            string       joinedHeaderValues = string.Join(",", IdField, NameField);
            var          reqContextMock     = MockRepository.GenerateStub <IRequestContext>();

            reqContextMock.Expect(x => x.GetHeader(partialReponseConfig.FieldsHeaderName)).Return(joinedHeaderValues);

            Assert.Equal(
                joinedHeaderValues,
                FieldsRetriever.FieldsFromHeader(reqContextMock, partialReponseConfig.FieldsHeaderName));
        }
Exemple #16
0
        public void GetFields_HeaderThenQueryStringBothSetDifferent_ReturnsHeaderFieldOnly()
        {
            IPartialResponseConfig partialReponseConfig =
                GetMockResponseConfig(FieldResolutionMethod.HeaderThenQueryString);

            const string IdField   = "id";
            const string NameField = "name";
            var          request   = MockRepository.GenerateStub <IRequest>();

            StubQueryString(request, partialReponseConfig.FieldsQueryStringName, IdField);
            StubHeaders(request, partialReponseConfig.FieldsHeaderName, NameField);

            Assert.Equal(
                NameField,
                FieldsRetriever.GetFields(request, partialReponseConfig));
        }
Exemple #17
0
        public void GetFields_HeaderOnlyQueryStringSet_ReturnsEmptyString()
        {
            IPartialResponseConfig partialReponseConfig = GetMockResponseConfig(FieldResolutionMethod.HeaderOnly);

            const string IdField          = "id";
            var          reqContextMock   = MockRepository.GenerateStub <IRequestContext>();
            var          httpRequesttMock = MockRepository.GenerateStub <IHttpRequest>();

            reqContextMock.Expect(x => x.Get <IHttpRequest>()).Return(httpRequesttMock);
            httpRequesttMock.Expect(x => x.QueryString)
            .Return(new NameValueCollection {
                { partialReponseConfig.FieldsQueryStringName, IdField }
            });

            Assert.Equal(string.Empty, FieldsRetriever.GetFields(reqContextMock, partialReponseConfig));
        }
Exemple #18
0
        public void GetFields_QueryStringAndHeaderBothSet_ReturnsAllFields()
        {
            IPartialResponseConfig partialReponseConfig =
                GetMockResponseConfig(FieldResolutionMethod.QueryStringAndHeader);

            const string IdField   = "id";
            const string NameField = "name";

            var request = MockRepository.GenerateStub <IRequest>();

            StubQueryString(request, partialReponseConfig.FieldsQueryStringName, IdField);
            StubHeaders(request, partialReponseConfig.FieldsHeaderName, NameField);

            Assert.Equal(
                string.Join(FieldSelectorConstants.MultipleFieldSeparator.ToString(), NameField, IdField),
                FieldsRetriever.GetFields(request, partialReponseConfig));
        }
Exemple #19
0
        public void GetFields_HeaderThenQueryStringBothSetDifferent_ReturnsHeaderFieldOnly()
        {
            IPartialResponseConfig partialReponseConfig =
                GetMockResponseConfig(FieldResolutionMethod.HeaderThenQueryString);

            const string IdField          = "id";
            const string NameField        = "name";
            var          reqContextMock   = MockRepository.GenerateStub <IRequestContext>();
            var          httpRequesttMock = MockRepository.GenerateStub <IHttpRequest>();

            reqContextMock.Expect(x => x.Get <IHttpRequest>()).Return(httpRequesttMock);
            httpRequesttMock.Expect(x => x.QueryString)
            .Return(new NameValueCollection {
                { partialReponseConfig.FieldsQueryStringName, IdField }
            });
            reqContextMock.Expect(x => x.GetHeader(partialReponseConfig.FieldsHeaderName)).Return(NameField);

            Assert.Equal(
                NameField,
                FieldsRetriever.GetFields(reqContextMock, partialReponseConfig));
        }
Exemple #20
0
        public void GetFields_QueryStringAndHeaderBothSet_ReturnsAllFields()
        {
            IPartialResponseConfig partialReponseConfig =
                GetMockResponseConfig(FieldResolutionMethod.QueryStringAndHeader);

            const string IdField   = "id";
            const string NameField = "name";

            var reqContextMock   = MockRepository.GenerateStub <IRequestContext>();
            var httpRequesttMock = MockRepository.GenerateStub <IHttpRequest>();

            reqContextMock.Expect(x => x.Get <IHttpRequest>()).Return(httpRequesttMock);
            httpRequesttMock.Expect(x => x.QueryString)
            .Return(new NameValueCollection {
                { partialReponseConfig.FieldsQueryStringName, IdField }
            });
            reqContextMock.Expect(x => x.GetHeader(partialReponseConfig.FieldsHeaderName)).Return(NameField);

            Assert.Equal(
                string.Join(FieldSelectorConstants.MultipleFieldSeparator.ToString(), NameField, IdField),
                FieldsRetriever.GetFields(reqContextMock, partialReponseConfig));
        }
Exemple #21
0
        public void GetFields_NoFields_ReturnsEmptyString()
        {
            var request = MockRepository.GenerateStub <IRequest>();

            Assert.Equal(string.Empty, FieldsRetriever.GetFields(request, new DefaultPartialResponseConfig()));
        }