Skip to content

Added some acceptance tests #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Jan 3, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified lib/eventstore-bin/.NET 4.0/EventStore.dll
Binary file not shown.
Binary file modified lib/eventstore-bin/.NET 4.0/EventStore.pdb
Binary file not shown.
6,836 changes: 6,828 additions & 8 deletions lib/eventstore-bin/.NET 4.0/EventStore.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/CommonDomain.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonDomain.Persistence",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonDomain.Persistence.EventStore", "proj\CommonDomain.Persistence.EventStore\CommonDomain.Persistence.EventStore.csproj", "{F489D9D1-F275-4018-A86F-D84352BCD4E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonDomain.AcceptanceTests", "tests\CommonDomain.AcceptanceTests\CommonDomain.AcceptanceTests.csproj", "{115A8436-93A0-4481-802C-CBC15285FF4E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -35,6 +37,10 @@ Global
{F489D9D1-F275-4018-A86F-D84352BCD4E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F489D9D1-F275-4018-A86F-D84352BCD4E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F489D9D1-F275-4018-A86F-D84352BCD4E9}.Release|Any CPU.Build.0 = Release|Any CPU
{115A8436-93A0-4481-802C-CBC15285FF4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{115A8436-93A0-4481-802C-CBC15285FF4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{115A8436-93A0-4481-802C-CBC15285FF4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{115A8436-93A0-4481-802C-CBC15285FF4E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -44,5 +50,6 @@ Global
{51C99F4D-CCF0-431A-B37C-D620EF1DF37B} = {06FD3DEE-6B33-408C-AFE4-6FADE5525AB0}
{75C8F482-B38D-428C-AD67-890B40E35A63} = {06FD3DEE-6B33-408C-AFE4-6FADE5525AB0}
{F489D9D1-F275-4018-A86F-D84352BCD4E9} = {06FD3DEE-6B33-408C-AFE4-6FADE5525AB0}
{115A8436-93A0-4481-802C-CBC15285FF4E} = {092DA80E-4854-41FD-91F7-D996F41419F2}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{115A8436-93A0-4481-802C-CBC15285FF4E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CommonDomain.AcceptanceTests</RootNamespace>
<AssemblyName>CommonDomain.AcceptanceTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EventStore">
<HintPath>..\..\..\lib\eventstore-bin\.NET 4.0\EventStore.dll</HintPath>
</Reference>
<Reference Include="Machine.Specifications">
<HintPath>..\..\..\bin\machine.specifications-bin\.NET 4.0\Machine.Specifications.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\proj\GlobalAssemblyInfo.cs">
<Link>GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\..\proj\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<Compile Include="..\..\proj\VersionAssemblyInfo.cs">
<Link>VersionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="in_the_event_store.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="When_an_aggregate_is_persisted.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\proj\CommonDomain.Core\CommonDomain.Core.csproj">
<Project>{51C99F4D-CCF0-431A-B37C-D620EF1DF37B}</Project>
<Name>CommonDomain.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\proj\CommonDomain.Persistence.EventStore\CommonDomain.Persistence.EventStore.csproj">
<Project>{F489D9D1-F275-4018-A86F-D84352BCD4E9}</Project>
<Name>CommonDomain.Persistence.EventStore</Name>
</ProjectReference>
<ProjectReference Include="..\..\proj\CommonDomain.Persistence\CommonDomain.Persistence.csproj">
<Project>{75C8F482-B38D-428C-AD67-890B40E35A63}</Project>
<Name>CommonDomain.Persistence</Name>
</ProjectReference>
<ProjectReference Include="..\..\proj\CommonDomain\CommonDomain.csproj">
<Project>{E07187E1-EEE1-44DF-996A-C4733F327BDC}</Project>
<Name>CommonDomain</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\proj\CustomDictionary.xml">
<Link>CustomDictionary.xml</Link>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
using System.Reflection;
[assembly: AssemblyTitle("CommonDomain.AcceptanceTests")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
namespace CommonDomain.AcceptanceTests
{
using System;
using Core;
using EventStore;
using Machine.Specifications;

[Subject("Persistence")]
public class When_an_aggregate_is_persisted: in_the_event_store
{
static Guid id = Guid.NewGuid();
static TestAggregate aggregate;

Establish context = () => aggregate = new TestAggregate(id,"Some name");


Because of = () =>
_repository.Save(aggregate, Guid.NewGuid(), null);

It should_be_returned_when_calling_get_by_id = () =>
_repository.GetById<TestAggregate>(id, 0).ShouldEqual(aggregate);
}

[Subject("Persistence")]
public class When_an_aggregate_is_updated : in_the_event_store
{
static Guid id = Guid.NewGuid();
static string newName = "New name";

Establish context = () => _repository.Save(new TestAggregate(id, "Some name"), Guid.NewGuid(), null);


Because of = () =>
{
var aggregate = _repository.GetById<TestAggregate>(id, 0);
aggregate.ChangeName(newName);

_repository.Save(aggregate,Guid.NewGuid(),null);
};

It should_the_version_number_should_increase = () =>
_repository.GetById<TestAggregate>(id, 0).Version.ShouldEqual(2);
It should_update_the_aggregate = () =>
_repository.GetById<TestAggregate>(id, 0).Name.ShouldEqual(newName);
}


public class TestAggregate : AggregateBase<IDomainEvent>
{
public string Name { get; set; }
public TestAggregate(Guid id)
{
Register<TestAggregateCreatedEvent>(Apply);
Register<NameChangedEvent>(Apply);
Id = id;
}

public TestAggregate(Guid id,string name):this(id)
{
this.RaiseEvent(new TestAggregateCreatedEvent
{
Name = name
});
}
private void Apply(TestAggregateCreatedEvent @event)
{
Name = @event.Name;
}
private void Apply(NameChangedEvent @event)
{
Name = @event.Name;
}

public void ChangeName(string newName)
{
this.RaiseEvent(new NameChangedEvent{Name = newName});
}
}

public class NameChangedEvent : IDomainEvent
{
public string Name { get; set; }
}

public class TestAggregateCreatedEvent : IDomainEvent
{
public string Name { get; set; }
}
}
73 changes: 73 additions & 0 deletions src/tests/CommonDomain.AcceptanceTests/in_the_event_store.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommonDomain.AcceptanceTests
{
using Core;
using EventStore;
using EventStore.Dispatcher;
using EventStore.Persistence;
using EventStore.Persistence.InMemoryPersistence;
using Machine.Specifications;
using Persistence;
using Persistence.EventStore;

public class in_the_event_store
{
protected static IRepository _repository;
protected static ICollection<IDomainEvent> _publishedEvents;

Establish context = () =>
{
var engine = new InMemoryPersistenceEngine();
engine.Initialize();

_publishedEvents = new List<IDomainEvent>();

var eventStore = new OptimisticEventStore(engine, new SynchronousDispatcher(new FakeBus(_publishedEvents), engine));

_repository = new EventStoreRepository(eventStore, new AggregateFactory(), new ReflectionVersionStamper(), new ConflictDetector());

};

Cleanup everything = () =>
{
};

}

internal class AggregateFactory : IConstructAggregates
{
public IAggregate Build(Type type, Guid id, IMemento snapshot)
{
//todo
return Activator.CreateInstance(type,id) as IAggregate;
}
}


public class FakeBus : IPublishMessages
{
readonly ICollection<IDomainEvent> _domainEvents;

public FakeBus(ICollection<IDomainEvent> domainEvents)
{
_domainEvents = domainEvents;
}

public void Dispose()
{
}

public void Publish(Commit commit)
{
commit.Events.ToList().ForEach(e => _domainEvents.Add(e.Body as IDomainEvent));
}
}

public interface IDomainEvent
{
}
}