public void GetRegistered() {
     var innerMapper = new MReadOnlyMappingManager();
     innerMapper.getRegisteredTypes += () => new[] {typeof (TestDocument)};
     var mapper = new MemoizingMappingManager(innerMapper);
     var types = mapper.GetRegisteredTypes();
     Assert.AreEqual(1, types.Count);
     Assert.AreEqual(typeof (TestDocument), types.First());
     mapper.GetRegisteredTypes();
 }
 public void GetRegistered()
 {
     var innerMapper = MockRepository.GenerateMock<IReadOnlyMappingManager>();
     innerMapper.Expect(x => x.GetRegisteredTypes()).Repeat.Once().Return(new[] { typeof(TestDocument) });
     var mapper = new MemoizingMappingManager(innerMapper);
     var types = mapper.GetRegisteredTypes();
     Assert.AreEqual(1, types.Count);
     Assert.AreEqual(typeof (TestDocument), types.First());
     types = mapper.GetRegisteredTypes();
     innerMapper.VerifyAllExpectations();
 }
        public void GetUniqueKeyIsMemoized() {
            var innerMapper = new MReadOnlyMappingManager();
            innerMapper.getUniqueKey += t => {
	            Assert.AreEqual(typeof (TestDocument), t);
	            return new SolrFieldModel(property : typeof (TestDocument).GetProperty("Id"),
	                                      fieldName : "id");
            };
            var mapper = new MemoizingMappingManager(innerMapper);
            mapper.GetUniqueKey(typeof(TestDocument));
            mapper.GetUniqueKey(typeof(TestDocument));
            Assert.AreEqual(1, innerMapper.getUniqueKey.Calls);
        }
 public void CallsInnerJustOnce() {
     var innerMapper = new MReadOnlyMappingManager();
     innerMapper.getFields += t => {
         Assert.AreEqual(typeof (TestDocument), t);
         return new Dictionary<string, SolrFieldModel> {
             {"id", new SolrFieldModel (property : typeof (TestDocument).GetProperty("Id"), fieldName : "id")},
         };
     };
     var mapper = new MemoizingMappingManager(innerMapper);
     mapper.GetFields(typeof (TestDocument));
     mapper.GetFields(typeof (TestDocument));
     Assert.AreEqual(1, innerMapper.getFields.Calls);
 }
 public void GetUniqueKeyIsMemoized()
 {
     var mocks = new MockRepository();
     var innerMapper = mocks.StrictMock<IReadOnlyMappingManager>();
     With.Mocks(mocks)
         .Expecting(() => Expect.Call(innerMapper.GetUniqueKey(typeof (TestDocument)))
                              .Repeat.Once()
                              .Return(new SolrFieldModel { Property = typeof(TestDocument).GetProperty("Id"), FieldName = "id" }))
         .Verify(() => {
             var mapper = new MemoizingMappingManager(innerMapper);
             mapper.GetUniqueKey(typeof (TestDocument));
             mapper.GetUniqueKey(typeof(TestDocument));
         });
 }
 public void GetUniqueKeyIsMemoized()
 {
     var mocks = new MockRepository();
     var innerMapper = mocks.CreateMock<IReadOnlyMappingManager>();
     With.Mocks(mocks)
         .Expecting(() => Expect.Call(innerMapper.GetUniqueKey(typeof (TestDocument)))
                              .Repeat.Once()
                              .Return(new KeyValuePair<PropertyInfo, string>(typeof(TestDocument).GetProperty("Id"), "id")))
         .Verify(() => {
             var mapper = new MemoizingMappingManager(innerMapper);
             mapper.GetUniqueKey(typeof (TestDocument));
             mapper.GetUniqueKey(typeof(TestDocument));
         });
 }
 public void CallsInnerJustOnce()
 {
     var mocks = new MockRepository();
     var innerMapper = mocks.StrictMock<IReadOnlyMappingManager>();
     With.Mocks(mocks)
         .Expecting(() => Expect.Call(innerMapper.GetFields(typeof (TestDocument)))
                              .Repeat.Once()
                              .Return(new Dictionary<string,SolrFieldModel> {
                                  {"id", new SolrFieldModel { Property = typeof (TestDocument).GetProperty("Id"), FieldName = "id"}},
                              }))
         .Verify(() => {
             var mapper = new MemoizingMappingManager(innerMapper);
             mapper.GetFields(typeof (TestDocument));
             mapper.GetFields(typeof (TestDocument));
         });
 }
 public void CallsInnerJustOnce()
 {
     var mocks = new MockRepository();
     var innerMapper = mocks.CreateMock<IReadOnlyMappingManager>();
     With.Mocks(mocks)
         .Expecting(() => Expect.Call(innerMapper.GetFields(typeof (TestDocument)))
                              .Repeat.Once()
                              .Return(new Dictionary<PropertyInfo, string> {
                                  {typeof (TestDocument).GetProperty("Id"), "id"},
                              }))
         .Verify(() => {
             var mapper = new MemoizingMappingManager(innerMapper);
             mapper.GetFields(typeof (TestDocument));
             mapper.GetFields(typeof (TestDocument));
         });
 }
예제 #9
0
        private void RegisterInterfaces(ContainerBuilder builder)
        {
            var mapper = new MemoizingMappingManager(new AttributesMappingManager());
            builder.RegisterInstance(mapper).As<IReadOnlyMappingManager>();
            // builder.RegisterType<HttpRuntimeCache>().As<ISolrCache>();
            builder.RegisterType<DefaultDocumentVisitor>().As<ISolrDocumentPropertyVisitor>();
            builder.RegisterType<DefaultFieldParser>().As<ISolrFieldParser>();
            builder.RegisterGeneric(typeof (SolrDocumentActivator<>)).As(typeof (ISolrDocumentActivator<>));
            builder.RegisterGeneric(typeof (SolrDocumentResponseParser<>)).As(typeof (ISolrDocumentResponseParser<>));
            builder.RegisterType<DefaultFieldSerializer>().As<ISolrFieldSerializer>();
            builder.RegisterType<DefaultQuerySerializer>().As<ISolrQuerySerializer>();
            builder.RegisterType<DefaultFacetQuerySerializer>().As<ISolrFacetQuerySerializer>();
            foreach (var p in new[] {
                typeof (ResultsResponseParser<>),
                typeof (HeaderResponseParser<>),
                typeof (FacetsResponseParser<>),
                typeof (HighlightingResponseParser<>),
                typeof (MoreLikeThisResponseParser<>),
                typeof (SpellCheckResponseParser<>),
                typeof (StatsResponseParser<>),
                typeof (CollapseResponseParser<>),
                typeof (GroupingResponseParser<>),
                typeof (ClusterResponseParser<>),
                typeof (TermsResponseParser<>)
            })

                builder.RegisterGeneric(p).As(typeof (ISolrResponseParser<>));
            builder.RegisterType<HeaderResponseParser<string>>().As<ISolrHeaderResponseParser>();
            builder.RegisterType<ExtractResponseParser>().As<ISolrExtractResponseParser>();
            foreach (var p in new[] {
                typeof (MappedPropertiesIsInSolrSchemaRule),
                typeof (RequiredFieldsAreMappedRule),
                typeof (UniqueKeyMatchesMappingRule),
            })

                builder.RegisterType(p).As<IValidationRule>();
            builder.RegisterType<SolrSchemaParser>().As<ISolrSchemaParser>();
            builder.RegisterGeneric(typeof (SolrQueryResultParser<>)).As(typeof (ISolrQueryResultParser<>));
            builder.RegisterGeneric(typeof (SolrDocumentSerializer<>)).As(typeof (ISolrDocumentSerializer<>));
            builder.RegisterType<SolrDIHStatusParser>().As<ISolrDIHStatusParser>();
            builder.RegisterType<MappingValidator>().As<IMappingValidator>();
        }