├── .gitignore ├── BDD.xml ├── Relax.sln ├── demo ├── Relax.Overflow │ ├── Comment.cs │ ├── Post.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Relax.Overflow.csproj │ └── Users.cs └── RelaxDemo │ ├── BulkDataLoader.cs │ ├── BulkDataPersister.cs │ ├── ChangeWatcher.cs │ ├── DatabaseDeleter.cs │ ├── DocumentRetriever.cs │ ├── DocumentSaver.cs │ ├── LuceneSearchClient.cs │ ├── PagingDataLoader.cs │ ├── Program.cs │ ├── Program.cs.orig │ ├── Properties │ └── AssemblyInfo.cs │ ├── RelaxDemo.csproj │ ├── RelaxDemoService.cs │ ├── TestDocument.cs │ └── app.config ├── lib ├── MSpec │ ├── CommandLine.dll │ ├── CommandLine.xml │ ├── License.txt │ ├── Machine.Specifications.TDNetRunner.dll │ ├── Machine.Specifications.TDNetRunner.pdb │ ├── Machine.Specifications.dll │ ├── Machine.Specifications.dll.tdnet │ ├── Machine.Specifications.pdb │ ├── Newtonsoft.Json.dll │ ├── Spark.dll │ ├── Spark.pdb │ ├── TestDriven.Framework.dll │ ├── ThoughtWorks.Selenium.Core.dll │ ├── ThoughtWorks.Selenium.Core.pdb │ ├── mspec-clr4.exe │ ├── mspec-clr4.pdb │ ├── mspec-x86-clr4.exe │ ├── mspec-x86-clr4.pdb │ ├── mspec-x86.exe │ ├── mspec-x86.pdb │ ├── mspec.exe │ └── mspec.pdb ├── Moq.dll ├── Reactive │ ├── System.CoreEx.dll │ ├── System.Interactive.dll │ └── System.Reactive.dll ├── Symbiote.Core.XML ├── Symbiote.Core.dll └── Symbiote.Core.pdb ├── src └── Relax │ ├── ChangeRecord.cs │ ├── Config │ ├── CouchConfiguration.cs │ ├── CouchConfigurationException.cs │ ├── CouchConfigurator.cs │ ├── CouchDependencies.cs │ ├── ICouchConfiguration.cs │ └── RelaxConfigurationException.cs │ ├── CouchAssimilation.cs │ ├── CouchDocument.cs │ ├── CouchInit.cs │ ├── ICouchDocument.cs │ ├── ICouchServer.cs │ ├── IDocumentRepository.cs │ ├── IRelaxQueryService.cs │ ├── IResolveDatabaseNames.cs │ ├── Impl │ ├── Cache │ │ ├── CacheKeyBuilder.cs │ │ ├── CouchCacheProvider.cs │ │ ├── DefaultKeyAssociationManager.cs │ │ ├── ICacheKeyBuilder.cs │ │ ├── ICouchCacheProvider.cs │ │ └── IKeyAssociationManager.cs │ ├── Commands │ │ ├── BaseCouchCommand.cs │ │ ├── BaseSaveDocumentCollection.cs │ │ ├── ChangeStreamCommand.cs │ │ ├── CommandResult.cs │ │ ├── CouchCommandFactory.cs │ │ ├── CouchQueryCommand.cs │ │ ├── DeleteAttachmentCommand.cs │ │ ├── DeleteDocumentCommand.cs │ │ ├── GetAllDocumentsCommand.cs │ │ ├── GetAttachmentCommand.cs │ │ ├── GetDocumentCommand.cs │ │ ├── GetDocumentsByIdsCommand.cs │ │ ├── GetDocumentsInRangeCommand.cs │ │ ├── GetDocumentsPagedCommand.cs │ │ ├── GetFromViewCommand.cs │ │ ├── ISaveDocument.cs │ │ ├── ISaveDocuments.cs │ │ ├── SaveAttachmentCommand.cs │ │ ├── SaveDocumentCommand.cs │ │ ├── SaveDocumentListCommand.cs │ │ ├── ServerCommand.cs │ │ └── ViewQuery.cs │ ├── CouchDbServer.cs │ ├── CouchProxy.cs │ ├── CouchUtility.cs │ ├── DocumentUtility.cs │ ├── Feed.cs │ ├── Http │ │ ├── CouchURI.cs │ │ ├── HttpAction.cs │ │ └── IHttpAction.cs │ ├── IDocumentSearchProvider.cs │ ├── Json │ │ ├── BulkPersist.cs │ │ ├── DesignDocumentFilter.cs │ │ ├── JsonUrlEncoder.cs │ │ ├── KeyList.cs │ │ ├── ReplicationCommand.cs │ │ ├── SaveResponse.cs │ │ ├── ViewResult.cs │ │ └── ViewRow.cs │ ├── Model │ │ ├── BaseDocument.cs │ │ ├── ComplexCouchDocument.cs │ │ ├── DesignDocument.cs │ │ ├── DesignView.cs │ │ ├── DocumentMetadata.cs │ │ ├── IHaveAttachments.cs │ │ ├── IHaveDocumentId.cs │ │ ├── IHaveDocumentRevision.cs │ │ └── JSONDocument.cs │ ├── Persistence │ │ ├── KeyValueStore.cs │ │ └── SimpleRepository.cs │ ├── Repository │ │ ├── BaseDocumentRepository.cs │ │ ├── CachedDocumentRepository.cs │ │ └── DocumentRepository.cs │ ├── Serialization │ │ ├── DocumentContractResolver.cs │ │ ├── DocumentConventions.cs │ │ ├── DocumentMetadataProvider.cs │ │ ├── IProvideDocumentMetadata.cs │ │ ├── ISerializationProvider.cs │ │ ├── IValueProviderCache.cs │ │ ├── MetadataValueProvider.cs │ │ ├── MetadataValueProviderCache.cs │ │ └── SerializationProvider.cs │ └── UtilityExtensions.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Relax.csproj │ └── RelaxException.cs └── tests ├── Assimilation ├── when_assimilating_with_caching.cs └── when_assimilating_without_caching.cs ├── Caching ├── when_adding_cross_reference.cs ├── when_associating_keys.cs ├── when_deleting_item_by_key.cs ├── when_deleting_item_by_key_and_rev.cs ├── when_getting_cache_keys.cs ├── when_getting_cache_keys_with_default_cache_key_builder.cs ├── when_getting_documents_by_range_cached.cs ├── when_getting_documents_by_range_uncached.cs ├── when_getting_entire_list_cached.cs ├── when_getting_entire_list_uncached.cs ├── when_getting_item_by_key_and_rev_not_cached.cs ├── when_getting_item_by_key_and_rev_when_cached.cs ├── when_getting_item_by_key_not_cached.cs ├── when_getting_item_by_key_when_cached.cs ├── when_getting_paged_list_cached.cs ├── when_getting_paged_list_uncached.cs ├── when_invalidating_item.cs ├── when_saving_a_collection.cs ├── when_saving_a_document.cs ├── with_cache_provider.cs ├── with_caching_provider.cs └── with_couch_cache_provider.cs ├── Commands ├── DeletingAttachments │ ├── when_deleting_attachment.cs │ └── with_delete_attachment_command.cs ├── FromView │ ├── when_getting_from_view.cs │ └── with_get_from_view_command.cs ├── GetCommand │ ├── when_getting_all_documents.cs │ ├── when_getting_all_documents_by_ids.cs │ ├── when_getting_all_documents_paged.cs │ ├── when_getting_doc_by_id.cs │ ├── when_getting_doc_by_id_and_rev.cs │ ├── when_getting_documents_by_key_range.cs │ ├── with_get_all_docs.cs │ ├── with_get_all_docs_by_ids.cs │ ├── with_get_all_docs_paged.cs │ ├── with_get_doc_by_id_and_rev_setup.cs │ ├── with_get_doc_by_id_setup.cs │ └── with_get_doc_by_range.cs ├── GettingAttachments │ ├── when_getting_attachment.cs │ └── with_get_attachment_command.cs ├── GettingDocuments │ ├── when_getting_all_documents.cs │ ├── when_getting_all_documents_by_ids.cs │ ├── when_getting_all_documents_paged.cs │ ├── when_getting_all_pocos_by_ids.cs │ ├── when_getting_all_pocos_by_ids_timed.cs │ ├── when_getting_doc_by_id.cs │ ├── when_getting_doc_by_id_and_rev.cs │ ├── when_getting_doc_by_id_timed.cs │ ├── when_getting_documents_by_key_range.cs │ ├── when_getting_poco_by_id.cs │ ├── when_getting_poco_by_id_timed.cs │ ├── with_get_all_docs.cs │ ├── with_get_all_docs_by_ids.cs │ ├── with_get_all_docs_paged.cs │ ├── with_get_all_pocos_by_ids.cs │ ├── with_get_doc_by_id_and_rev_setup.cs │ ├── with_get_doc_by_id_setup.cs │ ├── with_get_doc_by_range.cs │ └── with_get_poco_by_id_setup.cs ├── ParentDoc.cs ├── SaveCommand │ ├── when_persisting_list_with_breaking_documents.cs │ ├── when_persisting_list_without_breaking_documents.cs │ ├── when_saving_list_to_database.cs │ ├── when_saving_poco_list_to_database.cs │ ├── when_saving_poco_to_database.cs │ ├── when_scrubbing_bulk_persist_type_tokens.cs │ ├── with_document_list.cs │ ├── with_nested_document_list.cs │ ├── with_poco_list.cs │ ├── with_poco_list_persistence.cs │ ├── with_poco_persistence.cs │ ├── with_serialized_bulk_persist.cs │ └── with_single_parent_document.cs ├── SavingAttachments │ ├── when_saving_document_attachment.cs │ └── with_save_attachment_command.cs ├── TestDoc.cs ├── with_command_factory.cs ├── with_configuration.cs └── with_mock_http_action.cs ├── Configuration ├── TestDatabaseResolver.cs ├── when_providing_custom_configuration.cs ├── when_using_cache_without_a_cache_provider.cs ├── when_using_caching_with_expiration_date.cs ├── when_using_caching_with_no_expiration.cs ├── when_using_caching_with_time_limit.cs ├── when_using_defaults.cs ├── with_couch_configuration.cs └── with_couch_configurator.cs ├── Document ├── Driver.cs ├── Person.cs ├── when_serializing_design_document.cs ├── when_using_custom_complex_key.cs ├── when_using_custom_key.cs ├── when_working_with_complex_couch_document.cs ├── when_working_with_simple_couch_document.cs ├── with_custom_document_complex_key.cs ├── with_custom_document_simple_key.cs └── with_design_document.cs ├── Mocks └── with_mock_repository.cs ├── Properties └── AssemblyInfo.cs ├── Relax.Lucene.Tests ├── Car.cs ├── DomainHelper.cs ├── Person.cs ├── Properties │ └── AssemblyInfo.cs ├── Relax.Lucene.Tests.csproj ├── when_searching_against_family.cs ├── with_domain_model.cs ├── with_indexed_people.cs └── with_lucene.cs ├── Relax.Tests.csproj ├── Repository ├── when_deleting_attachment.cs ├── when_deleting_document.cs ├── when_deleting_document_by_id.cs ├── when_deleting_document_by_id_and_rev.cs ├── when_getting_a_document_by_key.cs ├── when_getting_a_document_by_key_and_rev.cs ├── when_getting_all_docuemnts.cs ├── when_getting_all_docuemnts_with_paging.cs ├── when_getting_all_documents.cs ├── when_getting_all_documents_with_paging.cs ├── when_getting_attachment.cs ├── when_getting_documents_by_id.cs ├── when_getting_documents_by_range.cs ├── when_getting_from_view.cs ├── when_saving_a_document.cs ├── when_saving_documents.cs ├── with_delete_attachment_command.cs ├── with_delete_document_command.cs ├── with_delete_document_command_by_id.cs ├── with_delete_document_command_by_id_and_rev.cs ├── with_document_repository.cs ├── with_from_view_command.cs ├── with_get_all_documents_command.cs ├── with_get_all_documents_paged_command.cs ├── with_get_attachment.cs ├── with_get_document_by_key_and_rev_command.cs ├── with_get_document_by_key_command.cs ├── with_get_documents_by_keys.cs ├── with_get_documents_by_range.cs ├── with_save_model_command.cs ├── with_save_models_command.cs └── with_test_document.cs ├── Serialization ├── ComplexDocument.cs ├── Filtering │ ├── ClassA.cs │ ├── ClassB.cs │ ├── ClassC.cs │ ├── ClassD.cs │ ├── ClassE.cs │ ├── ClassF.cs │ ├── when_serializing_complex_graph.cs │ └── with_test_graph.cs ├── Test.cs ├── when_deserializing_complex_document.cs ├── when_deserializing_complex_view.cs ├── when_deserializing_view_result_and_document_excluded.cs ├── when_deserializing_view_result_with_documents_included.cs ├── when_serializing_bulk_insert.cs ├── when_trying_custom_serializer.cs ├── with_assimilation.cs ├── with_bulk_insert.cs ├── with_complex_document.cs ├── with_complex_view_result.cs ├── with_single_document.cs ├── with_view_result_and_documents_included.cs └── with_view_result_and_no_documents.cs ├── Server ├── when_checking_database_existence.cs ├── when_cleaning_up_views.cs ├── when_compacting_db.cs ├── when_compacting_view.cs ├── when_copying_from_any_database.cs ├── when_copying_from_local_database.cs ├── when_creating_database.cs ├── when_deleteing_database.cs ├── when_getting_list_of_databases.cs ├── when_starting_replication_from_any_database.cs ├── when_starting_replication_from_local_database.cs ├── with_check_database_exists_command.cs ├── with_continuous_replication.cs ├── with_copy_replication.cs ├── with_couch_server.cs ├── with_create_database_command.cs ├── with_create_delete_database_command.cs ├── with_db_compaction.cs ├── with_list_databases_command.cs ├── with_view_cleanup_command.cs └── with_view_compaction.cs ├── SimpleDocument.cs ├── TestDocument.cs ├── URI ├── Encoding │ ├── UrlEncoder.cs │ ├── when_encoding_json_for_url.cs │ └── with_test_json.cs ├── ViewQuery │ ├── when_testing_view_query_scenario_1.cs │ ├── when_testing_view_query_scenario_2.cs │ └── with_couch_uri.cs ├── when_bulk_inserting.cs ├── when_cleaning_up_view.cs ├── when_compacting_database.cs ├── when_compacting_view.cs ├── when_creating_baseline_uri.cs ├── when_getting_attachment_including_revision.cs ├── when_grouping.cs ├── when_grouping_with_level.cs ├── when_inclusive_end_in_view.cs ├── when_retrieving_by_key.cs ├── when_retrieving_by_key_and_revision.cs ├── when_retrieving_by_list_all.cs ├── when_retrieving_by_list_all_with_descending.cs ├── when_retrieving_by_list_all_with_descending_and_limit.cs ├── when_retrieving_by_list_all_with_descending_and_skip.cs ├── when_retrieving_by_named_list_with_descending_and_skip.cs ├── when_retrieving_by_range.cs ├── when_retrieving_by_view.cs ├── when_retrieving_changes_continuously.cs ├── when_retrieving_changes_continuously_including_documents.cs ├── when_retrieving_changes_via_longpolling.cs ├── when_retrieving_design_document.cs ├── when_setting_up_replication.cs ├── when_stale_records_are_ok.cs ├── when_turning_off_reduce.cs ├── when_using_attachments.cs ├── when_using_end_key_only.cs ├── when_using_start_key_only.cs ├── with_basic_uri.cs └── with_basic_uri_without_db.cs ├── ViewFilter ├── Request.cs ├── when_filtering_design_documents_from_results.cs └── with_test_json.cs └── with_configuration.cs /.gitignore: -------------------------------------------------------------------------------- 1 | _ReSharper.* 2 | Debug* 3 | Release* 4 | bin* 5 | obj* 6 | *.cache 7 | *.user 8 | *.suo 9 | *~HEAD -------------------------------------------------------------------------------- /demo/Relax.Overflow/Comment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Relax.Overflow 4 | { 5 | public class Comment 6 | { 7 | public virtual long Id { get; set; } 8 | public virtual long PostId { get; set; } 9 | public virtual decimal Score { get; set; } 10 | public virtual string Text { get; set; } 11 | public virtual DateTime CreationDate { get; set; } 12 | public virtual long UserId { get; set; } 13 | } 14 | } -------------------------------------------------------------------------------- /demo/Relax.Overflow/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Relax.Overflow")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Relax.Overflow")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("70d6b6b8-f85b-48e8-88d0-8821f27892ad")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /demo/Relax.Overflow/Users.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Relax.Overflow 4 | { 5 | public class Users 6 | { 7 | public virtual long Id { get; set; } 8 | public virtual decimal Reputation { get; set; } 9 | public virtual DateTime CreationDate { get; set; } 10 | public virtual string DisplayName { get; set; } 11 | public virtual string EmailHash { get; set; } 12 | public virtual DateTime LastAccessDate { get; set; } 13 | public virtual string WebSiteUrl { get; set; } 14 | public virtual string Location { get; set; } 15 | public virtual long Age { get; set; } 16 | public virtual string AboutMe { get; set; } 17 | public virtual long Views { get; set; } 18 | public virtual long UpVotes { get; set; } 19 | public virtual long DownVotes { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/BulkDataLoader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Relax; 3 | 4 | namespace RelaxDemo 5 | { 6 | public class BulkDataLoader 7 | { 8 | private IDocumentRepository _couch; 9 | 10 | public IList GetAllDocuments() 11 | { 12 | return _couch.GetAll(); 13 | } 14 | 15 | public BulkDataLoader(IDocumentRepository couch) 16 | { 17 | _couch = couch; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/BulkDataPersister.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Relax; 3 | 4 | namespace RelaxDemo 5 | { 6 | public class BulkDataPersister 7 | { 8 | private IDocumentRepository _couch; 9 | 10 | private TestDocument[] documents = new TestDocument[] 11 | { 12 | new TestDocument("Document 1"), 13 | new TestDocument("Document 2"), 14 | new TestDocument("Document 3"), 15 | new TestDocument("Document 4"), 16 | new TestDocument("Document 5"), 17 | new TestDocument("Document 6"), 18 | new TestDocument("Document 7"), 19 | new TestDocument("Document 8"), 20 | new TestDocument("Document 9"), 21 | new TestDocument("Document 10"), 22 | }; 23 | 24 | public void SaveDocuments() 25 | { 26 | _couch.SaveAll(documents); 27 | } 28 | 29 | public BulkDataPersister(IDocumentRepository couch) 30 | { 31 | _couch = couch; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/ChangeWatcher.cs: -------------------------------------------------------------------------------- 1 | using Relax; 2 | using Symbiote.Core.Extensions; 3 | 4 | namespace RelaxDemo 5 | { 6 | public class ChangeWatcher 7 | { 8 | private IDocumentRepository _couch; 9 | 10 | public void Start() 11 | { 12 | _couch.HandleUpdates(0, Update, null); 13 | } 14 | 15 | private void Update(string database, ChangeRecord obj) 16 | { 17 | "An update was posted to couch: \r\n\t {0}" 18 | .ToInfo(obj.Document); 19 | } 20 | 21 | public void Stop() 22 | { 23 | _couch.StopChangeStreaming(); 24 | } 25 | 26 | public ChangeWatcher(IDocumentRepository couch) 27 | { 28 | _couch = couch; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/DatabaseDeleter.cs: -------------------------------------------------------------------------------- 1 | using Relax; 2 | 3 | namespace RelaxDemo 4 | { 5 | public class DatabaseDeleter 6 | { 7 | private ICouchServer _couch; 8 | 9 | public void Nuke() 10 | { 11 | _couch.DeleteDatabase(); 12 | } 13 | 14 | public DatabaseDeleter(ICouchServer couch) 15 | { 16 | _couch = couch; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/DocumentRetriever.cs: -------------------------------------------------------------------------------- 1 | using Relax; 2 | 3 | namespace RelaxDemo 4 | { 5 | public class DocumentRetriever 6 | { 7 | private IDocumentRepository _couch; 8 | 9 | public TestDocument GetById(object id, string rev) 10 | { 11 | return _couch.Get(id, rev); 12 | } 13 | 14 | public DocumentRetriever(IDocumentRepository couch) 15 | { 16 | _couch = couch; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/DocumentSaver.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Relax; 3 | using Symbiote.Core.Extensions; 4 | 5 | namespace RelaxDemo 6 | { 7 | public class DocumentSaver 8 | { 9 | private IDocumentRepository _couch; 10 | 11 | public void Save(TestDocument document) 12 | { 13 | var watch = Stopwatch.StartNew(); 14 | _couch.Save(document); 15 | watch.Stop(); 16 | "Save completed in {0}" 17 | .ToInfo(watch.ElapsedMilliseconds); 18 | } 19 | 20 | public DocumentSaver(IDocumentRepository couch) 21 | { 22 | _couch = couch; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/LuceneSearchClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Relax; 6 | using Symbiote.JsonRpc.Client; 7 | 8 | namespace RelaxDemo 9 | { 10 | public class LuceneSearchClient 11 | { 12 | protected IRemoteProxy queryService; 13 | 14 | public string[] GetMatchesForQuery() 15 | { 16 | return queryService.Call(x => x.GetDocumentIdsForQuery("testdocument", "Message:Doc*")); 17 | } 18 | 19 | public LuceneSearchClient(IRemoteProxy queryService) 20 | { 21 | this.queryService = queryService; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /demo/RelaxDemo/PagingDataLoader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Relax; 3 | 4 | namespace RelaxDemo 5 | { 6 | public class PagingDataLoader 7 | { 8 | private IDocumentRepository _couch; 9 | private int _page = 0; 10 | 11 | public IList GetNext3Documents() 12 | { 13 | return _couch.GetAll(3, ++_page); 14 | } 15 | 16 | public PagingDataLoader(IDocumentRepository couch) 17 | { 18 | _couch = couch; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("RelaxDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("RelaxDemo")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("eb7e993a-6211-4cb1-b212-b3545f8b2c22")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /demo/RelaxDemo/TestDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Relax; 4 | using Relax.Impl; 5 | using Relax.Impl.Model; 6 | 7 | namespace RelaxDemo 8 | { 9 | [Serializable] 10 | public class TestDocument 11 | : ComplexCouchDocument 12 | { 13 | public virtual string Message { get; set; } 14 | public virtual DateTime Time { get; set; } 15 | public virtual int RandomNumber { get; set; } 16 | 17 | public TestDocument() 18 | { 19 | _documentId = Guid.NewGuid(); 20 | var rnd = new Random(); 21 | RandomNumber = rnd.Next(100); 22 | } 23 | 24 | public TestDocument(string message) 25 | { 26 | _documentId = Guid.NewGuid(); 27 | Message = message; 28 | Time = DateTime.Now; 29 | var rnd = new Random(); 30 | RandomNumber = rnd.Next(100); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /demo/RelaxDemo/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /lib/MSpec/CommandLine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/CommandLine.dll -------------------------------------------------------------------------------- /lib/MSpec/Machine.Specifications.TDNetRunner.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/Machine.Specifications.TDNetRunner.dll -------------------------------------------------------------------------------- /lib/MSpec/Machine.Specifications.TDNetRunner.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/Machine.Specifications.TDNetRunner.pdb -------------------------------------------------------------------------------- /lib/MSpec/Machine.Specifications.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/Machine.Specifications.dll -------------------------------------------------------------------------------- /lib/MSpec/Machine.Specifications.dll.tdnet: -------------------------------------------------------------------------------- 1 | 2 | Machine.Specifications 0.4.0-no SHA 3 | Machine.Specifications.TDNetRunner.dll 4 | Machine.Specifications.TDNetRunner.SpecificationRunner 5 | 6 | -------------------------------------------------------------------------------- /lib/MSpec/Machine.Specifications.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/Machine.Specifications.pdb -------------------------------------------------------------------------------- /lib/MSpec/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /lib/MSpec/Spark.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/Spark.dll -------------------------------------------------------------------------------- /lib/MSpec/Spark.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/Spark.pdb -------------------------------------------------------------------------------- /lib/MSpec/TestDriven.Framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/TestDriven.Framework.dll -------------------------------------------------------------------------------- /lib/MSpec/ThoughtWorks.Selenium.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/ThoughtWorks.Selenium.Core.dll -------------------------------------------------------------------------------- /lib/MSpec/ThoughtWorks.Selenium.Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/ThoughtWorks.Selenium.Core.pdb -------------------------------------------------------------------------------- /lib/MSpec/mspec-clr4.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/mspec-clr4.exe -------------------------------------------------------------------------------- /lib/MSpec/mspec-clr4.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/mspec-clr4.pdb -------------------------------------------------------------------------------- /lib/MSpec/mspec-x86-clr4.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/mspec-x86-clr4.exe -------------------------------------------------------------------------------- /lib/MSpec/mspec-x86-clr4.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/mspec-x86-clr4.pdb -------------------------------------------------------------------------------- /lib/MSpec/mspec-x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/mspec-x86.exe -------------------------------------------------------------------------------- /lib/MSpec/mspec-x86.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/mspec-x86.pdb -------------------------------------------------------------------------------- /lib/MSpec/mspec.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/mspec.exe -------------------------------------------------------------------------------- /lib/MSpec/mspec.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/MSpec/mspec.pdb -------------------------------------------------------------------------------- /lib/Moq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/Moq.dll -------------------------------------------------------------------------------- /lib/Reactive/System.CoreEx.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/Reactive/System.CoreEx.dll -------------------------------------------------------------------------------- /lib/Reactive/System.Interactive.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/Reactive/System.Interactive.dll -------------------------------------------------------------------------------- /lib/Reactive/System.Reactive.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/Reactive/System.Reactive.dll -------------------------------------------------------------------------------- /lib/Symbiote.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/Symbiote.Core.dll -------------------------------------------------------------------------------- /lib/Symbiote.Core.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/code-attic/Relax/19c1ae826b1d219a73c3d9a42b3192c813bba06b/lib/Symbiote.Core.pdb -------------------------------------------------------------------------------- /src/Relax/ChangeRecord.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using Newtonsoft.Json; 17 | 18 | namespace Relax 19 | { 20 | public class ChangeRecord 21 | { 22 | [JsonProperty( PropertyName = "id" )] 23 | public string Id { get; set; } 24 | 25 | [JsonProperty( PropertyName = "seq" )] 26 | public string Sequence { get; set; } 27 | 28 | [JsonIgnore] 29 | public string Document { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /src/Relax/Config/CouchConfigurationException.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System; 17 | 18 | namespace Relax.Config 19 | { 20 | public class CouchConfigurationException : Exception 21 | { 22 | public CouchConfigurationException( string message ) : base( message ) 23 | { 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Relax/Config/ICouchConfiguration.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System; 17 | 18 | namespace Relax.Config 19 | { 20 | public interface ICouchConfiguration 21 | { 22 | bool Cache { get; set; } 23 | DateTime CacheExpiration { get; set; } 24 | TimeSpan CacheLimit { get; set; } 25 | string CouchQueryServiceUrl { get; set; } 26 | string DefaultDatabaseName { get; set; } 27 | bool IncludeTypeSpecification { get; set; } 28 | int MetadataCacheLimit { get; set; } 29 | string Password { get; set; } 30 | int Port { get; set; } 31 | bool Preauthorize { get; set; } 32 | string Protocol { get; set; } 33 | string Server { get; set; } 34 | bool Throw404Exceptions { get; set; } 35 | int TimeOut { get; set; } 36 | string User { get; set; } 37 | string GetDatabaseNameForType(); 38 | void SetDatabaseNameForType( string databaseName ); 39 | } 40 | } -------------------------------------------------------------------------------- /src/Relax/Config/RelaxConfigurationException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Relax.Config 4 | { 5 | public class RelaxConfigurationException : Exception 6 | { 7 | public RelaxConfigurationException(string message) : base(message) 8 | { 9 | 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/Relax/CouchAssimilation.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System; 17 | using Relax.Config; 18 | using Symbiote.Core; 19 | 20 | namespace Relax 21 | { 22 | public static class CouchAssimilation 23 | { 24 | public static IAssimilate Couch( this IAssimilate assimilate, Action configure ) 25 | { 26 | var config = new CouchConfigurator(); 27 | configure( config ); 28 | var configuration = config.Configuration; 29 | CouchInit.Configure( configuration ); 30 | return assimilate; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/Relax/ICouchDocument.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System.Collections.Generic; 17 | using Relax.Impl.Model; 18 | 19 | namespace Relax 20 | { 21 | public interface ICouchDocument 22 | : IHaveDocumentId, IHaveDocumentRevision 23 | { 24 | TKey DocumentId { get; set; } 25 | IEnumerable Attachments { get; } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Relax/ICouchServer.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System; 17 | using System.Collections.Generic; 18 | using Relax.Impl.Http; 19 | 20 | namespace Relax 21 | { 22 | public interface ICouchServer 23 | : IDisposable 24 | { 25 | IList DatabaseList { get; } 26 | IDocumentRepository Repository { get; } 27 | void CleanViews(); 28 | void CreateDatabase(); 29 | void CompactDatabase(); 30 | void CompactView( string testview ); 31 | void CopyDatabase( CouchUri targetUri ); 32 | void CopyDatabase( CouchUri sourceUri, CouchUri targetUri ); 33 | bool DatabaseExists(); 34 | void DeleteDatabase(); 35 | void Replicate( CouchUri targetUri ); 36 | void Replicate( CouchUri sourceUri, CouchUri targetUri ); 37 | } 38 | } -------------------------------------------------------------------------------- /src/Relax/IRelaxQueryService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Relax 7 | { 8 | public interface IRelaxQueryService 9 | { 10 | string[] GetDocumentIdsForQuery(string database, string luceneQuery); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Relax/IResolveDatabaseNames.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax 17 | { 18 | public interface IResolveDatabaseNames 19 | { 20 | string GetDatabaseNameFor(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Cache/ICacheKeyBuilder.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax.Impl.Cache 17 | { 18 | public interface ICacheKeyBuilder 19 | { 20 | string GetKey( object id ); 21 | string GetKey( object id, string rev ); 22 | string GetRangeKey( object startKey, object endKey ); 23 | string GetListKey(); 24 | string GetListKey( int page, int size ); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Cache/IKeyAssociationManager.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System.Collections.Generic; 17 | 18 | namespace Relax.Impl.Cache 19 | { 20 | public interface IKeyAssociationManager 21 | { 22 | void AddKeyAssociation( string key, string cacheKey ); 23 | IEnumerable GetAllKeys(); 24 | IEnumerable GetAssociations( string key ); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Commands/ISaveDocument.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax.Impl.Commands 17 | { 18 | public interface ISaveDocument 19 | { 20 | CommandResult Save( TModel model ); 21 | CommandResult Save( string databaseName, object model ); 22 | } 23 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Commands/ISaveDocuments.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System.Collections.Generic; 17 | 18 | namespace Relax.Impl.Commands 19 | { 20 | public interface ISaveDocuments 21 | { 22 | CommandResult SaveAll( IEnumerable models ); 23 | CommandResult SaveAll( string database, IEnumerable models ); 24 | } 25 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Feed.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax.Impl 17 | { 18 | public enum Feed 19 | { 20 | Continuous, 21 | LongPolling, 22 | Simple 23 | } 24 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Http/IHttpAction.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System; 17 | 18 | namespace Relax.Impl.Http 19 | { 20 | public interface IHttpAction 21 | { 22 | string GetResponse( CouchUri uri, string method, string body ); 23 | Tuple GetAttachment( CouchUri uri ); 24 | string SaveAttachment( CouchUri uri, string type, byte[] content ); 25 | void GetContinuousResponse( CouchUri uri, int since, Action callback ); 26 | void StopContinousResponse(); 27 | string Post( CouchUri uri ); 28 | string Post( CouchUri uri, string body ); 29 | string Put( CouchUri uri ); 30 | string Put( CouchUri uri, string body ); 31 | string Get( CouchUri uri ); 32 | string Delete( CouchUri uri ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/Relax/Impl/IDocumentSearchProvider.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System; 17 | using System.Linq.Expressions; 18 | 19 | namespace Relax.Impl 20 | { 21 | public interface IDocumentSearchProvider 22 | { 23 | object[] GetDocumentIdsForQuery( Expression> criteria ); 24 | } 25 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Json/KeyList.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax.Impl.Json 17 | { 18 | public class KeyList 19 | { 20 | public object[] keys { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Json/SaveResponse.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using Newtonsoft.Json; 17 | 18 | namespace Relax.Impl.Json 19 | { 20 | public class SaveResponse 21 | { 22 | [JsonProperty( PropertyName = "ok" )] 23 | public bool Success { get; set; } 24 | 25 | [JsonProperty( PropertyName = "id" )] 26 | public string Id { get; set; } 27 | 28 | [JsonProperty( PropertyName = "rev" )] 29 | public string Revision { get; set; } 30 | } 31 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Json/ViewResult.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using Newtonsoft.Json; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | 20 | namespace Relax.Impl.Json 21 | { 22 | public class ViewResult 23 | { 24 | [JsonProperty( PropertyName = "total_rows" )] 25 | public int TotalRows { get; set; } 26 | 27 | [JsonProperty( PropertyName = "offset" )] 28 | public int Offset { get; set; } 29 | 30 | [JsonProperty( PropertyName = "rows" )] 31 | public ViewRow[] Rows { get; set; } 32 | 33 | public IEnumerable GetList() 34 | { 35 | return Rows.Select( x => x.Model ); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Model/DesignDocument.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using Newtonsoft.Json; 17 | using System.Collections.Generic; 18 | 19 | namespace Relax.Impl.Model 20 | { 21 | public class DesignDocument : ComplexCouchDocument 22 | { 23 | [JsonProperty( PropertyName = "views" )] 24 | public Dictionary Views { get; set; } 25 | 26 | public DesignDocument() 27 | { 28 | Views = new Dictionary(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Model/DesignView.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using Newtonsoft.Json; 17 | 18 | namespace Relax.Impl.Model 19 | { 20 | public class DesignView 21 | { 22 | [JsonProperty( PropertyName = "map" )] 23 | public string Map { get; set; } 24 | 25 | [JsonProperty( PropertyName = "reduce" )] 26 | public string Reduce { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Model/DocumentMetadata.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | 17 | using Relax.Impl.Model; 18 | 19 | namespace Relax.Impl.Model 20 | { 21 | public class DocumentMetadata : BaseDocument 22 | { 23 | public virtual string _id { get; set; } 24 | 25 | public virtual string _rev { get; set; } 26 | 27 | public virtual void UpdateRevFromJson( string jsonRev ) 28 | { 29 | _rev = jsonRev; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Relax/Impl/Model/IHaveAttachments.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax.Impl.Model 17 | { 18 | public interface IHaveAttachments 19 | { 20 | void AddAttachment( string attachmentName, string contentType, long contentLength ); 21 | void RemoveAttachment( string attachmentName ); 22 | } 23 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Model/IHaveDocumentId.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax.Impl.Model 17 | { 18 | public interface IHaveDocumentId 19 | { 20 | string GetDocumentIdAsJson(); 21 | object GetDocumentId(); 22 | } 23 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Model/IHaveDocumentRevision.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax.Impl.Model 17 | { 18 | public interface IHaveDocumentRevision 19 | { 20 | string DocumentRevision { get; set; } 21 | void UpdateRevFromJson( string jsonRev ); 22 | } 23 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Model/JSONDocument.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System; 17 | using Newtonsoft.Json; 18 | 19 | namespace Relax.Impl.Model 20 | { 21 | [Serializable] 22 | [JsonObject( MemberSerialization = MemberSerialization.OptIn )] 23 | public class JsonDocument : CouchDocument 24 | { 25 | [JsonProperty( DefaultValueHandling = DefaultValueHandling.Ignore )] 26 | public string Body { get; set; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Persistence/KeyValueStore.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System.Collections.Generic; 17 | using Symbiote.Core.Persistence; 18 | 19 | namespace Relax.Impl.Persistence 20 | { 21 | public class KeyValueStore : IKeyValueStore 22 | { 23 | public IDocumentRepository Repository { get; set; } 24 | 25 | public bool Delete( string key ) 26 | { 27 | return Repository.DeleteDocument( key ); 28 | } 29 | 30 | public T Get( string key ) 31 | { 32 | return Repository.Get( key ); 33 | } 34 | 35 | public IEnumerable GetAll() 36 | { 37 | return Repository.GetAll(); 38 | } 39 | 40 | public bool Persist( string key, T instance ) 41 | { 42 | return Repository.Save( key, instance ); 43 | } 44 | 45 | public KeyValueStore( IDocumentRepository repository ) 46 | { 47 | Repository = repository; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Relax/Impl/Repository/DocumentRepository.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using Relax.Config; 17 | using Relax.Impl.Serialization; 18 | 19 | namespace Relax.Impl.Repository 20 | { 21 | public class DocumentRepository 22 | : BaseDocumentRepository 23 | { 24 | public DocumentRepository( ICouchConfiguration configuration, ISerializationProvider serializer ) : base( configuration, serializer ) 25 | { 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Serialization/DocumentConventions.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Impl.Serialization 2 | { 3 | public class DocumentConventions 4 | { 5 | public string IdPropertyName { get; set; } 6 | public string RevisionPropertyName { get; set; } 7 | 8 | public DocumentConventions() 9 | { 10 | IdPropertyName = "Id"; 11 | RevisionPropertyName = "Rev"; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Relax/Impl/Serialization/DocumentMetadataProvider.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using Relax.Impl.Model; 17 | using Symbiote.Core.Collections; 18 | 19 | namespace Relax.Impl.Serialization 20 | { 21 | public class DocumentMetadataProvider : IProvideDocumentMetadata 22 | { 23 | public MruDictionary Cache { get; set; } 24 | 25 | public void Clear() 26 | { 27 | Cache.Clear(); 28 | } 29 | 30 | public DocumentMetadata GetMetadata( string key ) 31 | { 32 | DocumentMetadata metadata = null; 33 | Cache.TryGetValue( key, out metadata ); 34 | return metadata; 35 | } 36 | 37 | public void SetMetadata( string key, DocumentMetadata metadata ) 38 | { 39 | Cache[ key ] = metadata; 40 | } 41 | 42 | public DocumentMetadataProvider() 43 | { 44 | Cache = new MruDictionary( 100000 ); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Serialization/IProvideDocumentMetadata.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using Relax.Impl.Model; 17 | 18 | namespace Relax.Impl.Serialization 19 | { 20 | public interface IProvideDocumentMetadata 21 | { 22 | void Clear(); 23 | DocumentMetadata GetMetadata( string key ); 24 | void SetMetadata( string key, DocumentMetadata metadata ); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Serialization/ISerializationProvider.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | using System.IO; 17 | using Relax.Impl.Json; 18 | 19 | namespace Relax.Impl.Serialization 20 | { 21 | public interface ISerializationProvider 22 | { 23 | void Serialize( T instance, TextWriter writer ); 24 | //void Serialize( BulkPersist bulkPersist, TextWriter writer ); 25 | T Deserialize( string json ); 26 | ViewResult DeserializeList( string json ); 27 | } 28 | } -------------------------------------------------------------------------------- /src/Relax/Impl/Serialization/IValueProviderCache.cs: -------------------------------------------------------------------------------- 1 | // /* 2 | // Copyright 2008-2011 Alex Robson 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // */ 16 | namespace Relax.Impl.Serialization 17 | { 18 | public interface IValueProviderCache 19 | { 20 | MetadataValueProvider GetValueProviderFor( string memberName ); 21 | } 22 | } -------------------------------------------------------------------------------- /src/Relax/RelaxException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Relax 4 | { 5 | public class RelaxException : Exception 6 | { 7 | public RelaxException(string message) : base(message) 8 | { 9 | } 10 | 11 | public RelaxException(string message, Exception innerException) : base(message, innerException) 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /tests/Assimilation/when_assimilating_with_caching.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Moq; 3 | using Relax.Config; 4 | using Symbiote.Core; 5 | using Symbiote.Core.Cache; 6 | using It = Machine.Specifications.It; 7 | 8 | namespace Relax.Tests.Assimilation 9 | { 10 | 11 | [Subject("Assimilation")] 12 | public class when_assimilating_with_caching 13 | { 14 | private Because of = () => 15 | { 16 | Assimilate.Initialize(); 17 | var rememberMock = new Mock().Object; 18 | Assimilate.Dependencies( x => x.For().Use( rememberMock ) ); 19 | CouchInit.Configure(x => x.Cache()); 20 | }; 21 | 22 | private It should_use_CouchConfiguration_for_ICouchConfiguration = 23 | () => Assimilate 24 | .Assimilation 25 | .DependencyAdapter 26 | .GetDefaultTypeFor() 27 | .ShouldEqual(typeof(CouchConfiguration)); 28 | 29 | private It should_use_DocumentRepository_for_IDocumentRepository = 30 | () => Assimilate 31 | .Assimilation 32 | .DependencyAdapter 33 | .HasPluginFor(typeof (IDocumentRepository)) 34 | .ShouldBeTrue(); 35 | 36 | private It should_have_couch_server_configured = 37 | () => Assimilate 38 | .Assimilation 39 | .DependencyAdapter 40 | .HasPluginFor() 41 | .ShouldBeTrue(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Assimilation/when_assimilating_without_caching.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Config; 3 | using Symbiote.Core; 4 | 5 | namespace Relax.Tests.Assimilation 6 | { 7 | [Subject("Assimilation")] 8 | public class when_assimilating_without_caching 9 | { 10 | private Because of = () => Assimilate.Initialize(); 11 | 12 | private It should_use_CouchConfiguration_for_ICouchConfiguration = 13 | () => Assimilate 14 | .Assimilation 15 | .DependencyAdapter 16 | .GetDefaultTypeFor() 17 | .ShouldEqual(typeof(CouchConfiguration)); 18 | 19 | private It should_use_DocumentRepository_for_IDocumentRepository = 20 | () => Assimilate 21 | .Assimilation 22 | .DependencyAdapter 23 | .HasPluginFor() 24 | .ShouldBeTrue(); 25 | 26 | private It should_have_couch_server_configured = 27 | () => Assimilate 28 | .Assimilation 29 | .DependencyAdapter 30 | .HasPluginFor() 31 | .ShouldBeTrue(); 32 | } 33 | } -------------------------------------------------------------------------------- /tests/Caching/when_adding_cross_reference.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Cache; 3 | 4 | namespace Relax.Tests.Caching 5 | { 6 | public class when_adding_cross_reference : with_couch_cache_provider 7 | { 8 | protected static ICouchCacheProvider couchCacheProvider; 9 | 10 | private Because of = () => 11 | { 12 | keyAssociationManagerMock 13 | .Setup(x => x.AddKeyAssociation("item_1", "cache_key")); 14 | couchCacheProvider = CouchCacheProvider; 15 | couchCacheProvider.AddCrossReference("item_1", "cache_key"); 16 | }; 17 | 18 | private It calling_add_cross_reference_should_add_association_to_key_manager = () => 19 | keyAssociationManagerMock.Verify(); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/Caching/when_associating_keys.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Machine.Specifications; 3 | using Relax.Impl.Cache; 4 | 5 | namespace Relax.Tests.Caching 6 | { 7 | public class when_associating_keys 8 | { 9 | protected static IKeyAssociationManager manager; 10 | protected static string[] expected = new string[] { "Mithrandir", "Greyhame", "Storm Crow" }; 11 | protected static string[] actual; 12 | protected static string[] keyList; 13 | private Establish context = () => manager = new DefaultKeyAssociationManager(); 14 | 15 | private Because of = () => 16 | { 17 | manager.AddKeyAssociation("Gandalf", "Storm Crow"); 18 | manager.AddKeyAssociation("Gandalf", "Greyhame"); 19 | manager.AddKeyAssociation("Gandalf", "Mithrandir"); 20 | actual = manager.GetAssociations("Gandalf").ToArray(); 21 | keyList = manager.GetAllKeys().ToArray(); 22 | }; 23 | 24 | private It should_have_key_list = () => keyList.SequenceEqual(new [] {"Gandalf"}); 25 | private It should_have_all_keys_previously_associated = () => 26 | actual.SequenceEqual(expected).ShouldBeTrue(); 27 | } 28 | } -------------------------------------------------------------------------------- /tests/Caching/when_getting_cache_keys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Machine.Specifications; 6 | using Relax.Impl.Cache; 7 | 8 | namespace Relax.Tests.Caching 9 | { 10 | public class when_getting_cache_keys_with_default_cache_key_builder 11 | { 12 | protected static ICacheKeyBuilder keyBuilder; 13 | protected static int pageIndex = 1; 14 | protected static int pageSize = 10; 15 | protected static string id = "1"; 16 | protected static string rev = "B"; 17 | 18 | protected static string expected_id_key = "Relax.Tests.TestDocument_1"; 19 | protected static string expected_id_and_rev_key = "Relax.Tests.TestDocument_1_B"; 20 | protected static string expected_list_key = "Relax.Tests.TestDocument_list"; 21 | protected static string expected_paged_list_key = "Relax.Tests.TestDocument_1_10"; 22 | 23 | private Establish context = () => keyBuilder = new CacheKeyBuilder(); 24 | 25 | private It should_produce_id_key = () => keyBuilder.GetKey(id).ShouldEqual(expected_id_key); 26 | private It should_produce_id_and_rev_key = () => keyBuilder.GetKey(id, rev).ShouldEqual(expected_id_and_rev_key); 27 | private It should_produce_list_key = () => keyBuilder.GetListKey().ShouldEqual(expected_list_key); 28 | private It should_produce_paging_list_key = () => keyBuilder.GetListKey(pageIndex, pageSize).ShouldEqual(expected_paged_list_key); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Caching/when_invalidating_item.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Cache; 3 | 4 | namespace Relax.Tests.Caching 5 | { 6 | public class when_invalidating_item : with_couch_cache_provider 7 | { 8 | protected static ICouchCacheProvider couchCacheProvider; 9 | 10 | private Because of = () => 11 | { 12 | keyAssociationManagerMock 13 | .Setup(x => x.GetAssociations("item_1")) 14 | .Returns(new string[] {"cache_key1", "cache_key2"}); 15 | 16 | cacheProviderMock 17 | .Setup(x => x.Remove("cache_key1")) 18 | .AtMostOnce(); 19 | 20 | cacheProviderMock 21 | .Setup(x => x.Remove("cache_key2")) 22 | .AtMostOnce(); 23 | 24 | couchCacheProvider = CouchCacheProvider; 25 | couchCacheProvider.InvalidateItem("item_1"); 26 | }; 27 | 28 | private It should_get_associations_from_key_association_manager = () => keyAssociationManagerMock.VerifyAll(); 29 | private It should_remove_associated_keys_from_the_cache = () => cacheProviderMock.VerifyAll(); 30 | } 31 | } -------------------------------------------------------------------------------- /tests/Caching/with_cache_provider.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Moq; 3 | using Symbiote.Core.Cache; 4 | 5 | namespace Relax.Tests.Caching 6 | { 7 | public abstract class with_cache_provider : with_configuration 8 | { 9 | protected static Mock cacheProviderMock; 10 | protected static ICacheProvider CacheProvider { get { return cacheProviderMock.Object; } } 11 | 12 | private Establish context = () => 13 | { 14 | cacheProviderMock = new Mock(); 15 | }; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/Caching/with_caching_provider.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Caching 2 | { 3 | public abstract class with_caching_provider 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/Caching/with_couch_cache_provider.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Moq; 3 | using Relax.Impl.Cache; 4 | 5 | namespace Relax.Tests.Caching 6 | { 7 | public abstract class with_couch_cache_provider : with_cache_provider 8 | { 9 | protected static Mock cacheKeyBuilderMock; 10 | protected static Mock keyAssociationManagerMock; 11 | 12 | protected static ICacheKeyBuilder CacheKeyBuilder { get { return cacheKeyBuilderMock.Object; } } 13 | protected static IKeyAssociationManager KeyAssociationManager { get { return keyAssociationManagerMock.Object; } } 14 | 15 | protected static CouchCacheProvider CouchCacheProvider 16 | { 17 | get 18 | { 19 | return new CouchCacheProvider( 20 | CacheProvider, 21 | KeyAssociationManager, 22 | CacheKeyBuilder); 23 | } 24 | } 25 | 26 | private Establish context = () => 27 | { 28 | cacheKeyBuilderMock = new Mock(); 29 | keyAssociationManagerMock = new Mock(); 30 | }; 31 | } 32 | } -------------------------------------------------------------------------------- /tests/Commands/DeletingAttachments/when_deleting_attachment.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Commands.DeletingAttachments 5 | { 6 | public class when_deleting_attachment : with_delete_attachment_command 7 | { 8 | private Because of = () => 9 | { 10 | command.DeleteAttachment(document, "myattachment"); 11 | }; 12 | 13 | private It should_update_revision = () => document.DocumentRevision.ShouldEqual("02"); 14 | private It should_remove_attachment = () => ShouldExtensionMethods.ShouldEqual(document.Attachments.Count(), 0); 15 | } 16 | } -------------------------------------------------------------------------------- /tests/Commands/FromView/when_getting_from_view.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Machine.Specifications; 3 | using Relax.Impl.Commands; 4 | using Relax.Impl.Json; 5 | 6 | namespace Relax.Tests.Commands.FromView 7 | { 8 | public class when_getting_from_view : with_get_from_view_command 9 | { 10 | protected static ViewResult expectedResult; 11 | protected static CommandResult result; 12 | protected static TestDoc document; 13 | 14 | private Because of = () => 15 | { 16 | result = command.GetFromView("test", "test", 17 | x => x.AllowStale().NoReduce()); 18 | expectedResult = result.GetResultAs>(); 19 | document = expectedResult.Rows.First().Model; 20 | }; 21 | 22 | private It should_only_have_one_record = () => expectedResult.Rows.Length.ShouldEqual(1); 23 | private It should_have_correct_id = () => document.DocumentId.ShouldEqual("test"); 24 | private It should_have_correct_rev = () => document.DocumentRevision.ShouldEqual("1"); 25 | private It should_have_correct_message = () => document.Message.ShouldEqual("Hi"); 26 | } 27 | } -------------------------------------------------------------------------------- /tests/Commands/FromView/with_get_from_view_command.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Http; 4 | 5 | namespace Relax.Tests.Commands.FromView 6 | { 7 | public abstract class with_get_from_view_command : with_command_factory 8 | { 9 | protected static string url; 10 | protected static GetFromViewCommand command; 11 | protected static string jsonResult; 12 | 13 | private Establish context = () => 14 | { 15 | jsonResult = @" 16 | { 17 | total_rows: 2, 18 | offset: 0, 19 | rows: 20 | [ 21 | { 22 | doc: { _id: ""test"", _rev: ""1"", Message: ""Hi"" } 23 | }, 24 | { 25 | doc: { _id: ""_design/mydesigndoc"" } 26 | } 27 | ] 28 | } 29 | "; 30 | url = @"http://localhost:5984/relax/_design/test/_view/test?stale=ok&reduce=false"; 31 | mockAction 32 | .Setup(x => x.Get(Moq.It.Is(u => u.ToString() == url))) 33 | .Returns(jsonResult); 34 | 35 | command = factory.CreateGetFromViewCommand(); 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Commands/GetCommand/when_getting_doc_by_id.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Machine.Specifications; 6 | using Relax.Impl.Commands; 7 | using It = Machine.Specifications.It; 8 | 9 | namespace Relax.Tests.Commands 10 | { 11 | public class when_getting_doc_by_id : with_get_doc_by_id_setup 12 | { 13 | protected static CommandResult result; 14 | protected static TestDoc model; 15 | protected static string json; 16 | 17 | private Because of = () => 18 | { 19 | result = command.GetDocument("1"); 20 | model = result.GetResultAs(); 21 | json = result.Json.Replace("\r\n", "").Replace(" ", ""); 22 | }; 23 | 24 | private It should_produce_expected_json = () => json.ShouldEqual(response); 25 | 26 | private It should_create_valid_instance = () => 27 | { 28 | model.DocumentId.ShouldEqual("1"); 29 | model.DocumentRevision.ShouldEqual("1"); 30 | model.Message.ShouldEqual("Test"); 31 | }; 32 | private It should_call_action = () => mockAction.Verify(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Commands/GetCommand/when_getting_doc_by_id_and_rev.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | 4 | namespace Relax.Tests.Commands 5 | { 6 | public class when_getting_doc_by_id_and_rev : with_get_doc_by_id_and_rev_setup 7 | { 8 | protected static CommandResult result; 9 | protected static TestDoc model; 10 | protected static string json; 11 | 12 | private Because of = () => 13 | { 14 | result = command.GetDocument("1", "1"); 15 | model = result.GetResultAs(); 16 | json = result.Json.Replace("\r\n", "").Replace(" ", ""); 17 | }; 18 | 19 | private It should_produce_expected_json = () => json.ShouldEqual(response); 20 | 21 | private It should_create_valid_instance = () => 22 | { 23 | model.DocumentId.ShouldEqual("1"); 24 | model.DocumentRevision.ShouldEqual("1"); 25 | model.Message.ShouldEqual("Test"); 26 | }; 27 | private It should_call_action = () => mockAction.Verify(); 28 | } 29 | } -------------------------------------------------------------------------------- /tests/Commands/GetCommand/when_getting_documents_by_key_range.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Json; 4 | 5 | namespace Relax.Tests.Commands 6 | { 7 | public class when_getting_documents_by_key_range : with_get_doc_by_range 8 | { 9 | protected static CommandResult result; 10 | protected static ViewResult viewResult; 11 | protected static string json; 12 | 13 | private Because of = () => 14 | { 15 | result = command.GetDocumentsInRange("doc 1", "doc 2"); 16 | viewResult = result.GetResultAs>(); 17 | }; 18 | 19 | private It should_have_one_document = () => viewResult.TotalRows.ShouldEqual(1); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/Commands/GetCommand/with_get_all_docs_paged.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Commands 4 | { 5 | public abstract class with_get_all_docs_paged : with_get_all_docs 6 | { 7 | private Establish context = () => 8 | { 9 | url = @"http://localhost:5984/relax/_all_docs?include_docs=true&skip=4&limit=2"; 10 | }; 11 | } 12 | } -------------------------------------------------------------------------------- /tests/Commands/GetCommand/with_get_doc_by_id_and_rev_setup.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Commands 4 | { 5 | public abstract class with_get_doc_by_id_and_rev_setup : with_get_doc_by_id_setup 6 | { 7 | private Establish context = () => 8 | { 9 | url = @"http://localhost:5984/relax/1?rev=1"; 10 | }; 11 | } 12 | } -------------------------------------------------------------------------------- /tests/Commands/GetCommand/with_get_doc_by_id_setup.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Http; 4 | 5 | namespace Relax.Tests.Commands 6 | { 7 | public abstract class with_get_doc_by_id_setup : with_command_factory 8 | { 9 | protected static string response; 10 | protected static string url; 11 | protected static GetDocumentCommand command; 12 | 13 | private Establish context = () => 14 | { 15 | url = @"http://localhost:5984/relax/1"; 16 | response = @"{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""1"",""_rev"":""1"",""Message"":""Test""}"; 17 | mockAction 18 | .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) 19 | .Returns(response) 20 | .AtMostOnce(); 21 | command = factory.CreateGetDocumentCommand(); 22 | }; 23 | } 24 | } -------------------------------------------------------------------------------- /tests/Commands/GetCommand/with_get_doc_by_range.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Http; 4 | 5 | namespace Relax.Tests.Commands 6 | { 7 | public abstract class with_get_doc_by_range : with_command_factory 8 | { 9 | protected static string response; 10 | protected static string url; 11 | protected static GetDocumentsInRangeCommand command; 12 | 13 | private Establish context = () => 14 | { 15 | url = @"http://localhost:5984/relax/_all_docs?include_docs=true&startkey=""doc+1""&endkey=""doc+2"""; 16 | response = @" 17 | { 18 | total_rows: 1, 19 | offset: 0, 20 | rows: 21 | [ 22 | { 23 | doc: { 24 | $type: ""Relax.Tests.Commands.TestDoc, Relax.Tests"", 25 | _id: ""1"", 26 | _rev: ""1"", 27 | Message: ""Test"" 28 | } 29 | } 30 | ] 31 | }"; 32 | mockAction 33 | .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) 34 | .Returns(response) 35 | .AtMostOnce(); 36 | command = factory.CreateGetDocumentsInRangeCommand(); 37 | }; 38 | } 39 | } -------------------------------------------------------------------------------- /tests/Commands/GettingAttachments/when_getting_attachment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Machine.Specifications; 4 | 5 | namespace Relax.Tests.Commands.GettingAttachments 6 | { 7 | public class when_getting_attachment : with_get_attachment_command 8 | { 9 | protected static Tuple expectedAttachment; 10 | protected static string content; 11 | 12 | private Because of = () => 13 | { 14 | expectedAttachment = command.GetAttachment("test", "myattachment"); 15 | content = Encoding.UTF8.GetString(expectedAttachment.Item2); 16 | }; 17 | 18 | private It should_have_attachment_name = () => expectedAttachment.Item1.ShouldEqual("myattachment"); 19 | private It should_have_correct_content = () => content.ShouldEqual("this is a lame attachment :("); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/Commands/GettingAttachments/with_get_attachment_command.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Machine.Specifications; 4 | using Relax.Impl.Commands; 5 | using Relax.Impl.Http; 6 | 7 | namespace Relax.Tests.Commands.GettingAttachments 8 | { 9 | public abstract class with_get_attachment_command : with_command_factory 10 | { 11 | protected static string url; 12 | protected static Tuple attachment; 13 | protected static GetAttachmentCommand command; 14 | 15 | private Establish context = () => 16 | { 17 | url = @"http://localhost:5984/relax/test/myattachment"; 18 | 19 | var content = "this is a lame attachment :("; 20 | var bytes = Encoding.UTF8.GetBytes(content); 21 | attachment = Tuple.Create("myattachment", bytes); 22 | 23 | mockAction 24 | .Setup( 25 | x => x.GetAttachment(Moq.It.Is(u => u.ToString() == url))) 26 | .Returns(attachment); 27 | command = factory.CreateGetAttachmentCommand(); 28 | }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/when_getting_all_pocos_by_ids_timed.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Machine.Specifications; 3 | using Relax.Impl.Commands; 4 | using Relax.Impl.Json; 5 | using Relax.Impl.Serialization; 6 | using Symbiote.Core; 7 | 8 | namespace Relax.Tests.Commands.GettingDocuments 9 | { 10 | public class when_getting_all_pocos_by_ids_timed : with_get_all_pocos_by_ids 11 | { 12 | protected static CommandResult result; 13 | protected static ViewResult viewResult; 14 | protected static string json; 15 | protected static IProvideDocumentMetadata MetadataProvider; 16 | protected static Stopwatch watch; 17 | 18 | private Because of = () => 19 | { 20 | MetadataProvider = Assimilate.GetInstanceOf(); 21 | result = command.GetDocuments(new object[] {"1","2"}); 22 | 23 | watch = Stopwatch.StartNew(); 24 | 25 | for( int i = 0; i < 10000; i++ ) 26 | { 27 | viewResult = command.DeserializeView( result.Json ); 28 | } 29 | 30 | watch.Stop(); 31 | }; 32 | 33 | private It should_not_take_longer_than_2_seconds = () => watch.ElapsedMilliseconds.ShouldBeLessThan( 3000 ); 34 | } 35 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/when_getting_doc_by_id.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | 4 | namespace Relax.Tests.Commands.GettingDocuments 5 | { 6 | public class when_getting_doc_by_id : with_get_doc_by_id_setup 7 | { 8 | protected static CommandResult result; 9 | protected static TestDoc model; 10 | protected static string json; 11 | 12 | private Because of = () => 13 | { 14 | result = command.GetDocument("1"); 15 | model = command.Deserialize(result.Json); 16 | json = result.Json.Replace("\r\n", "").Replace(" ", ""); 17 | }; 18 | 19 | private It should_produce_expected_json = () => json.ShouldEqual(response); 20 | 21 | private It should_create_valid_instance = () => 22 | { 23 | model.DocumentId.ShouldEqual("1"); 24 | model.DocumentRevision.ShouldEqual("1"); 25 | model.Message.ShouldEqual("Test"); 26 | }; 27 | private It should_call_action = () => mockAction.Verify(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/when_getting_doc_by_id_and_rev.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | 4 | namespace Relax.Tests.Commands.GettingDocuments 5 | { 6 | public class when_getting_doc_by_id_and_rev : with_get_doc_by_id_and_rev_setup 7 | { 8 | protected static CommandResult result; 9 | protected static TestDoc model; 10 | protected static string json; 11 | 12 | private Because of = () => 13 | { 14 | result = command.GetDocument("1", "1"); 15 | model = result.GetResultAs(); 16 | json = result.Json.Replace("\r\n", "").Replace(" ", ""); 17 | }; 18 | 19 | private It should_produce_expected_json = () => json.ShouldEqual(response); 20 | 21 | private It should_create_valid_instance = () => 22 | { 23 | model.DocumentId.ShouldEqual("1"); 24 | model.DocumentRevision.ShouldEqual("1"); 25 | model.Message.ShouldEqual("Test"); 26 | }; 27 | private It should_call_action = () => mockAction.Verify(); 28 | } 29 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/when_getting_doc_by_id_timed.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Machine.Specifications; 3 | using Relax.Impl.Commands; 4 | 5 | namespace Relax.Tests.Commands.GettingDocuments 6 | { 7 | public class when_getting_doc_by_id_timed : with_get_doc_by_id_setup 8 | { 9 | protected static CommandResult result; 10 | protected static TestDoc model; 11 | protected static string json; 12 | protected static Stopwatch watch; 13 | 14 | private Because of = () => 15 | { 16 | watch = Stopwatch.StartNew(); 17 | 18 | result = command.GetDocument("1"); 19 | 20 | for( int i = 0; i < 10000; i++ ) 21 | { 22 | model = command.Deserialize(result.Json); 23 | } 24 | 25 | watch.Stop(); 26 | }; 27 | 28 | private It should_take_less_than_1_second = () => watch.ElapsedMilliseconds.ShouldBeLessThan( 1100 ); 29 | } 30 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/when_getting_documents_by_key_range.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Json; 4 | 5 | namespace Relax.Tests.Commands.GettingDocuments 6 | { 7 | public class when_getting_documents_by_key_range : with_get_doc_by_range 8 | { 9 | protected static CommandResult result; 10 | protected static ViewResult viewResult; 11 | protected static string json; 12 | 13 | private Because of = () => 14 | { 15 | result = command.GetDocumentsInRange("doc 1", "doc 2"); 16 | viewResult = result.GetResultAs>(); 17 | }; 18 | 19 | private It should_have_one_document = () => viewResult.TotalRows.ShouldEqual(1); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/when_getting_poco_by_id.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Serialization; 4 | using Symbiote.Core; 5 | 6 | namespace Relax.Tests.Commands.GettingDocuments 7 | { 8 | public class when_getting_poco_by_id : with_get_poco_by_id_setup 9 | { 10 | protected static CommandResult result; 11 | protected static MyPoco model; 12 | protected static string json; 13 | protected static IProvideDocumentMetadata MetadataProvider; 14 | 15 | private Because of = () => 16 | { 17 | MetadataProvider = Assimilate.GetInstanceOf(); 18 | result = command.GetDocument("1"); 19 | model = command.Deserialize(result.Json); 20 | json = result.Json.Replace("\r\n", "").Replace(" ", ""); 21 | }; 22 | 23 | private It should_produce_expected_json = () => json.ShouldEqual(response); 24 | 25 | private It should_create_valid_instance = () => 26 | { 27 | var metadata = MetadataProvider.GetMetadata( "1" ); 28 | metadata._id.ShouldEqual("1"); 29 | metadata._rev.ShouldEqual("1"); 30 | model.MyId.ShouldEqual( "1" ); 31 | model.Message.ShouldEqual("Test"); 32 | }; 33 | private It should_call_action = () => mockAction.Verify(); 34 | } 35 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/when_getting_poco_by_id_timed.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Machine.Specifications; 3 | using Relax.Impl.Commands; 4 | using Relax.Impl.Serialization; 5 | using Symbiote.Core; 6 | 7 | namespace Relax.Tests.Commands.GettingDocuments 8 | { 9 | public class when_getting_poco_by_id_timed : with_get_poco_by_id_setup 10 | { 11 | protected static CommandResult result; 12 | protected static MyPoco model; 13 | protected static string json; 14 | protected static IProvideDocumentMetadata MetadataProvider; 15 | protected static Stopwatch watch; 16 | 17 | private Because of = () => 18 | { 19 | MetadataProvider = Assimilate.GetInstanceOf(); 20 | 21 | watch = Stopwatch.StartNew(); 22 | 23 | result = command.GetDocument("1"); 24 | for( int i = 0; i < 10000; i++ ) 25 | { 26 | model = command.Deserialize(result.Json); 27 | } 28 | 29 | watch.Stop(); 30 | }; 31 | 32 | private It should_not_take_over_1_second = () => watch.ElapsedMilliseconds.ShouldBeLessThan( 1000 ); 33 | } 34 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/with_get_all_docs_paged.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Commands.GettingDocuments 4 | { 5 | public abstract class with_get_all_docs_paged : with_get_all_docs 6 | { 7 | private Establish context = () => 8 | { 9 | url = @"http://localhost:5984/relax/_all_docs?include_docs=true&skip=4&limit=2"; 10 | }; 11 | } 12 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/with_get_all_pocos_by_ids.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Http; 4 | using Relax.Impl.Json; 5 | using Symbiote.Core.Serialization; 6 | 7 | namespace Relax.Tests.Commands.GettingDocuments 8 | { 9 | public abstract class with_get_all_pocos_by_ids : with_command_factory 10 | { 11 | protected static KeyList keyList; 12 | protected static string response; 13 | protected static string url; 14 | protected static GetDocumentsByIdsCommand command; 15 | 16 | private Establish context = () => 17 | { 18 | keyList = new KeyList() { keys = new object[] { "1", "2" } }; 19 | response = @"{""total_rows"":""2"",""offset"":""0"",""rows"":[{""doc"":{""$type"":""Relax.Tests.Commands.MyPoco,Relax.Tests"",""_id"":""1"",""_rev"":""1"",""Message"":""Test1"",""MyId"":""1""}},{""doc"":{""$type"":""Relax.Tests.Commands.MyPoco,Relax.Tests"",""_id"":""2"",""_rev"":""1"",""Message"":""Test2"",""MyId"":""2""}}]}"; 20 | url = @"http://localhost:5984/relax/_all_docs?include_docs=true"; 21 | mockAction 22 | .Setup(x => x.Post(Moq.It.Is(i => i.ToString() == url), keyList.ToJson(false))) 23 | .Returns(response) 24 | .AtMostOnce(); 25 | command = factory.CreateGetDocumentsByIdsCommand(); 26 | }; 27 | } 28 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/with_get_doc_by_id_and_rev_setup.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Commands.GettingDocuments 4 | { 5 | public abstract class with_get_doc_by_id_and_rev_setup : with_get_doc_by_id_setup 6 | { 7 | private Establish context = () => 8 | { 9 | url = @"http://localhost:5984/relax/1?rev=1"; 10 | }; 11 | } 12 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/with_get_doc_by_id_setup.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Http; 4 | 5 | namespace Relax.Tests.Commands.GettingDocuments 6 | { 7 | public abstract class with_get_doc_by_id_setup : with_command_factory 8 | { 9 | protected static string response; 10 | protected static string url; 11 | protected static GetDocumentCommand command; 12 | 13 | private Establish context = () => 14 | { 15 | url = @"http://localhost:5984/relax/1"; 16 | response = @"{""$type"":""Relax.Tests.Commands.TestDoc,Relax.Tests"",""_id"":""1"",""_rev"":""1"",""Message"":""Test""}"; 17 | mockAction 18 | .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) 19 | .Returns(response) 20 | .AtMostOnce(); 21 | command = factory.CreateGetDocumentCommand(); 22 | }; 23 | } 24 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/with_get_doc_by_range.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Http; 4 | 5 | namespace Relax.Tests.Commands.GettingDocuments 6 | { 7 | public abstract class with_get_doc_by_range : with_command_factory 8 | { 9 | protected static string response; 10 | protected static string url; 11 | protected static GetDocumentsInRangeCommand command; 12 | 13 | private Establish context = () => 14 | { 15 | url = @"http://localhost:5984/relax/_all_docs?include_docs=true&startkey=""doc+1""&endkey=""doc+2"""; 16 | response = @" 17 | { 18 | total_rows: 1, 19 | offset: 0, 20 | rows: 21 | [ 22 | { 23 | doc: { 24 | $type: ""Relax.Tests.Commands.TestDoc, Relax.Tests"", 25 | _id: ""1"", 26 | _rev: ""1"", 27 | Message: ""Test"" 28 | } 29 | } 30 | ] 31 | }"; 32 | mockAction 33 | .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) 34 | .Returns(response) 35 | .AtMostOnce(); 36 | command = factory.CreateGetDocumentsInRangeCommand(); 37 | }; 38 | } 39 | } -------------------------------------------------------------------------------- /tests/Commands/GettingDocuments/with_get_poco_by_id_setup.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Http; 4 | 5 | namespace Relax.Tests.Commands.GettingDocuments 6 | { 7 | public abstract class with_get_poco_by_id_setup : with_command_factory 8 | { 9 | protected static string response; 10 | protected static string url; 11 | protected static GetDocumentCommand command; 12 | 13 | private Establish context = () => 14 | { 15 | url = @"http://localhost:5984/relax/1"; 16 | response = @"{""$type"":""Relax.Tests.Commands.MyPoco,Relax.Tests"",""_id"":""1"",""_rev"":""1"",""Message"":""Test"",""MyId"":""1""}"; 17 | mockAction 18 | .Setup(x => x.Get(Moq.It.Is(i => i.ToString() == url))) 19 | .Returns(response) 20 | .AtMostOnce(); 21 | command = factory.CreateGetDocumentCommand(); 22 | }; 23 | } 24 | } -------------------------------------------------------------------------------- /tests/Commands/ParentDoc.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Relax.Tests.Commands 4 | { 5 | public class ParentDoc : CouchDocument 6 | { 7 | public virtual string Message { get; set; } 8 | public virtual List Children { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/when_persisting_list_with_breaking_documents.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Machine.Specifications; 3 | using Newtonsoft.Json.Linq; 4 | using Relax.Config; 5 | using Relax.Impl; 6 | using StructureMap; 7 | using Symbiote.Core.Extensions; 8 | 9 | namespace Relax.Tests.Commands.SaveCommand 10 | { 11 | class when_persisting_list_with_breaking_documents : with_nested_document_list 12 | { 13 | protected static object[] result; 14 | protected static string serialized; 15 | 16 | private Because of = () => 17 | { 18 | var configuration = ObjectFactory.GetInstance(); 19 | configuration.BreakDownDocumentGraphs = true; 20 | 21 | result = testDocs.GetDocmentsFromGraph(); 22 | serialized = result[0].ToJson(); 23 | }; 24 | 25 | private It should_produce_eight_documents_total = () => 26 | result.Length.ShouldEqual(8); 27 | 28 | private It should_not_include_children_property_in_json = () => 29 | { 30 | var json = JObject.Parse(serialized); 31 | ShouldExtensionMethods.ShouldNotContain(json.Properties().Select(x => x.Name), "Children"); 32 | }; 33 | } 34 | } -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/when_saving_list_to_database.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.Commands.SaveCommand 5 | { 6 | public class when_saving_list_to_database : with_serialized_bulk_persist 7 | { 8 | protected static string url; 9 | protected static string response; 10 | 11 | private Because of = () => 12 | { 13 | url = @"http://localhost:5984/relax/_bulk_docs"; 14 | 15 | response = @"[{ ok:true, id:""doc 1"", rev: ""2""}]"; 16 | 17 | mockAction 18 | .Setup(x => x.Post(Moq.It.Is(i => url.ToString() == url), Moq.It.IsAny())) 19 | .Returns(response) 20 | .AtMostOnce(); 21 | command = factory.CreateSaveDocumentsCommand(); 22 | command.SaveAll("Couch", new object[] {testDoc}); 23 | }; 24 | 25 | private It should_call_action = () => mockAction.Verify(); 26 | private It should_update_revision = () => testDoc.DocumentRevision.ShouldEqual("2"); 27 | } 28 | } -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/when_saving_poco_to_database.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | using Relax.Impl.Serialization; 4 | using Symbiote.Core; 5 | 6 | namespace Relax.Tests.Commands.SaveCommand 7 | { 8 | public class when_saving_poco_to_database : with_poco_persistence 9 | { 10 | protected static string url; 11 | protected static string response; 12 | protected static IProvideDocumentMetadata MetadataProvider; 13 | 14 | private Because of = () => 15 | { 16 | url = @"http://localhost:5984/relax/1"; 17 | 18 | response = @"{ ok:true, id:""1"", rev: ""2""}"; 19 | 20 | MetadataProvider = Assimilate.GetInstanceOf(); 21 | MetadataProvider.Clear(); 22 | 23 | mockAction 24 | .Setup( x => x 25 | .Put( Moq.It.Is( i => url.ToString() == url ), 26 | Moq.It.IsAny() ) ) 27 | .Returns( response ) 28 | .AtMostOnce(); 29 | command = factory.CreateSaveDocumentCommand(); 30 | command.Save( "Couch", testDocs[0] ); 31 | }; 32 | 33 | private It should_call_action = () => mockAction.Verify(); 34 | private It should_update_revision = () => 35 | { 36 | MetadataProvider.GetMetadata( "1" )._rev.ShouldEqual( "2" ); 37 | }; 38 | } 39 | } -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/with_document_list.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Commands.SaveCommand 5 | { 6 | public abstract class with_document_list : with_command_factory 7 | { 8 | protected static List testDocs; 9 | 10 | private Establish context = () => 11 | { 12 | testDocs = new List() 13 | { 14 | new TestDoc() { Message = "Message1"}, 15 | new TestDoc() { Message = "Message2"}, 16 | new TestDoc() { Message = "Message3"}, 17 | }; 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/with_poco_list.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Commands.SaveCommand 5 | { 6 | public abstract class with_poco_list : with_command_factory 7 | { 8 | protected static List testDocs; 9 | 10 | private Establish context = () => 11 | { 12 | testDocs = new List() 13 | { 14 | new MyPoco() { Message = "Message1", MyId = "1" }, 15 | new MyPoco() { Message = "Message2", MyId = "2" }, 16 | new MyPoco() { Message = "Message3", MyId = "3" }, 17 | }; 18 | }; 19 | } 20 | } -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/with_poco_list_persistence.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Json; 4 | 5 | namespace Relax.Tests.Commands.SaveCommand 6 | { 7 | public abstract class with_poco_list_persistence : with_poco_list 8 | { 9 | protected static BulkPersist persist; 10 | protected static string json; 11 | protected static ISaveDocuments command; 12 | 13 | private Establish context = () => 14 | { 15 | persist = new BulkPersist(true, false, testDocs); 16 | command = factory.CreateSaveDocumentsCommand(); 17 | }; 18 | } 19 | } -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/with_poco_persistence.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Json; 4 | 5 | namespace Relax.Tests.Commands.SaveCommand 6 | { 7 | public abstract class with_poco_persistence : with_poco_list 8 | { 9 | protected static BulkPersist persist; 10 | protected static string json; 11 | protected static ISaveDocument command; 12 | 13 | private Establish context = () => 14 | { 15 | persist = new BulkPersist(true, false, testDocs); 16 | command = factory.CreateSaveDocumentCommand(); 17 | }; 18 | } 19 | } -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/with_serialized_bulk_persist.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Relax.Impl.Json; 4 | using Symbiote.Core.Serialization; 5 | 6 | namespace Relax.Tests.Commands.SaveCommand 7 | { 8 | public abstract class with_serialized_bulk_persist : with_single_parent_document 9 | { 10 | protected static BulkPersist persist; 11 | protected static string json; 12 | protected static ISaveDocuments command; 13 | 14 | private Establish context = () => 15 | { 16 | persist = new BulkPersist(true, false, new [] {testDoc}); 17 | json = persist.ToJson(); 18 | command = factory.CreateSaveDocumentsCommand(); 19 | }; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Commands/SaveCommand/with_single_parent_document.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Commands.SaveCommand 5 | { 6 | public abstract class with_single_parent_document : with_command_factory 7 | { 8 | protected static ParentDoc testDoc; 9 | 10 | private Establish context = () => 11 | { 12 | testDoc = new ParentDoc() 13 | { 14 | DocumentId = "doc 1", 15 | Message = "Parent1", 16 | Children = new List() 17 | { 18 | new TestDoc() { Message = "Child1"} 19 | } 20 | }; 21 | }; 22 | } 23 | } -------------------------------------------------------------------------------- /tests/Commands/SavingAttachments/when_saving_document_attachment.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Commands.SavingAttachments 5 | { 6 | public class when_saving_document_attachment : with_save_attachment_command 7 | { 8 | private Because of = () => 9 | { 10 | command.SaveAttachment(document, "test", "text", bytes); 11 | }; 12 | 13 | private It should_update_revision = () => 14 | document.DocumentRevision.ShouldEqual("2"); 15 | 16 | private It should_add_attachment_to_document = () => document.Attachments.Count().ShouldEqual(1); 17 | private It should_have_attachment = () => document.Attachments.First().ShouldEqual("test"); 18 | private It should_call_action = () => mockAction.VerifyAll(); 19 | } 20 | } -------------------------------------------------------------------------------- /tests/Commands/SavingAttachments/with_save_attachment_command.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Machine.Specifications; 3 | using Relax.Impl.Commands; 4 | using Relax.Impl.Http; 5 | 6 | namespace Relax.Tests.Commands.SavingAttachments 7 | { 8 | public abstract class with_save_attachment_command : with_command_factory 9 | { 10 | protected static string url; 11 | protected static string attachment; 12 | protected static byte[] bytes; 13 | protected static TestDoc document; 14 | protected static SaveAttachmentCommand command; 15 | 16 | private Establish context = () => 17 | { 18 | attachment = "123, look at me"; 19 | document = new TestDoc() {DocumentId = "1", DocumentRevision = "1"}; 20 | bytes = Encoding.UTF8.GetBytes(attachment); 21 | 22 | url = @"http://localhost:5984/relax/1/test?rev=1"; 23 | 24 | mockAction 25 | .Setup(x => x.SaveAttachment(Moq.It.Is(u => u.ToString() == url), "text", bytes)) 26 | .Returns(@"{rev:2}"); 27 | command = factory.CreateSaveAttachmentCommand(); 28 | }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Commands/TestDoc.cs: -------------------------------------------------------------------------------- 1 | using Symbiote.Core; 2 | 3 | namespace Relax.Tests.Commands 4 | { 5 | public class TestDoc : CouchDocument 6 | { 7 | public virtual string Message { get; set; } 8 | } 9 | 10 | public class MyPocoKeyAccessor : IKeyAccessor 11 | { 12 | public string GetId( MyPoco actor ) 13 | { 14 | return actor.MyId; 15 | } 16 | 17 | public void SetId( MyPoco actor, TKey key ) 18 | { 19 | actor.MyId = key.ToString(); 20 | } 21 | } 22 | 23 | 24 | public class MyPoco 25 | { 26 | public string MyId { get; set; } 27 | public string Message { get; set; } 28 | } 29 | } -------------------------------------------------------------------------------- /tests/Commands/with_command_factory.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Commands; 3 | using Symbiote.Core; 4 | 5 | namespace Relax.Tests.Commands 6 | { 7 | public abstract class with_command_factory : with_mock_http_action 8 | { 9 | protected static CouchCommandFactory factory; 10 | 11 | private Establish context = () => 12 | { 13 | factory = Assimilate.GetInstanceOf(); 14 | }; 15 | } 16 | } -------------------------------------------------------------------------------- /tests/Commands/with_configuration.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Symbiote.Core; 3 | 4 | namespace Relax.Tests.Commands 5 | { 6 | public abstract class with_configuration 7 | { 8 | private Establish context = () => 9 | { 10 | Assimilate.Initialize(); 11 | }; 12 | } 13 | } -------------------------------------------------------------------------------- /tests/Commands/with_mock_http_action.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Moq; 3 | using Relax.Impl.Http; 4 | using Symbiote.Core; 5 | using It = Machine.Specifications.It; 6 | 7 | namespace Relax.Tests.Commands 8 | { 9 | public abstract class with_mock_http_action : with_configuration 10 | { 11 | protected static Mock mockAction; 12 | protected static IHttpAction action { get { return mockAction.Object; }} 13 | 14 | private Establish context = () => 15 | { 16 | mockAction = new Mock(); 17 | Assimilate.Dependencies( x => x.For().CreateWith( c => action ) ); 18 | }; 19 | } 20 | 21 | public class when_testing_blank_action : with_mock_http_action 22 | { 23 | It should_not_be_null = () => { mockAction.ShouldNotBeNull(); }; 24 | } 25 | } -------------------------------------------------------------------------------- /tests/Configuration/TestDatabaseResolver.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Configuration 2 | { 3 | public class TestDatabaseResolver : IResolveDatabaseNames 4 | { 5 | public string GetDatabaseNameFor() 6 | { 7 | if (typeof(TModel).Equals(typeof(object))) 8 | return null; 9 | return typeof (TModel).Name.ToLower(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/Configuration/when_using_caching_with_no_expiration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Configuration 5 | { 6 | [Subject("Couch Configuration")] 7 | public class when_using_caching_with_no_expiration : with_couch_configuration 8 | { 9 | private Because of = () => configurator 10 | .Https() 11 | .Port(1234) 12 | .Server("couchdb") 13 | .TimeOut(1000) 14 | .Cache(); 15 | 16 | private It should_use_http_as_protocol = () => configuration.Protocol.ShouldEqual("https"); 17 | private It should_use_localhost_as_server = () => configuration.Server.ShouldEqual("couchdb"); 18 | private It should_use_port_5984 = () => configuration.Port.ShouldEqual(1234); 19 | private It should_not_require_preauthorization = () => configuration.Preauthorize.ShouldBeFalse(); 20 | private It should_not_have_username = () => configuration.User.ShouldBeNull(); 21 | private It should_not_have_password = () => configuration.Password.ShouldBeNull(); 22 | private It should_have_six_second_timeout = () => configuration.TimeOut.ShouldEqual(1000); 23 | private It should_not_use_cache = () => configuration.Cache.ShouldBeTrue(); 24 | private It should_not_have_cache_timeout = () => configuration.CacheLimit.ShouldEqual(TimeSpan.Zero); 25 | private It should_not_expire = () => configuration.CacheExpiration.ShouldEqual(DateTime.MaxValue); 26 | } 27 | } -------------------------------------------------------------------------------- /tests/Configuration/when_using_caching_with_time_limit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Configuration 5 | { 6 | [Subject("Couch Configuration")] 7 | public class when_using_caching_with_time_limit : with_couch_configuration 8 | { 9 | private Because of = () => configurator 10 | .Https() 11 | .Port(1234) 12 | .Server("couchdb") 13 | .TimeOut(1000) 14 | .Cache(TimeSpan.FromMinutes(15)); 15 | 16 | private It should_use_http_as_protocol = () => configuration.Protocol.ShouldEqual("https"); 17 | private It should_use_localhost_as_server = () => configuration.Server.ShouldEqual("couchdb"); 18 | private It should_use_port_5984 = () => configuration.Port.ShouldEqual(1234); 19 | private It should_not_require_preauthorization = () => configuration.Preauthorize.ShouldBeFalse(); 20 | private It should_not_have_username = () => configuration.User.ShouldBeNull(); 21 | private It should_not_have_password = () => configuration.Password.ShouldBeNull(); 22 | private It should_have_six_second_timeout = () => configuration.TimeOut.ShouldEqual(1000); 23 | private It should_not_use_cache = () => configuration.Cache.ShouldBeTrue(); 24 | private It should_have_15_minute_timeout = () => configuration.CacheLimit.ShouldEqual(TimeSpan.FromMinutes(15)); 25 | private It should_not_expire = () => configuration.CacheExpiration.ShouldEqual(new DateTime()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Configuration/when_using_defaults.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Configuration 4 | { 5 | [Subject("Couch Configuration")] 6 | public class when_using_defaults : with_couch_configuration 7 | { 8 | private It should_use_http_as_protocol = () => configuration.Protocol.ShouldEqual("http"); 9 | private It should_use_localhost_as_server = () => configuration.Server.ShouldEqual("localhost"); 10 | private It should_use_port_5984 = () => configuration.Port.ShouldEqual(5984); 11 | private It should_not_require_preauthorization = () => configuration.Preauthorize.ShouldBeFalse(); 12 | private It should_have_six_second_timeout = () => configuration.TimeOut.ShouldEqual(6000); 13 | private It should_not_use_cache = () => configuration.Cache.ShouldBeFalse(); 14 | private It should_use_solution_as_default_database = () => configuration.GetDatabaseNameForType().ShouldEqual("relax"); 15 | private It should_include_type_specification_in_json = () => configuration.IncludeTypeSpecification.ShouldBeTrue(); 16 | private It should_not_throw_exception_on_failed_calls = () => configuration.Throw404Exceptions.ShouldBeFalse(); 17 | 18 | private It should_provide_default_couch_name_for_type = () => 19 | configuration 20 | .GetDatabaseNameForType() 21 | .ShouldEqual("relax"); 22 | } 23 | } -------------------------------------------------------------------------------- /tests/Configuration/with_couch_configuration.cs: -------------------------------------------------------------------------------- 1 | using Relax.Config; 2 | 3 | namespace Relax.Tests.Configuration 4 | { 5 | public abstract class with_couch_configuration : with_couch_configurator 6 | { 7 | protected static ICouchConfiguration configuration { get { return configurator.Configuration; } } 8 | } 9 | } -------------------------------------------------------------------------------- /tests/Configuration/with_couch_configurator.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Config; 3 | using Symbiote.Core; 4 | 5 | namespace Relax.Tests.Configuration 6 | { 7 | public abstract class with_couch_configurator 8 | { 9 | protected static CouchConfigurator configurator; 10 | private Establish context = () => 11 | { 12 | configurator = new CouchConfigurator(); 13 | Assimilate.Initialize(); 14 | }; 15 | } 16 | } -------------------------------------------------------------------------------- /tests/Document/Driver.cs: -------------------------------------------------------------------------------- 1 | using Relax.Impl.Model; 2 | 3 | namespace Relax.Tests.Document 4 | { 5 | public class Driver : ComplexCouchDocument 6 | { 7 | public virtual Person Person { get; set; } 8 | public virtual string LicenseNumber { get; set; } 9 | 10 | protected void Init() 11 | { 12 | KeyGetter(x => x.Person); 13 | KeySetter((x,k) => x.Person = k); 14 | } 15 | 16 | public Driver(Person person) 17 | { 18 | Person = person; 19 | Init(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /tests/Document/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Relax.Impl.Model; 3 | using Symbiote.Core.Extensions; 4 | 5 | namespace Relax.Tests.Document 6 | { 7 | public class Person : ComplexCouchDocument 8 | { 9 | public virtual string FirstName { get; set; } 10 | public virtual string LastName { get; set; } 11 | public virtual string Social { get; set; } 12 | public virtual DateTime DateOfBirth { get; set; } 13 | 14 | protected void Init() 15 | { 16 | KeyGetter(x => "{0}, {1} born {2}".AsFormat(LastName, FirstName, DateOfBirth)); 17 | KeySetter((x,k) => {}); 18 | } 19 | 20 | public Person() 21 | { 22 | Init(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /tests/Document/when_serializing_design_document.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Symbiote.Core.Serialization; 3 | 4 | namespace Relax.Tests.Document 5 | { 6 | public class when_serializing_design_document : with_design_document 7 | { 8 | protected static string json; 9 | 10 | private Because of = () => 11 | { 12 | json = doc.ToJson(false); 13 | }; 14 | 15 | private It should_not_be_empty = () => 16 | json.ShouldNotBeEmpty(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/Document/when_using_custom_complex_key.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Symbiote.Core.Serialization; 3 | 4 | namespace Relax.Tests.Document 5 | { 6 | [Subject("custom document")] 7 | public class when_using_custom_complex_key : with_custom_document_complex_key 8 | { 9 | private static string jsonKey; 10 | private Because of = () => 11 | { 12 | jsonKey = person.ToJson(false); 13 | }; 14 | 15 | private It should_have_expected_key = () => driver.DocumentId.ShouldEqual(person); 16 | private It should_have_correct_json = () => driver.GetDocumentIdAsJson().ShouldEqual(jsonKey); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Document/when_using_custom_key.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Symbiote.Core.Extensions; 3 | 4 | namespace Relax.Tests.Document 5 | { 6 | [Subject("custom document")] 7 | public class when_using_custom_key : with_custom_document_simple_key 8 | { 9 | private It should_have_expected_key = () => person.DocumentId.ShouldEqual("{0}, {1} born {2}".AsFormat(person.LastName, person.FirstName, person.DateOfBirth)); 10 | } 11 | } -------------------------------------------------------------------------------- /tests/Document/with_custom_document_complex_key.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Symbiote.Core; 3 | 4 | namespace Relax.Tests.Document 5 | { 6 | public class with_custom_document_complex_key : with_custom_document_simple_key 7 | { 8 | protected static Driver driver; 9 | 10 | private Establish context = () => 11 | { 12 | Assimilate.Initialize(); 13 | driver = new Driver(person); 14 | }; 15 | } 16 | } -------------------------------------------------------------------------------- /tests/Document/with_custom_document_simple_key.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Document 5 | { 6 | public class with_custom_document_simple_key 7 | { 8 | protected static Person person; 9 | protected static DateTime dob = DateTime.Parse("04/01/1980"); 10 | 11 | private Establish context = () => person = new Person() 12 | { 13 | FirstName = "Dude", 14 | LastName = "Duderson", 15 | Social = "000-11-1234", 16 | DateOfBirth = dob 17 | }; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Document/with_design_document.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Model; 3 | 4 | namespace Relax.Tests.Document 5 | { 6 | public abstract class with_design_document 7 | { 8 | public static DesignDocument doc; 9 | 10 | private Establish context = () => 11 | { 12 | doc = new DesignDocument() 13 | { 14 | DocumentId = @"design/test", 15 | Views = 16 | { 17 | {"one", new DesignView() { Map = @"function(doc) { emit(doc); }"}} 18 | } 19 | }; 20 | }; 21 | } 22 | } -------------------------------------------------------------------------------- /tests/Mocks/with_mock_repository.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Mocks 2 | { 3 | class with_mock_repository 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Relax.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Relax.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("5369b63e-5150-46a8-9d2d-c63922d75028")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /tests/Relax.Lucene.Tests/Car.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Lucene.Tests 2 | { 3 | public class Car : CouchDocument 4 | { 5 | public virtual string Make { get; set; } 6 | public virtual string Model { get; set; } 7 | public virtual int Year { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /tests/Relax.Lucene.Tests/Person.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Lucene.Net.Analysis; 5 | using Lucene.Net.Analysis.Standard; 6 | using Lucene.Net.Index; 7 | using Lucene.Net.QueryParsers; 8 | using Lucene.Net.Store; 9 | using Newtonsoft.Json.Linq; 10 | using Relax.Impl.Commands; 11 | using Relax.Impl.Http; 12 | using Relax.Impl.Model; 13 | using StructureMap.Pipeline; 14 | 15 | namespace Relax.Lucene.Tests 16 | { 17 | public class Person : CouchDocument 18 | { 19 | public virtual string FirstName { get; set; } 20 | public virtual string LastName { get; set; } 21 | public virtual int Age { get; set; } 22 | public virtual List Cars { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Relax.Lucene.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Relax.Lucene.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Relax.Lucene.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c2eb3576-9100-44ee-b0f4-53af7346e7d3")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /tests/Relax.Lucene.Tests/when_searching_against_family.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Lucene.Net.Documents; 5 | using Lucene.Net.Search; 6 | using Machine.Specifications; 7 | 8 | namespace Relax.Lucene.Tests 9 | { 10 | public class when_searching_against_family : with_indexed_people 11 | { 12 | protected static Tuple result; 13 | protected static List> results; 14 | 15 | private Because of = () => 16 | { 17 | results = provider.GetDocumentsForQuery(x => 18 | x.Cars.Count > 0 && 19 | x.Cars.Any(c => c.Year == 2010) 20 | ).ToList(); 21 | result = results[0]; 22 | }; 23 | 24 | private It should_produce_1_result = () => 25 | results.Count.ShouldEqual(1); 26 | } 27 | } -------------------------------------------------------------------------------- /tests/Relax.Lucene.Tests/with_domain_model.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Machine.Specifications; 4 | using Symbiote.Core.Extensions; 5 | 6 | namespace Relax.Lucene.Tests 7 | { 8 | public abstract class with_domain_model : with_lucene 9 | { 10 | protected static List people; 11 | protected static List personDocuments; 12 | 13 | private Establish context = () => 14 | { 15 | people = DomainHelper.Create_Family_With_Two_Cars(); 16 | personDocuments = people.Select(x => x.ToJson(false)).ToList(); 17 | }; 18 | } 19 | } -------------------------------------------------------------------------------- /tests/Relax.Lucene.Tests/with_indexed_people.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Machine.Specifications; 3 | using Symbiote.Lucene; 4 | 5 | namespace Relax.Lucene.Tests 6 | { 7 | public abstract class with_indexed_people : with_domain_model 8 | { 9 | protected static ILuceneSearchProvider provider; 10 | 11 | private Establish context = () => 12 | { 13 | 14 | provider = luceneServiceFactory.GetSearchProviderForIndex("test"); 15 | provider.IndexWriter.DeleteAll(); 16 | provider.IndexWriter.ExpungeDeletes(); 17 | Parallel.ForEach(personDocuments, IndexJson); 18 | }; 19 | 20 | protected static void IndexJson(string x) 21 | { 22 | var observer = luceneServiceFactory.GetIndexingObserverForIndex("test"); 23 | var visitor = new JsonVisitor(); 24 | visitor.Subscribe(observer); 25 | visitor.Accept(x); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /tests/Relax.Lucene.Tests/with_lucene.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using StructureMap; 3 | using Symbiote.Core; 4 | using Symbiote.Lucene; 5 | using Symbiote.StructureMap; 6 | 7 | namespace Relax.Lucene.Tests 8 | { 9 | public abstract class with_lucene 10 | { 11 | protected static ILuceneServiceFactory luceneServiceFactory; 12 | 13 | private Establish context = () => 14 | { 15 | Assimilate.Core().Relax().Lucene(); 16 | luceneServiceFactory = ObjectFactory.GetInstance(); 17 | }; 18 | } 19 | } -------------------------------------------------------------------------------- /tests/Repository/when_deleting_attachment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | using Relax.Tests.Commands; 4 | 5 | namespace Relax.Tests.Repository 6 | { 7 | public class when_deleting_attachment : with_delete_attachment_command 8 | { 9 | private static Exception exception; 10 | 11 | private Because of = () => 12 | { 13 | exception = 14 | Catch.Exception( 15 | () => repository.DeleteAttachment(document, attachmentName)); 16 | }; 17 | 18 | private It should_delete_attachment_without_exception = () => exception.ShouldBeNull(); 19 | private It should_call_command_correctly = () => commandMock.VerifyAll(); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/Repository/when_deleting_document.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | using Relax.Impl.Json; 4 | 5 | namespace Relax.Tests.Repository 6 | { 7 | public class when_deleting_document_by_id_and_rev : with_delete_document_command_by_id_and_rev 8 | { 9 | private static Exception exception = null; 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception( 13 | () => repository.DeleteDocument(id, "1") 14 | ); 15 | }; 16 | 17 | private It should_delete_document_without_exception = () => exception.ShouldBeNull(); 18 | private It should_call_delete_correctly = () => commandMock.Verify(x => x.Delete(couchUri)); 19 | } 20 | } -------------------------------------------------------------------------------- /tests/Repository/when_deleting_document_by_id.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | using Relax.Tests.Commands; 4 | 5 | namespace Relax.Tests.Repository 6 | { 7 | public class when_deleting_document_by_id : with_delete_document_command_by_id 8 | { 9 | private static Exception exception = null; 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception( 13 | () => repository.DeleteDocument(id) 14 | ); 15 | }; 16 | 17 | private It should_delete_document_without_exception = () => exception.ShouldBeNull(); 18 | private It should_call_delete_correctly = () => commandMock.VerifyAll(); 19 | } 20 | } -------------------------------------------------------------------------------- /tests/Repository/when_deleting_document_by_id_and_rev.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Repository 5 | { 6 | public class when_deleting_document_by_id_and_rev : with_delete_document_command_by_id_and_rev 7 | { 8 | private static Exception exception = null; 9 | private Because of = () => 10 | { 11 | exception = Catch.Exception( 12 | () => repository.DeleteDocument(id, "1") 13 | ); 14 | }; 15 | 16 | private It should_delete_document_without_exception = () => exception.ShouldBeNull(); 17 | private It should_call_delete_correctly = () => commandMock.VerifyAll(); 18 | } 19 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_a_document_by_key.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Repository 5 | { 6 | public class when_getting_a_document_by_key : with_get_document_by_key_command 7 | { 8 | private static Exception exception = null; 9 | private static TestDocument record; 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception( 13 | () => record = repository.Get(id) 14 | ); 15 | }; 16 | 17 | private It should_get_document_without_exception = () => exception.ShouldBeNull(); 18 | private It should_get_record = () => 19 | { 20 | record.DocumentId.ShouldEqual(id); 21 | record.Message.ShouldEqual("Hello"); 22 | record.DocumentRevision.ShouldEqual("1"); 23 | }; 24 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 25 | } 26 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_a_document_by_key_and_rev.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Repository 5 | { 6 | public class when_getting_a_document_by_key_and_rev : with_get_document_by_key_and_rev_command 7 | { 8 | private static Exception exception = null; 9 | private static TestDocument record; 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception( 13 | () => record = repository.Get(id, "2") 14 | ); 15 | }; 16 | 17 | private It should_get_document_without_exception = () => exception.ShouldBeNull(); 18 | private It should_get_record = () => 19 | { 20 | record.DocumentId.ShouldEqual(id); 21 | record.Message.ShouldEqual("Hello"); 22 | record.DocumentRevision.ShouldEqual("2"); 23 | }; 24 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 25 | } 26 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_all_docuemnts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Machine.Specifications; 4 | 5 | namespace Relax.Tests.Repository 6 | { 7 | public class when_getting_all_docuemnts : with_get_all_documents_command 8 | { 9 | private static Exception exception = null; 10 | private static IList records; 11 | private Because of = () => 12 | { 13 | exception = Catch.Exception( 14 | () => records = repository.GetAll() 15 | ); 16 | }; 17 | 18 | private It should_get_documents_without_exception = () => exception.ShouldBeNull(); 19 | private It should_get_one_record = () => records.Count.ShouldEqual(1); 20 | private It should_get_right_record = () => 21 | { 22 | records[0].DocumentId.ShouldEqual(id); 23 | records[0].Message.ShouldEqual("Hello"); 24 | records[0].DocumentRevision.ShouldEqual("2"); 25 | }; 26 | private It should_call_get_correctly = () => commandMock.Verify(x => x.Get(couchUri)); 27 | } 28 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_all_docuemnts_with_paging.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Machine.Specifications; 4 | 5 | namespace Relax.Tests.Repository 6 | { 7 | public class when_getting_all_docuemnts_with_paging : with_get_all_documents_paged_command 8 | { 9 | private static Exception exception = null; 10 | private static IList records; 11 | private Because of = () => 12 | { 13 | exception = Catch.Exception( 14 | () => records = repository.GetAll(10, 1) 15 | ); 16 | }; 17 | 18 | private It should_get_documents_without_exception = () => exception.ShouldBeNull(); 19 | private It should_get_one_record = () => records.Count.ShouldEqual(1); 20 | private It should_get_right_record = () => 21 | { 22 | records[0].DocumentId.ShouldEqual(id); 23 | records[0].Message.ShouldEqual("Hello"); 24 | records[0].DocumentRevision.ShouldEqual("2"); 25 | }; 26 | private It should_call_get_correctly = () => commandMock.Verify(x => x.Get(couchUri)); 27 | } 28 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_all_documents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Machine.Specifications; 4 | 5 | namespace Relax.Tests.Repository 6 | { 7 | public class when_getting_all_documents : with_get_all_documents_command 8 | { 9 | private static Exception exception = null; 10 | private static IList records; 11 | private Because of = () => 12 | { 13 | exception = Catch.Exception( 14 | () => records = repository.GetAll() 15 | ); 16 | }; 17 | 18 | private It should_get_documents_without_exception = () => exception.ShouldBeNull(); 19 | private It should_get_one_record = () => records.Count.ShouldEqual(1); 20 | private It should_get_right_record = () => 21 | { 22 | records[0].DocumentId.ShouldEqual(id); 23 | records[0].Message.ShouldEqual("Hello"); 24 | records[0].DocumentRevision.ShouldEqual("2"); 25 | }; 26 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 27 | } 28 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_all_documents_with_paging.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Machine.Specifications; 4 | 5 | namespace Relax.Tests.Repository 6 | { 7 | public class when_getting_all_documents_with_paging : with_get_all_documents_paged_command 8 | { 9 | private static Exception exception = null; 10 | private static IList records; 11 | private Because of = () => 12 | { 13 | exception = Catch.Exception( 14 | () => records = repository.GetAll(10, 1) 15 | ); 16 | }; 17 | 18 | private It should_get_documents_without_exception = () => exception.ShouldBeNull(); 19 | private It should_get_one_record = () => records.Count.ShouldEqual(1); 20 | private It should_get_right_record = () => 21 | { 22 | records[0].DocumentId.ShouldEqual(id); 23 | records[0].Message.ShouldEqual("Hello"); 24 | records[0].DocumentRevision.ShouldEqual("2"); 25 | }; 26 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 27 | } 28 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_attachment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Machine.Specifications; 4 | using Relax.Tests.Commands; 5 | 6 | namespace Relax.Tests.Repository 7 | { 8 | public class when_getting_attachment : with_get_attachment 9 | { 10 | protected static Tuple attachmentResult; 11 | protected static string contentResult; 12 | protected static Exception exception; 13 | 14 | private Because of = () => 15 | { 16 | exception = 17 | Catch.Exception( 18 | () => attachmentResult = repository.GetAttachment("1", "myattachment")); 19 | contentResult = Encoding.UTF8.GetString(attachmentResult.Item2); 20 | }; 21 | 22 | private It should_get_correct_attachment = () => attachmentResult.Item1.ShouldEqual("myattachment"); 23 | private It should_have_correct_content = () => contentResult.ShouldEqual(content); 24 | private It should_get_documents_without_exception = () => exception.ShouldBeNull(); 25 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 26 | } 27 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_documents_by_id.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Machine.Specifications; 4 | using Relax.Tests.Commands; 5 | 6 | namespace Relax.Tests.Repository 7 | { 8 | public class when_getting_documents_by_id : with_get_documents_by_keys 9 | { 10 | protected static IList records; 11 | protected static Exception exception; 12 | 13 | private Because of = () => 14 | { 15 | exception = 16 | Catch.Exception( 17 | () => records = repository.GetAllByKeys(new object[] { "1" })); 18 | }; 19 | 20 | private It should_get_documents_without_exception = () => exception.ShouldBeNull(); 21 | private It should_get_one_record = () => records.Count.ShouldEqual(1); 22 | private It should_get_right_record = () => 23 | { 24 | records[0].DocumentId.ShouldEqual("1"); 25 | records[0].Message.ShouldEqual("Hello"); 26 | records[0].DocumentRevision.ShouldEqual("2"); 27 | }; 28 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 29 | } 30 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_documents_by_range.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Machine.Specifications; 4 | using Relax.Tests.Commands; 5 | 6 | namespace Relax.Tests.Repository 7 | { 8 | public class when_getting_documents_by_range : with_get_documents_by_range 9 | { 10 | protected static IList records; 11 | protected static Exception exception; 12 | 13 | private Because of = () => 14 | { 15 | exception = 16 | Catch.Exception( 17 | () => records = repository.GetAllBetweenKeys("1","2")); 18 | }; 19 | 20 | private It should_get_documents_without_exception = () => exception.ShouldBeNull(); 21 | private It should_get_one_record = () => records.Count.ShouldEqual(1); 22 | private It should_get_right_record = () => 23 | { 24 | records[0].DocumentId.ShouldEqual("1"); 25 | records[0].Message.ShouldEqual("Hello"); 26 | records[0].DocumentRevision.ShouldEqual("2"); 27 | }; 28 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 29 | } 30 | } -------------------------------------------------------------------------------- /tests/Repository/when_getting_from_view.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Machine.Specifications; 4 | using Relax.Tests.Commands; 5 | 6 | namespace Relax.Tests.Repository 7 | { 8 | public class when_getting_from_view : with_from_view_command 9 | { 10 | protected static IList result; 11 | private static Exception exception = null; 12 | 13 | private Because of = () => 14 | { 15 | exception = 16 | Catch.Exception( () => 17 | { 18 | result = repository.FromView( "test", "test", x => x.NoReduce() ); 19 | } ); 20 | }; 21 | 22 | private It should_get_view_result_without_exception = () => exception.ShouldBeNull(); 23 | private It should_call_get_action = () => commandMock.VerifyAll(); 24 | private It should_get_one_record = () => result.Count.ShouldEqual(1); 25 | } 26 | } -------------------------------------------------------------------------------- /tests/Repository/when_saving_a_document.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Repository 5 | { 6 | public class when_saving_a_document : with_save_model_command 7 | { 8 | private static Exception exception = null; 9 | 10 | private Because of = () => { 11 | exception = Catch.Exception(() => 12 | repository.Save(document)); 13 | }; 14 | 15 | private It should_save_document_without_exception = () => exception.ShouldBeNull(); 16 | private It should_update_revision = () => document.DocumentRevision.ShouldEqual("3"); 17 | private It should_call_put_correctly = () => commandMock.VerifyAll(); 18 | } 19 | } -------------------------------------------------------------------------------- /tests/Repository/when_saving_documents.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Repository 5 | { 6 | public class when_saving_documents : with_save_models_command 7 | { 8 | private static Exception exception = null; 9 | 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception( 13 | () => repository.SaveAll(new [] {document}) 14 | ); 15 | }; 16 | 17 | private It should_save_documents_without_exception = () => exception.ShouldBeNull(); 18 | private It should_update_revision = () => document.DocumentRevision.ShouldEqual("3"); 19 | private It should_call_post_correctly = () => commandMock.VerifyAll(); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/Repository/with_delete_document_command.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | using Relax.Impl; 4 | using Relax.Impl.Http; 5 | 6 | namespace Relax.Tests.Repository 7 | { 8 | public abstract class with_delete_document_command : with_document_repository 9 | { 10 | protected static Guid id; 11 | 12 | private Establish context = () => 13 | { 14 | id = Guid.NewGuid(); 15 | uri = new CouchUri("http", "localhost", 5984, "relax").IdAndRev(id, "1"); 16 | commandMock.Setup(x => x.Delete(couchUri)); 17 | WireUpCommandMock(commandMock.Object); 18 | }; 19 | } 20 | } -------------------------------------------------------------------------------- /tests/Repository/with_delete_document_command_by_id_and_rev.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | using Moq; 4 | using Relax.Impl.Http; 5 | using Relax.Impl.Repository; 6 | using Symbiote.Core; 7 | 8 | namespace Relax.Tests.Repository 9 | { 10 | public abstract class with_delete_document_command_by_id_and_rev : with_configuration 11 | { 12 | protected static Guid id; 13 | protected static Mock commandMock; 14 | protected static CouchUri uri; 15 | protected static IDocumentRepository repository; 16 | protected static CouchUri couchUri 17 | { 18 | get 19 | { 20 | return Moq.It.Is( u => u.ToString().Equals( uri.ToString() ) ); 21 | } 22 | } 23 | 24 | private Establish context = () => 25 | { 26 | repository = Assimilate.GetInstanceOf(); 27 | commandMock = new Mock(); 28 | //id = Guid.NewGuid(); 29 | id = Guid.Parse( "00000000-0000-0000-0000-000000000001" ); 30 | uri = new CouchUri("http", "localhost", 5984, "relax").IdAndRev(id, "1"); 31 | commandMock.Setup( x => x.Delete( couchUri ) ); 32 | WireUpCommandMock( commandMock.Object ); 33 | }; 34 | } 35 | } -------------------------------------------------------------------------------- /tests/Repository/with_document_repository.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Moq; 3 | using Symbiote.Core; 4 | 5 | namespace Relax.Tests.Repository 6 | { 7 | //public abstract class with_document_repository : with_configuration 8 | //{ 9 | // protected static IDocumentRepository repository; 10 | // protected static CouchUri uri; 11 | // //protected static Mock commandMock; 12 | // protected static CouchUri couchUri 13 | // { 14 | // get 15 | // { 16 | // return Moq.It.Is(u => u.ToString().Equals(uri.ToString())); 17 | // } 18 | // } 19 | 20 | // private Establish context = () => 21 | // { 22 | // //commandMock = new Mock(); 23 | // repository = Assimilate.GetInstanceOf(); 24 | // }; 25 | //} 26 | 27 | 28 | } -------------------------------------------------------------------------------- /tests/Repository/with_test_document.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Repository 4 | { 5 | public abstract class with_test_document : with_configuration 6 | { 7 | protected static TestDocument document; 8 | private Establish context = () => { document = new TestDocument() {Message = "hi"}; }; 9 | } 10 | } -------------------------------------------------------------------------------- /tests/Serialization/ComplexDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Relax.Impl.Model; 3 | 4 | namespace Relax.Tests.Serialization 5 | { 6 | [Serializable] 7 | public class ComplexDocument : ComplexCouchDocument 8 | { 9 | public virtual string Message { get; set; } 10 | public virtual DateTime Time { get; set; } 11 | 12 | public ComplexDocument() 13 | { 14 | _documentId = Guid.NewGuid(); 15 | } 16 | 17 | public ComplexDocument(string message) 18 | { 19 | _documentId = Guid.NewGuid(); 20 | Message = message; 21 | Time = DateTime.Now; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /tests/Serialization/Filtering/ClassA.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Relax.Tests.Serialization.Filtering 4 | { 5 | public class ClassA : CouchDocument 6 | { 7 | public ClassB B { get; set; } 8 | public List Cs { get; set; } 9 | public List Ds { get; set; } 10 | public ClassE E { get; set; } 11 | public List Fs { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /tests/Serialization/Filtering/ClassB.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Serialization.Filtering 2 | { 3 | public class ClassB : CouchDocument 4 | { 5 | public string Message { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /tests/Serialization/Filtering/ClassC.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Serialization.Filtering 2 | { 3 | public class ClassC : ClassB 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /tests/Serialization/Filtering/ClassD.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Serialization.Filtering 2 | { 3 | public class ClassD : ClassC 4 | { 5 | public string Message { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /tests/Serialization/Filtering/ClassE.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Serialization.Filtering 2 | { 3 | public class ClassE 4 | { 5 | public string Message { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /tests/Serialization/Filtering/ClassF.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Serialization.Filtering 2 | { 3 | public class ClassF 4 | { 5 | public string Message { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /tests/Serialization/Test.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Serialization 2 | { 3 | public class Test 4 | { 5 | public string Id { get; set; } 6 | public string Rev { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /tests/Serialization/when_deserializing_complex_document.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Symbiote.Core.Serialization; 3 | 4 | namespace Relax.Tests.Serialization 5 | { 6 | public class when_deserializing_complex_document : with_complex_document 7 | { 8 | protected static ComplexDocument document; 9 | 10 | private Because of = () => 11 | { 12 | document = json.FromJson(); 13 | }; 14 | 15 | private It should_have_correct_revision = () => 16 | document.DocumentRevision.ShouldEqual("1-39759d4fdfa5e162acec9551b741c82e"); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Serialization/when_deserializing_complex_view.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Machine.Specifications; 3 | using Relax.Impl.Json; 4 | using Symbiote.Core.Serialization; 5 | 6 | namespace Relax.Tests.Serialization 7 | { 8 | public class when_deserializing_complex_view : with_complex_view_result 9 | { 10 | protected static ViewResult documents; 11 | 12 | private Because of = () => 13 | { 14 | documents = json.FromJson>(); 15 | }; 16 | 17 | private It should_have_correct_revision = () => 18 | documents.GetList().ToList()[0].DocumentRevision.ShouldEqual("1-39759d4fdfa5e162acec9551b741c82e"); 19 | } 20 | } -------------------------------------------------------------------------------- /tests/Serialization/when_deserializing_view_result_and_document_excluded.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Json; 3 | using Symbiote.Core.Serialization; 4 | 5 | namespace Relax.Tests.Serialization 6 | { 7 | public class when_deserializing_view_result_and_document_excluded : with_view_result_and_no_documents 8 | { 9 | protected static ViewResult result; 10 | 11 | private Because of = () => 12 | { 13 | result = viewResultJson.FromJson>(); 14 | }; 15 | 16 | private It should_have_document_message = () => 17 | result.Rows[0].Model.Message.ShouldEqual("Hi"); 18 | } 19 | } -------------------------------------------------------------------------------- /tests/Serialization/when_deserializing_view_result_with_documents_included.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Json; 3 | using Symbiote.Core.Serialization; 4 | 5 | namespace Relax.Tests.Serialization 6 | { 7 | public class when_deserializing_view_result_with_documents_included : with_view_result_and_documents_included 8 | { 9 | protected static ViewResult result; 10 | 11 | private Because of = () => 12 | { 13 | result = viewResultJson.FromJson>(); 14 | }; 15 | 16 | private It should_have_document_message = () => 17 | result.Rows[0].Model.Message.ShouldEqual("Howdy"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Serialization/when_trying_custom_serializer.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Machine.Specifications; 3 | using Newtonsoft.Json; 4 | using Relax.Impl.Serialization; 5 | 6 | namespace Relax.Tests.Serialization 7 | { 8 | public class when_trying_custom_serializer : with_single_document 9 | { 10 | protected static Test test; 11 | 12 | private Because of = () => 13 | { 14 | var resolver = new ConventionDeserializationContractResolver(new DocumentConventions()); 15 | var serializer = new JsonSerializer() 16 | { 17 | ContractResolver = resolver 18 | }; 19 | var txtReader = new StringReader(json); 20 | var jsonReader = new JsonTextReader(txtReader); 21 | test = serializer.Deserialize(jsonReader, typeof(Test)) as Test; 22 | }; 23 | 24 | private It should_populate_id = () => test.Id.ShouldEqual("test"); 25 | private It should_populate_rev = () => test.Rev.ShouldEqual("10"); 26 | } 27 | } -------------------------------------------------------------------------------- /tests/Serialization/with_assimilation.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Serialization 2 | { 3 | public abstract class with_assimilation 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/Serialization/with_bulk_insert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | using Relax.Impl.Json; 4 | using Relax.Tests.Document; 5 | 6 | namespace Relax.Tests.Serialization 7 | { 8 | public abstract class with_bulk_insert 9 | { 10 | protected static BulkPersist bulkAction; 11 | 12 | private Establish context = () => 13 | { 14 | //Assimilate.Core(); 15 | bulkAction = new BulkPersist(true, false, 16 | new object[] 17 | { 18 | new Person() 19 | { 20 | DateOfBirth = DateTime.Now, 21 | FirstName = "Roy", 22 | LastName = "Orbison", 23 | Social = "Wouldn't You like to know : p" 24 | } 25 | } 26 | ); 27 | }; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Serialization/with_complex_document.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.Serialization 2 | { 3 | public class with_complex_document 4 | { 5 | protected static string json = 6 | @"{ 7 | ""_id"": ""0b29aa9a-589e-467e-869b-864968aa9532"", 8 | ""_rev"": ""1-39759d4fdfa5e162acec9551b741c82e"", 9 | ""$id"": ""7"", 10 | ""$type"": ""Relax.Tests.Serialization.ComplexDocument, Relax.Tests"", 11 | ""Message"": ""Document 3"", 12 | ""Time"": ""2010-06-02T14:07:35.2683188-05:00"", 13 | ""$doc_type"": ""ComplexDocument"" 14 | }"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/Serialization/with_single_document.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Serialization 4 | { 5 | public abstract class with_single_document 6 | { 7 | protected static string json; 8 | 9 | private Establish context = () => 10 | { 11 | json = @"{ _id:""test"", _rev:""10""}"; 12 | }; 13 | } 14 | } -------------------------------------------------------------------------------- /tests/Serialization/with_view_result_and_documents_included.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Serialization 4 | { 5 | public abstract class with_view_result_and_documents_included 6 | { 7 | protected static string viewResultJson; 8 | 9 | private Establish context = () => 10 | { 11 | viewResultJson = @" 12 | { 13 | rows: 14 | [ 15 | { 16 | id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"", 17 | key: [""Test"",1], 18 | value: { 19 | _id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"", 20 | _rev:""1-7b9bfed448e9339c7afdbfd42964b02e"", 21 | Message: ""Hi"" 22 | }, 23 | doc: { 24 | _id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"", 25 | _rev:""1-7b9bfed448e9339c7afdbfd42964b02e"", 26 | Message: ""Howdy"" 27 | } 28 | } 29 | ] 30 | } 31 | "; 32 | }; 33 | } 34 | } -------------------------------------------------------------------------------- /tests/Serialization/with_view_result_and_no_documents.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.Serialization 4 | { 5 | public abstract class with_view_result_and_no_documents 6 | { 7 | protected static string viewResultJson; 8 | 9 | private Establish context = () => 10 | { 11 | viewResultJson = @" 12 | { 13 | rows: 14 | [ 15 | { 16 | id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"", 17 | key: {thingy:""Test"",thingy2:1}, 18 | value: { 19 | _id: ""8dd62969-9070-4f34-b478-e3e7e1c792aa"", 20 | _rev:""1-7b9bfed448e9339c7afdbfd42964b02e"", 21 | Message: ""Hi"" 22 | } 23 | } 24 | ] 25 | } 26 | "; 27 | }; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Server/when_checking_database_existence.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_checking_database_existence : with_check_database_exists_command 7 | { 8 | private static Exception exception = null; 9 | private static bool exists = false; 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception( 13 | () => exists = server.DatabaseExists() 14 | ); 15 | }; 16 | 17 | private It should_check_without_exception = () => exception.ShouldBeNull(); 18 | private It should_find_database = () => exists.ShouldBeTrue(); 19 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/Server/when_cleaning_up_views.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_cleaning_up_views : with_view_cleanup_command 7 | { 8 | private static Exception exception; 9 | 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception(() => server.CleanViews()); 13 | }; 14 | 15 | private It should_not_throw_exception = () => exception.ShouldBeNull(); 16 | private It should_call_clean_view_command = () => commandMock.VerifyAll(); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Server/when_compacting_db.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_compacting_db : with_db_compaction 7 | { 8 | private static Exception exception; 9 | 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception(() => server.CompactDatabase()); 13 | }; 14 | 15 | private It should_not_throw_exception = () => exception.ShouldBeNull(); 16 | private It should_call_clean_view_command = () => commandMock.VerifyAll(); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Server/when_compacting_view.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_compacting_view : with_view_compaction 7 | { 8 | private static Exception exception; 9 | 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception(() => server.CompactView("testView")); 13 | }; 14 | 15 | private It should_not_throw_exception = () => exception.ShouldBeNull(); 16 | private It should_call_clean_view_command = () => commandMock.VerifyAll(); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Server/when_copying_from_any_database.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_copying_from_any_database : with_copy_replication 7 | { 8 | protected static Exception exception; 9 | 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception(() => server.CopyDatabase(sourceUri, targetUri)); 13 | }; 14 | 15 | private It should_copy_without_exceptions = () => exception.ShouldBeNull(); 16 | private It should_call_replicate_via_post = () => commandMock.VerifyAll(); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Server/when_copying_from_local_database.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_copying_from_local_database : with_copy_replication 7 | { 8 | protected static Exception exception; 9 | 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception(() => server.CopyDatabase(targetUri)); 13 | }; 14 | 15 | private It should_copy_without_exceptions = () => exception.ShouldBeNull(); 16 | private It should_call_replicate_via_post = () => commandMock.VerifyAll(); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Server/when_creating_database.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_creating_database : with_create_database_command 7 | { 8 | private static Exception exception = null; 9 | private Because of = () => 10 | { 11 | exception = Catch.Exception( 12 | () => server.CreateDatabase() 13 | ); 14 | }; 15 | 16 | private It should_create_database_without_exception = () => exception.ShouldBeNull(); 17 | private It should_call_put_correctly = () => commandMock.VerifyAll(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Server/when_deleteing_database.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_deleteing_database : with_create_delete_database_command 7 | { 8 | private static Exception exception = null; 9 | private Because of = () => 10 | { 11 | exception = Catch.Exception( 12 | () => server.DeleteDatabase() 13 | ); 14 | }; 15 | 16 | private It should_delete_database_without_exception = () => exception.ShouldBeNull(); 17 | private It should_call_delete_correctly = () => commandMock.VerifyAll(); 18 | } 19 | } -------------------------------------------------------------------------------- /tests/Server/when_getting_list_of_databases.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Machine.Specifications; 4 | 5 | namespace Relax.Tests.Server 6 | { 7 | public class when_getting_list_of_databases : with_list_databases_command 8 | { 9 | private static Exception exception = null; 10 | private static IList databases; 11 | private Because of = () => 12 | { 13 | exception = Catch.Exception( 14 | () => databases = server.DatabaseList 15 | ); 16 | }; 17 | 18 | private It should_get_list_without_exception = () => exception.ShouldBeNull(); 19 | private It should_get_database_list = () => databases 20 | .ShouldContain("one", "two", "three"); 21 | private It should_call_get_correctly = () => commandMock.VerifyAll(); 22 | } 23 | } -------------------------------------------------------------------------------- /tests/Server/when_starting_replication_from_any_database.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_starting_replication_from_any_database : with_continuous_replication 7 | { 8 | protected static Exception exception; 9 | 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception(() => server.Replicate(sourceUri, targetUri)); 13 | }; 14 | 15 | private It should_replication_without_exceptions = () => exception.ShouldBeNull(); 16 | private It should_call_replicate_via_post = () => commandMock.VerifyAll(); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Server/when_starting_replication_from_local_database.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public class when_starting_replication_from_local_database : with_continuous_replication 7 | { 8 | protected static Exception exception; 9 | 10 | private Because of = () => 11 | { 12 | exception = Catch.Exception(() => server.Replicate(targetUri)); 13 | }; 14 | 15 | private It should_replication_without_exceptions = () => exception.ShouldBeNull(); 16 | private It should_call_replicate_via_post = () => commandMock.VerifyAll(); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Server/with_check_database_exists_command.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public abstract class with_check_database_exists_command : with_couch_server 7 | { 8 | private Establish context = () => 9 | { 10 | uri = new CouchUri("http", "localhost", 5984, "relax"); 11 | commandMock.Setup(x => x.Get(couchUri)).Returns("true"); 12 | WireUpCommandMock(commandMock.Object); 13 | }; 14 | } 15 | } -------------------------------------------------------------------------------- /tests/Server/with_continuous_replication.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | using Relax.Impl.Json; 4 | using Symbiote.Core.Serialization; 5 | 6 | namespace Relax.Tests.Server 7 | { 8 | public abstract class with_continuous_replication : with_couch_server 9 | { 10 | protected static CouchUri targetUri; 11 | protected static CouchUri sourceUri; 12 | protected static string replication; 13 | 14 | private Establish context = () => 15 | { 16 | uri = new CouchUri("http", "localhost", 5984).Replicate(); 17 | sourceUri = new CouchUri("http", "localhost", 5984, "relax"); 18 | targetUri = new CouchUri("admin", "password", "http", "remotehost", 5984); 19 | 20 | replication = ReplicationCommand.Continuous(sourceUri, targetUri).ToJson(false); 21 | 22 | commandMock 23 | .Setup(x => x.Post(couchUri, replication)); 24 | WireUpCommandMock(commandMock.Object); 25 | }; 26 | } 27 | } -------------------------------------------------------------------------------- /tests/Server/with_copy_replication.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | using Relax.Impl.Json; 4 | using Symbiote.Core.Serialization; 5 | 6 | namespace Relax.Tests.Server 7 | { 8 | public abstract class with_copy_replication : with_couch_server 9 | { 10 | protected static CouchUri targetUri; 11 | protected static CouchUri sourceUri; 12 | protected static string replication; 13 | 14 | private Establish context = () => 15 | { 16 | uri = new CouchUri("http", "localhost", 5984).Replicate(); 17 | sourceUri = new CouchUri("http", "localhost", 5984, "relax"); 18 | targetUri = new CouchUri("admin", "password", "http", "remotehost", 5984); 19 | 20 | replication = ReplicationCommand.Once(sourceUri, targetUri).ToJson(false); 21 | 22 | commandMock 23 | .Setup(x => x.Post(couchUri, replication)); 24 | WireUpCommandMock(commandMock.Object); 25 | }; 26 | } 27 | } -------------------------------------------------------------------------------- /tests/Server/with_couch_server.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Moq; 3 | using Relax.Impl; 4 | using Relax.Impl.Http; 5 | using Relax.Impl.Repository; 6 | using Symbiote.Core; 7 | 8 | namespace Relax.Tests.Server 9 | { 10 | public abstract class with_couch_server : with_configuration 11 | { 12 | protected static ICouchServer server; 13 | protected static CouchUri uri; 14 | protected static Mock commandMock; 15 | protected static CouchUri couchUri 16 | { 17 | get 18 | { 19 | //var config = Assimilate.GetInstanceOf(); 20 | //config.Cache = false; 21 | Assimilate.Dependencies(x => x.For().Use()); 22 | return Moq.It.Is(u => u.ToString().Equals(uri.ToString())); 23 | } 24 | } 25 | 26 | private Establish context = () => 27 | { 28 | commandMock = new Mock(); 29 | server = Assimilate.GetInstanceOf(); 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Server/with_create_database_command.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public abstract class with_create_database_command : with_couch_server 7 | { 8 | private Establish context = () => 9 | { 10 | uri = new CouchUri("http", "localhost", 5984, "relax"); 11 | commandMock.Setup(x => x.Put(couchUri)); 12 | WireUpCommandMock(commandMock.Object); 13 | }; 14 | } 15 | } -------------------------------------------------------------------------------- /tests/Server/with_create_delete_database_command.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public abstract class with_create_delete_database_command : with_couch_server 7 | { 8 | private Establish context = () => 9 | { 10 | uri = new CouchUri("http", "localhost", 5984, "relax"); 11 | commandMock.Setup(x => x.Delete(couchUri)); 12 | WireUpCommandMock(commandMock.Object); 13 | }; 14 | } 15 | } -------------------------------------------------------------------------------- /tests/Server/with_db_compaction.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public abstract class with_db_compaction : with_couch_server 7 | { 8 | private Establish context = () => 9 | { 10 | uri = new CouchUri("http", "localhost", 5984, "relax") 11 | .Compact(); 12 | commandMock.Setup(x => x.Post(couchUri)); 13 | WireUpCommandMock(commandMock.Object); 14 | }; 15 | } 16 | } -------------------------------------------------------------------------------- /tests/Server/with_list_databases_command.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public abstract class with_list_databases_command : with_couch_server 7 | { 8 | private Establish context = () => 9 | { 10 | uri = new CouchUri("http", "localhost", 5984, "_all_dbs"); 11 | commandMock.Setup(x => x.Get(couchUri)) 12 | .Returns("[ \"one\", \"two\", \"three\" ]"); 13 | WireUpCommandMock(commandMock.Object); 14 | }; 15 | } 16 | } -------------------------------------------------------------------------------- /tests/Server/with_view_cleanup_command.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public abstract class with_view_cleanup_command : with_couch_server 7 | { 8 | private Establish context = () => 9 | { 10 | uri = new CouchUri("http", "localhost", 5984, "relax") 11 | .CleanupViews(); 12 | commandMock.Setup(x => x.Post(couchUri)); 13 | WireUpCommandMock(commandMock.Object); 14 | }; 15 | } 16 | } -------------------------------------------------------------------------------- /tests/Server/with_view_compaction.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.Server 5 | { 6 | public abstract class with_view_compaction : with_couch_server 7 | { 8 | private Establish context = () => 9 | { 10 | uri = new CouchUri("http", "localhost", 5984, "relax") 11 | .CompactView("testView"); 12 | commandMock.Setup(x => x.Post(couchUri)); 13 | WireUpCommandMock(commandMock.Object); 14 | }; 15 | } 16 | } -------------------------------------------------------------------------------- /tests/SimpleDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Relax.Tests 4 | { 5 | public class SimpleDocument : CouchDocument 6 | { 7 | public virtual string Message { get; set; } 8 | public virtual DateTime CreatedOn { get; set; } 9 | 10 | public SimpleDocument() 11 | { 12 | CreatedOn = DateTime.Now; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /tests/TestDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Relax.Impl.Model; 3 | using Symbiote.Core; 4 | 5 | namespace Relax.Tests 6 | { 7 | public class TestDocument : ComplexCouchDocument 8 | { 9 | public virtual string Message { get; set; } 10 | public virtual DateTime CreatedOn { get; set; } 11 | 12 | public TestDocument() 13 | { 14 | _documentId = Guid.NewGuid(); 15 | CreatedOn = DateTime.Now; 16 | } 17 | } 18 | 19 | public class TestDocumentKeyAccessor : IKeyAccessor 20 | { 21 | public string GetId( TestDocument actor ) 22 | { 23 | return actor.DocumentId.ToString(); 24 | } 25 | 26 | public void SetId( TestDocument actor, TKey key ) 27 | { 28 | actor.DocumentId = Guid.Parse( key.ToString() ); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /tests/URI/Encoding/UrlEncoder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Machine.Specifications; 6 | using Relax.Impl.Json; 7 | using Symbiote.Core.Extensions; 8 | 9 | namespace Relax.Tests.URI.Encoding 10 | { 11 | public abstract class with_test_json 12 | { 13 | protected static object[] keySource; 14 | protected static string testJson; 15 | 16 | private Establish context = () => 17 | { 18 | keySource = new object[] {"a", 12, "ab+=.,[]<>", "123-123-4556", DateTime.Parse("6/17/1979"), 14.5,true}; 19 | testJson = keySource.ToJson(false); 20 | }; 21 | } 22 | 23 | public class when_encoding_json_for_url : with_test_json 24 | { 25 | protected static string result; 26 | protected static string expected = @"[""a"",12,""ab%2b%3d.%2c%5b%5d%3c%3e"",""123-123-4556"",""1979-06-17T00%3a00%3a00"",14.5,true]"; 27 | 28 | private Because of = () => 29 | { 30 | var encoder = new JsonUrlEncoder(); 31 | result = encoder.Encode(testJson); 32 | }; 33 | 34 | private It should_provide_expected_format = () => result.ShouldEqual(expected); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/URI/Encoding/when_encoding_json_for_url.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Json; 3 | 4 | namespace Relax.Tests.URI.Encoding 5 | { 6 | public class when_encoding_json_for_url : with_test_json 7 | { 8 | protected static string result; 9 | protected static string expected = @"[""a"",12,""ab%2b%3d.%2c%5b%5d%3c%3e"",""123-123-4556"",""1979-06-17T00%3a00%3a00"",14.5,true]"; 10 | 11 | private Because of = () => 12 | { 13 | var encoder = new JsonUrlEncoder(); 14 | result = encoder.Encode(testJson); 15 | }; 16 | 17 | private It should_provide_expected_format = () => result.ShouldEqual(expected); 18 | } 19 | } -------------------------------------------------------------------------------- /tests/URI/Encoding/with_test_json.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | using Symbiote.Core.Serialization; 4 | 5 | namespace Relax.Tests.URI.Encoding 6 | { 7 | public abstract class with_test_json 8 | { 9 | protected static object[] keySource; 10 | protected static string testJson; 11 | 12 | private Establish context = () => 13 | { 14 | keySource = new object[] {"a", 12, "ab+=.,[]<>", "123-123-4556", DateTime.Parse("6/17/1979"), 14.5,true}; 15 | testJson = keySource.ToJson(false); 16 | }; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/URI/ViewQuery/with_couch_uri.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Moq; 3 | using Relax.Impl.Http; 4 | 5 | namespace Relax.Tests.URI.ViewQuery 6 | { 7 | public abstract class with_couch_uri 8 | { 9 | protected static Mock uriMock; 10 | protected static CouchUri uri { get { return uriMock.Object; } } 11 | protected static Relax.Impl.Commands.ViewQuery query { get { return new Relax.Impl.Commands.ViewQuery(uri); } } 12 | 13 | private Establish context = () => 14 | { 15 | uriMock = new Mock("http", "localhost", 5984); 16 | }; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/URI/when_bulk_inserting.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_bulk_inserting : with_basic_uri 7 | { 8 | private Because of = () => uri.BulkInsert(); 9 | 10 | private It should_append_bulk_docs 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_bulk_docs"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/URI/when_cleaning_up_view.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_cleaning_up_view : with_basic_uri 7 | { 8 | private Because of = () => { uri.CleanupViews(); }; 9 | 10 | private It should_append_view_cleanup_to_uri = 11 | () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_view_cleanup"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_compacting_database.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_compacting_database : with_basic_uri 7 | { 8 | private Because of = () => { uri.Compact(); }; 9 | 10 | private It should_append_compact_to_uri = 11 | () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_compact"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_compacting_view.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_compacting_view : with_basic_uri 7 | { 8 | private Because of = () => { uri.CompactView("testView"); }; 9 | 10 | private It should_append_compact_to_uri = 11 | () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_compact/testView"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_creating_baseline_uri.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_creating_baseline_uri : with_basic_uri 7 | { 8 | private It should_have_proper_format = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax"); 9 | } 10 | } -------------------------------------------------------------------------------- /tests/URI/when_getting_attachment_including_revision.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_getting_attachment_including_revision : with_basic_uri 7 | { 8 | private Because of = () => uri.Id("id").Attachment("foo.txt").Revision("1-A"); 9 | 10 | private It should_append_attachment 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/id/foo.txt?rev=1-A"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_grouping.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_grouping : with_basic_uri 7 | { 8 | private Because of = () => uri.Group(); 9 | 10 | private It should_append_group_level_1 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax?group=true&group_level=1"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_grouping_with_level.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_grouping_with_level : with_basic_uri 7 | { 8 | private Because of = () => uri.Group(2); 9 | 10 | private It should_append_group_level_2 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax?group=true&group_level=2"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_inclusive_end_in_view.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_inclusive_end_in_view : with_basic_uri 7 | { 8 | private Because of = () => uri.NonInclusiveRange(); 9 | 10 | private It should_append_inclusive_end_true 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax?inclusive_end=false"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_key.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_key : with_basic_uri 7 | { 8 | private Because of = () => uri.Id("id"); 9 | 10 | private It should_append_id_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/id"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_key_and_revision.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_key_and_revision : with_basic_uri 7 | { 8 | private Because of = () => uri.IdAndRev("id", 2); 9 | 10 | private It should_append_key_and_rev_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/id?rev=2"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_list_all.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_list_all : with_basic_uri 7 | { 8 | private Because of = () => uri.ListAll(); 9 | 10 | private It should_append_all_docs_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_all_docs"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_list_all_with_descending.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_list_all_with_descending : with_basic_uri 7 | { 8 | private Because of = () => uri.ListAll().Descending(); 9 | 10 | private It should_append_all_docs_and_descending_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_all_docs?descending=true"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_list_all_with_descending_and_limit.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_list_all_with_descending_and_limit : with_basic_uri 7 | { 8 | private Because of = () => uri.ListAll().Descending().Limit(100); 9 | 10 | private It should_append_all_docs_and_descending_and_limit_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_all_docs?descending=true&limit=100"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_list_all_with_descending_and_skip.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_list_all_with_descending_and_skip : with_basic_uri 7 | { 8 | private Because of = () => uri.ListAll().Descending().Skip(5); 9 | 10 | private It should_append_all_docs_and_descending_and_skip_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_all_docs?descending=true&skip=5"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_named_list_with_descending_and_skip.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_named_list_with_descending_and_skip : with_basic_uri 7 | { 8 | private Because of = () => uri.List("myList").Descending().Skip(5); 9 | 10 | private It should_append_named_list_and_descending_and_skip_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_list/myList?descending=true&skip=5"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_range.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_range : with_basic_uri 7 | { 8 | private Because of = () => uri.ByRange("id1", "id10"); 9 | 10 | private It should_append_start_and_end_keys_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax?startkey=""id1""&endkey=""id10"""); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_by_view.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_by_view : with_basic_uri 7 | { 8 | private Because of = () => uri.View("myView"); 9 | 10 | private It should_append_view_name_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_view/myView"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_changes_continuously.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl; 3 | 4 | namespace Relax.Tests.URI 5 | { 6 | [Subject("Couch URI")] 7 | public class when_retrieving_changes_continuously : with_basic_uri 8 | { 9 | private Because of = () => uri.Changes(Feed.Continuous, 10); 10 | 11 | private It should_append_feed_and_since_to_uri 12 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_changes?feed=continuous&since=10"); 13 | } 14 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_changes_continuously_including_documents.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl; 3 | 4 | namespace Relax.Tests.URI 5 | { 6 | [Subject("Couch URI")] 7 | public class when_retrieving_changes_continuously_including_documents : with_basic_uri 8 | { 9 | private Because of = () => uri.Changes(Feed.Continuous, 10).IncludeDocuments(); 10 | 11 | private It should_append_feed_and_since_to_uri 12 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_changes?feed=continuous&since=10&include_docs=true"); 13 | } 14 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_changes_via_longpolling.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl; 3 | 4 | namespace Relax.Tests.URI 5 | { 6 | [Subject("Couch URI")] 7 | public class when_retrieving_changes_via_longpolling : with_basic_uri 8 | { 9 | private Because of = () => uri.Changes(Feed.LongPolling, 10); 10 | 11 | private It should_append_feed_and_since_to_uri 12 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_changes?feed=longpoll&since=10"); 13 | } 14 | } -------------------------------------------------------------------------------- /tests/URI/when_retrieving_design_document.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_retrieving_design_document : with_basic_uri 7 | { 8 | private Because of = () => uri.Design("myDesign"); 9 | 10 | private It should_append_design_document_to_uri 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/_design/myDesign"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_setting_up_replication.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_setting_up_replication : with_basic_uri_without_db 7 | { 8 | private Because of = () => { uri.Replicate(); }; 9 | 10 | private It should_append_compact_to_uri = 11 | () => uri.ToString().ShouldEqual(@"http://localhost:5984/_replicate"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_stale_records_are_ok.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_stale_records_are_ok : with_basic_uri 7 | { 8 | private Because of = () => uri.StaleOk(); 9 | 10 | private It should_append_stale 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax?stale=ok"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_turning_off_reduce.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_turning_off_reduce : with_basic_uri 7 | { 8 | private Because of = () => uri.NoReduce(); 9 | 10 | private It should_append_reduce_false 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax?reduce=false"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_using_attachments.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.URI 4 | { 5 | [Subject("Couch URI")] 6 | public class when_using_attachments : with_basic_uri 7 | { 8 | private Because of = () => uri.Attachment("foo.txt"); 9 | 10 | private It should_append_attachment 11 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax/foo.txt"); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/URI/when_using_end_key_only.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.URI 5 | { 6 | [Subject("Couch URI")] 7 | public class when_using_end_key_only : with_basic_uri 8 | { 9 | private static DateTime date = DateTime.Now; 10 | private static object complexKey; 11 | 12 | private Because of = () => 13 | { 14 | complexKey = new object[] {"test", 10, "+"}; 15 | uri.EndKey(complexKey); 16 | }; 17 | 18 | private It should_append_reduce_false 19 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax?endkey=[""test"",10,""%2b""]"); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/URI/when_using_start_key_only.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Machine.Specifications; 3 | 4 | namespace Relax.Tests.URI 5 | { 6 | [Subject("Couch URI")] 7 | public class when_using_start_key_only : with_basic_uri 8 | { 9 | private static DateTime date = DateTime.Now; 10 | private static string complexKey; 11 | 12 | private Because of = () => 13 | { 14 | complexKey = "test+10"; 15 | uri.StartKey(complexKey); 16 | }; 17 | 18 | private It should_append_reduce_false 19 | = () => uri.ToString().ShouldEqual(@"http://localhost:5984/relax?startkey=""test%2b10"""); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/URI/with_basic_uri.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.URI 5 | { 6 | public abstract class with_basic_uri 7 | { 8 | protected static CouchUri uri; 9 | private Establish context = () => uri = CouchUri.Build("http", "localhost", 5984, "relax"); 10 | } 11 | } -------------------------------------------------------------------------------- /tests/URI/with_basic_uri_without_db.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Impl.Http; 3 | 4 | namespace Relax.Tests.URI 5 | { 6 | public abstract class with_basic_uri_without_db 7 | { 8 | protected static CouchUri uri; 9 | private Establish context = () => uri = CouchUri.Build("http", "localhost", 5984); 10 | } 11 | } -------------------------------------------------------------------------------- /tests/ViewFilter/Request.cs: -------------------------------------------------------------------------------- 1 | namespace Relax.Tests.ViewFilter 2 | { 3 | public class Request : CouchDocument 4 | { 5 | public string Message { get; set; } 6 | 7 | public Request() 8 | { 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/ViewFilter/when_filtering_design_documents_from_results.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Machine.Specifications; 4 | using Relax.Impl.Json; 5 | using Symbiote.Core.Serialization; 6 | 7 | namespace Relax.Tests.ViewFilter 8 | { 9 | public class when_filtering_design_documents_from_results : with_test_json 10 | { 11 | protected static List requests; 12 | 13 | private Because of = () => 14 | { 15 | var filter = new DesignDocumentFilter(); 16 | json = filter.Filter(json); 17 | 18 | var view = json.FromJson>(); 19 | requests = view.GetList().ToList(); 20 | }; 21 | 22 | private It should_have_only_1_results = () => requests.Count.ShouldEqual(1); 23 | } 24 | } -------------------------------------------------------------------------------- /tests/ViewFilter/with_test_json.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | 3 | namespace Relax.Tests.ViewFilter 4 | { 5 | public abstract class with_test_json 6 | { 7 | protected static string json; 8 | 9 | private Establish context = () => 10 | { 11 | json = @"{""total_rows"":6,""offset"":0,""rows"":[ 12 | {""id"":""10c8208b-9575-4c13-be9f-3355b547c287"",""key"":""10c8208b-9575-4c13-be9f-3355b547c287"",""value"":{""rev"":""1-cead7a9977aa56695fc287c5050b676f""},""doc"":{""_id"":""10c8208b-9575-4c13-be9f-3355b547c287"",""_rev"":""1-cead7a9977aa56695fc287c5050b676f"",""Message"":""Test""}}, 13 | {""id"":""_design/requests"",""key"":""_design/requests"",""value"":{""rev"":""1-1ff1c1551a076eaed3ccebc516a5e77e""},""doc"":{""_id"":""_design/requests"",""_rev"":""1-1ff1c1551a076eaed3ccebc516a5e77e"",""language"":""javascript"",""views"":{""by_user"":{""map"":""function(doc) { emit(doc.Requestor, doc) }""}}}}, 14 | ]}"; 15 | }; 16 | } 17 | } -------------------------------------------------------------------------------- /tests/with_configuration.cs: -------------------------------------------------------------------------------- 1 | using Machine.Specifications; 2 | using Relax.Config; 3 | using Relax.Impl.Http; 4 | using Symbiote.Core; 5 | 6 | namespace Relax.Tests 7 | { 8 | public abstract class with_configuration 9 | { 10 | protected static ICouchConfiguration configuration; 11 | private Establish context = () => 12 | { 13 | Assimilate.Initialize(); 14 | configuration = new CouchConfiguration(); 15 | }; 16 | 17 | protected static void WireUpCommandMock(IHttpAction commandMock) 18 | { 19 | var mock = Assimilate.GetAllInstancesOf(); 20 | 21 | Assimilate.Dependencies( x => x.For().Use( commandMock ) ); 22 | } 23 | } 24 | } --------------------------------------------------------------------------------