Skip to content

Commit

Permalink
added coverage for aggregate root. added circle ci config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Stafford committed Feb 3, 2019
1 parent 8474ea3 commit 2a34c45
Show file tree
Hide file tree
Showing 46 changed files with 527 additions and 2,465 deletions.
23 changes: 23 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2
jobs:
build:
docker:
- image: microsoft/dotnet:2.2-sdk
branches:
only:
- master
steps:
- checkout
- run:
name: Restore Packages
command: dotnet restore src
- run:
name: Build Solution (should auto-pack)
command: dotnet build src -c Release /p:BuildNumber=${CIRCLE_BUILD_NUM}
- run:
name: Run unit tests
command: dotnet test src
- run:
name: Publish NuGet Packages
command: dotnet nuget push src/**/bin/Release/**.nupkg --source https://api.nuget.org/v3/index.json --api-key ${PROV_NUGET_KEY}

4 changes: 2 additions & 2 deletions src/Provausio.Practices.Tests/DDD/ValueObjectTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using DAS.Infrastructure;
using Provausio.Common;
using Provausio.Practices.DDD;
using Xunit;

Expand Down Expand Up @@ -231,7 +231,7 @@ public static TimestampObj FromString(string input)
var coll = ObjectPropertyCollection.FromKvpString(input);
return new TimestampObj
{
Timestamp = DAS.Infrastructure.Timestamp.FromMilliseconds(coll[nameof(Timestamp)]),
Timestamp = Common.Timestamp.FromMilliseconds(coll[nameof(Timestamp)]),
Prop1 = coll[nameof(Prop1)]
};
}
Expand Down
25 changes: 25 additions & 0 deletions src/Provausio.Practices.Tests/EventSourcing/AggregateEventTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Provausio.Practices.EventSourcing.Aggregate;
using Xunit;

namespace Provausio.Practices.Tests.EventSourcing
{
public class AggregateEventTests
{
[Fact]
public void Create_GeneratesAnId()
{
// arrange

// act
var ev = AggregateEvent.Create<TestEvent1>();

Assert.NotEmpty(ev.Id.ToString());
Assert.NotNull(ev.Id);
}
}

public class TestEvent1 : AggregateEvent
{

}
}
102 changes: 102 additions & 0 deletions src/Provausio.Practices.Tests/EventSourcing/AggregateRootTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Provausio.Practices.EventSourcing.Aggregate;
using Xunit;

namespace Provausio.Practices.Tests.EventSourcing
{
public class AggregateRootTests
{
[Fact]
public void Raise_QueuesEvent()
{
// arrange

// act
var test = TestRoot.Create("foo", 1);

// assert
Assert.Equal(1, test.UncommittedEvents.Count);
Assert.IsType<CreationEvent>(test.UncommittedEvents.First());
}

[Fact]
public void Raise_NewRoot_VersionIsNotIncremented()
{
// arrange
var test = TestRoot.Create("foo", 1);

// act
test.Action1();

// assert
Assert.Equal(-1, test.Version);
}

[Fact]
public void Raise_ExistingRoot_VersionIsIncremented()
{
// arrange
var eventStream = new List<AggregateEvent>
{
new CreationEvent {Version = 0, RootId = "abc"},
new Action1Occured {Version = 1, RootId = "abc"},
new EntityCreated {Version = 2, RootId = "abc"}
};

// act
var test = new TestRoot() {Id = "abc"};
test.LoadFromStream(eventStream);

// assert
Assert.Equal(2, test.Version);
}

[Fact]
public void LoadFromStream_BringsObjectToState()
{
// arrange
var id = Guid.NewGuid();
var test = new TestRoot { Id = id.ToString() };
var create = new CreationEvent { Id = id, RootId = id.ToString(), Version = 0, Prop1 = "foo", Prop2 = 1 };
var action1 = new Action1Occured { RootId = id.ToString(), Version = 1 };

// act
test.LoadFromStream(new AggregateEvent[] { create, action1 });

// assert
Assert.Equal(0, test.UncommittedEvents.Count);
Assert.Equal(id.ToString(), test.Id);
Assert.True(test.Action1Occured);
Assert.Equal(1, test.Version);
}

[Fact]
public void CreateEntity_CreatesEntity()
{
// arrange
var test = TestRoot.Create("foo", 1);

// act
test.CreateEntity("entity-foo");

// assert
Assert.Equal("entity-foo", test.EntityProp);
}

[Fact]
public void UpdateEntity_ProxiesEventsToEntity()
{
// arrange
var test = TestRoot.Create("foo", 1);
test.CreateEntity("entity-foo");

// act
test.UpdateEntity("entity-bar");

// assert
Assert.Equal("entity-bar", test.EntityProp);
}
}
}
86 changes: 0 additions & 86 deletions src/Provausio.Practices.Tests/EventSourcing/AggregateTests.cs

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2a34c45

Please sign in to comment.