Permalink
Browse files

Merge pull request #7 from chribben/share_document

Share document - command, events and tests.
  • Loading branch information...
2 parents f222794 + c108703 commit add154af33f8999a0ae11ede521ad9dbb2a8a335 @haf committed Dec 16, 2011
Showing with 220 additions and 37 deletions.
  1. +2 −1 .gitignore
  2. +5 −5 src/Documently.Commands/Command.cs
  3. +1 −1 src/Documently.Commands/CreateDocumentMetaData.cs
  4. +2 −2 src/Documently.Commands/CreateNewCustomer.cs
  5. +1 −1 src/Documently.Commands/CreateNewDocumentCollection.cs
  6. +1 −0 src/Documently.Commands/Documently.Commands.csproj
  7. +2 −2 src/Documently.Commands/RelocateTheCustomer.cs
  8. +21 −0 src/Documently.Commands/ShareDocument.cs
  9. +1 −1 src/Documently.Domain.Service/app.config
  10. +1 −1 src/Documently.Domain/CommandHandlers/CreateCustomerCommandHandler.cs
  11. +1 −1 src/Documently.Domain/CommandHandlers/DocumentAssociatedWithCollectionHandler.cs
  12. +1 −1 src/Documently.Domain/CommandHandlers/DocumentIndexingHandler.cs
  13. +5 −3 src/Documently.Domain/CommandHandlers/DocumentMetaDataHandler.cs
  14. +1 −1 src/Documently.Domain/CommandHandlers/RelocatingCustomerCommandHandler.cs
  15. +28 −0 src/Documently.Domain/CommandHandlers/ShareDocumentCommandHandler.cs
  16. +3 −0 src/Documently.Domain/Documently.Domain.csproj
  17. +24 −7 src/Documently.Domain/Domain/Document.cs
  18. +32 −0 src/Documently.Domain/Domain/User.cs
  19. +1 −1 src/Documently.Domain/Events/AssociatedIndexingPending.cs
  20. +1 −1 src/Documently.Domain/Events/DocumentIndexed.cs
  21. +23 −0 src/Documently.Domain/Events/DocumentSharedEvent.cs
  22. +2 −2 src/Documently.Domain/Events/DomainEvent.cs
  23. +1 −1 src/Documently.Indexer/IndexerServices.fs
  24. +1 −0 src/Documently.Specs/Documently.Specs.csproj
  25. +8 −4 src/Documently.Specs/Documents/when_creating_new_document_meta_data.cs
  26. +50 −0 src/Documently.Specs/Documents/when_sharing_a_document.cs
  27. +1 −1 src/Documently.WpfClient/app.config
View
@@ -5,4 +5,5 @@ bin/
obj/
*.csproj.user
src/packages/RavenDB.1.0.499/server/Data/
-src/packages/RavenDB.1.0.499/server/Logs
+src/packages/RavenDB.1.0.499/server/Logs
+*.tmp_proj
@@ -4,21 +4,21 @@ namespace Documently.Commands
{
public abstract class Command
{
- public Guid Id { get; protected set; }
+ public Guid ArId { get; protected set; }
public int Version { get; protected set; }
protected Command()
{
}
- protected Command(Guid id)
+ protected Command(Guid arId)
{
- Id = id;
+ ArId = arId;
}
- protected Command(Guid id, int version)
+ protected Command(Guid arId, int version)
{
- Id = id;
+ ArId = arId;
Version = version;
}
}
@@ -11,7 +11,7 @@ protected CreateDocumentMetaData()
{
}
- public CreateDocumentMetaData(Guid id, string title, DateTime utcTime) : base(id)
+ public CreateDocumentMetaData(Guid arId, string title, DateTime utcTime) : base(arId)
{
Title = title;
UtcTime = utcTime;
@@ -20,9 +20,9 @@ protected CreateNewCustomer()
{
}
- public CreateNewCustomer(Guid id, string customerName, string street, string streetNumber, string postalCode,
+ public CreateNewCustomer(Guid arId, string customerName, string street, string streetNumber, string postalCode,
string city, string phoneNumber)
- : base(id)
+ : base(arId)
{
CustomerName = customerName;
Street = street;
@@ -13,7 +13,7 @@ protected CreateNewDocumentCollection()
public CreateNewDocumentCollection(Guid id, string name)
{
- Id = id;
+ ArId = id;
Name = name;
}
@@ -48,6 +48,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RelocateTheCustomer.cs" />
<Compile Include="CreateDocumentMetaData.cs" />
+ <Compile Include="ShareDocument.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@@ -17,8 +17,8 @@ protected RelocateTheCustomer()
{
}
- public RelocateTheCustomer(Guid id, string street, string streetNumber, string postalCode, string city)
- : base(id)
+ public RelocateTheCustomer(Guid arId, string street, string streetNumber, string postalCode, string city)
+ : base(arId)
{
Street = street;
Streetnumber = streetNumber;
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+
+namespace Documently.Commands
+{
+ [Serializable]
+ public class ShareDocument : Command
+ {
+ [Obsolete("for serialization")]
+ protected ShareDocument()
+ {
+ }
+
+ public ShareDocument(Guid arId, int version, IEnumerable<int> userIds) : base(arId, version)
+ {
+ UserIds = userIds;
+ }
+
+ public IEnumerable<int> UserIds { get; protected set; }
+ }
+}
@@ -8,7 +8,7 @@
</startup>
<connectionStrings>
<!--Server mode-->
- <add name="RavenDB" connectionString="Url = http://localhost:8080" />
+ <add name="RavenDB" connectionString="Url = http://localhost:8081" />
</connectionStrings>
<log4net debug="false">
<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
@@ -20,7 +20,7 @@ public void Consume(CreateNewCustomer command)
{
var repo = _Repository();
- var client = Customer.CreateNew(command.Id, new CustomerName(command.CustomerName),
+ var client = Customer.CreateNew(command.ArId, new CustomerName(command.CustomerName),
new Address(command.Street, command.StreetNumber,
command.PostalCode, command.City),
new PhoneNumber(command.PhoneNumber));
@@ -20,7 +20,7 @@ public DocumentAssociatedWithCollectionHandler(Func<IRepository> repository)
public void Consume(AssociateDocumentWithCollection message)
{
var repository = _repository();
- var document = repository.GetById<Document>(message.Id);
+ var document = repository.GetById<Document>(message.ArId);
document.AssociateWithCollection(message.CollectionId);
repository.Save(document, Guid.NewGuid(), null);
@@ -22,7 +22,7 @@ public DocumentIndexingHandler(Func<IRepository> repo)
public void Consume(InitializeDocumentIndexing command)
{
var repo = _Repo();
- var doc = repo.GetById<Document>(command.Id, command.Version);
+ var doc = repo.GetById<Document>(command.ArId, command.Version);
doc.AssociateWithDocumentBlob(command.BlobId);
//_Bus.Context().Respond();
repo.Save(doc, CombGuid.Generate(), null);
@@ -2,23 +2,25 @@
using CommonDomain.Persistence;
using Documently.Commands;
using Documently.Domain.Domain;
+using Magnum;
using MassTransit;
namespace Documently.Domain.CommandHandlers
{
public class DocumentMetaDataHandler : Consumes<CreateDocumentMetaData>.All
{
- private readonly Func<IRepository> _Repo;
+ private readonly Func<IRepository> _repo;
public DocumentMetaDataHandler(Func<IRepository> repo)
{
if (repo == null) throw new ArgumentNullException("repo");
- _Repo = repo;
+ _repo = repo;
}
public void Consume(CreateDocumentMetaData command)
{
- _Repo().Save(new Document(command.Title, command.UtcTime), command.Id, null);
+ var document = new Document(command.ArId, command.Title, command.UtcTime);
+ _repo().Save(document, CombGuid.Generate(), null);
}
}
}
@@ -19,7 +19,7 @@ public void Consume(RelocateTheCustomer command)
{
var repo = _repository();
const int version = 0;
- var customer = repo.GetById<Customer>(command.Id, version);
+ var customer = repo.GetById<Customer>(command.ArId, version);
customer.RelocateCustomer(command.Street, command.Streetnumber, command.PostalCode, command.City);
repo.Save(customer, Guid.NewGuid(), null);
}
@@ -0,0 +1,28 @@
+using System;
+using CommonDomain.Persistence;
+using Documently.Commands;
+using Documently.Domain.Domain;
+using MassTransit;
+
+namespace Documently.Domain.CommandHandlers
+{
+ public class ShareDocumentCommandHandler : Consumes<ShareDocument>.All
+ {
+ private Func<IRepository> _repository;
+
+ public ShareDocumentCommandHandler(Func<IRepository> repository)
+ {
+ _repository = repository;
+
+ }
+ public void Consume(ShareDocument command)
+ {
+ var repo = _repository();
+ const int version = 0;
+ var document = repo.GetById<Document>(command.ArId, version);
+ document.ShareWith(command.UserIds);
+ repo.Save(document, Guid.NewGuid(), null);
+
+ }
+ }
+}
@@ -64,11 +64,13 @@
<Compile Include="CommandHandlers\DocumentIndexingHandler.cs" />
<Compile Include="CommandHandlers\DocumentMetaDataHandler.cs" />
<Compile Include="CommandHandlers\RelocatingCustomerCommandHandler.cs" />
+ <Compile Include="CommandHandlers\ShareDocumentCommandHandler.cs" />
<Compile Include="Domain\Address.cs" />
<Compile Include="Domain\Customer.cs" />
<Compile Include="Domain\CustomerName.cs" />
<Compile Include="Domain\Document.cs" />
<Compile Include="Domain\DocumentCollection.cs" />
+ <Compile Include="Domain\User.cs" />
<Compile Include="Events\DocumentCollectionCreated.cs" />
<Compile Include="Domain\DocumentState.cs" />
<Compile Include="Domain\NonExistingCustomerException.cs" />
@@ -79,6 +81,7 @@
<Compile Include="Events\DocumentIndexed.cs" />
<Compile Include="Events\DocumentMetaDataCreated.cs" />
<Compile Include="Events\AssociatedIndexingPending.cs" />
+ <Compile Include="Events\DocumentSharedEvent.cs" />
<Compile Include="Events\DomainEvent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@@ -1,4 +1,7 @@
using System;
+using System.Collections.Generic;
+using System.Diagnostics.Contracts;
+using System.Linq;
using CommonDomain.Core;
using Documently.Domain.Events;
using Magnum;
@@ -11,10 +14,10 @@ public Document()
{
}
- public Document(string title, DateTime utcCreated)
+ public Document(Guid documentId, string title, DateTime utcCreated)
{
var @event = new DocumentMetaDataCreated(
- CombGuid.Generate(), title, DocumentState.Created, utcCreated);
+ documentId, title, DocumentState.Created, utcCreated);
RaiseEvent(@event);
}
@@ -26,7 +29,7 @@ public void Apply(DocumentMetaDataCreated evt)
public void AssociateWithDocumentBlob(Guid blobId)
{
- var evt = new AssociatedIndexingPending(DocumentState.AssociatedIndexingPending, blobId, Id, (uint) Version + 1);
+ var evt = new AssociatedIndexingPending(DocumentState.AssociatedIndexingPending, blobId, Id, Version + 1);
RaiseEvent(evt);
}
@@ -41,10 +44,24 @@ public void AssociateWithCollection(Guid collectionId)
RaiseEvent(@event);
}
- public void Apply(AssociatedWithCollection @event)
- {
- }
+ public void Apply(AssociatedWithCollection @event)
+ { }
+
+ public void Apply(DocumentSharedEvent @event)
+ {
+ Id = @event.AggregateId;
+ Version = @event.Version;
+ }
+
+ private Guid _documentBlobId;
- private Guid _documentBlobId;
+ public void ShareWith(IEnumerable<int> userIDs)
+ {
+ Contract.Requires(userIDs != null);
+ Contract.Requires(userIDs.Count() > 0);
+ Contract.Ensures(Contract.OldValue(userIDs) == userIDs);
+ var @event = new DocumentSharedEvent(Id, Version, userIDs);
+ RaiseEvent(@event);
+ }
}
}
@@ -0,0 +1,32 @@
+using System;
+using CommonDomain.Core;
+using Documently.Domain.Events;
+
+namespace Documently.Domain.Domain
+{
+ public class User : AggregateBase
+ {
+ //private User(Guid id, UserName UserName, Address address, PhoneNumber phoneNumber)
+ //{
+ // RaiseEvent(new UserCreatedEvent(id, UserName.Name, address.Street, address.StreetNumber, address.PostalCode,
+ // address.City, phoneNumber.Number));
+ //}
+
+ public User()
+ {
+ }
+
+
+ //public static User CreateNew(Guid id, UserName UserName, Address address, PhoneNumber phoneNumber)
+ //{
+ // return new User(id, UserName, address, phoneNumber);
+ //}
+
+ //Domain-Eventhandlers
+ //private void Apply(UserCreatedEvent @event)
+ //{
+ // Id = @event.AggregateId;
+ // // we don't need to keep any other state here.
+ //}
+ }
+}
@@ -12,7 +12,7 @@ protected AssociatedIndexingPending()
{
}
- public AssociatedIndexingPending(DocumentState processingState, Guid blobId, Guid arId, uint version) : base(arId, version)
+ public AssociatedIndexingPending(DocumentState processingState, Guid blobId, Guid arId, int version) : base(arId, version)
{
ProcessingState = processingState;
BlobId = blobId;
@@ -11,7 +11,7 @@ protected DocumentIndexed()
{
}
- public DocumentIndexed(Guid arId, uint arVersion) : base(arId, arVersion)
+ public DocumentIndexed(Guid arId, int arVersion) : base(arId, arVersion)
{
}
}
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using Documently.Domain.Events;
+
+namespace Documently.Domain.Events
+{
+ [Serializable]
+ public class DocumentSharedEvent : DomainEvent
+ {
+ [Obsolete("for serialization")]
+ protected DocumentSharedEvent()
+ {
+ }
+
+ public DocumentSharedEvent(Guid arId, int arVersion, IEnumerable<int> userIds)
+ : base(arId, arVersion)
+ {
+ UserIds = userIds;
+ }
+
+ public IEnumerable<int> UserIds { get; protected set; }
+ }
+}
@@ -18,7 +18,7 @@ protected DomainEvent()
{
}
- protected DomainEvent(Guid aggregateId, uint aggregateVersion)
+ protected DomainEvent(Guid aggregateId, int aggregateVersion)
{
AggregateId = aggregateId;
Version = aggregateVersion;
@@ -31,6 +31,6 @@ protected DomainEvent(Guid aggregateId, uint aggregateVersion)
/// E.g. CreateNewCustomerCommand would map to (:NewCustomerCreated).Version = 1,
/// as that event corresponds to the creation of the customer.
/// </summary>
- public uint Version { get; protected set; }
+ public int Version { get; protected set; }
}
}
@@ -15,6 +15,6 @@
let txt = File.ReadAllText(p, Encoding.UTF8)
printfn "file contents:"
printfn "%A" txt
- let ret = DocumentIndexed(msg.AggregateId, msg.Version + 1u)
+ let ret = DocumentIndexed(msg.AggregateId, msg.Version + 1)
Thread.Sleep 200 // todo: parse the file!
bus.Publish<DocumentIndexed> ret
Oops, something went wrong.

0 comments on commit add154a

Please sign in to comment.