public void cache_should_save_multiple_data()
        {
            var cache = new RepositoryCache();

            IAggregate aggregate = User.CreateUser(FakeUser.TestLogin, FakeUser.TestPassword, new IdentityGenerator());
            cache.Add(aggregate);

            aggregate = Competence.Create("test", new IdentityGenerator());
            cache.Add(aggregate);

            cache.Get(aggregate.Id).Should().Be(aggregate);
        }
        public void cache_should_save_data()
        {
            var cache = new RepositoryCache();
            var aggregate = User.CreateUser(FakeUser.TestLogin, FakeUser.TestPassword, new IdentityGenerator());

            cache.Add(aggregate);
            cache.Get(aggregate.Id).Should().Be(aggregate);
        }
        public void cache_should_not_allow_duplicate_add()
        {
            var id = Guid.NewGuid();
            var generator = Substitute.For<IIdentityGenerator>();
            generator.NewId().Returns(id);

            var cache = new RepositoryCache();

            var aggregate = User.CreateUser(FakeUser.TestLogin, FakeUser.TestPassword, generator);
            cache.Add(aggregate);

            aggregate = User.CreateUser(FakeUser.TestLogin, FakeUser.TestPassword, generator);
            cache.Invoking(c => c.Add(aggregate)).ShouldThrow<AggregateVersionException>();
        }
        public void initial_builder_should_fail_for_creation_event_for_existing_aggregate()
        {
            var employee = FakeEmployee.ArrangeEmployee(2);
            var newCompetences = FakeEmployee.ArrangeCompetencies(3);
            employee.AddCompetences(newCompetences);

            var events = ((IAggregate)employee).GetUncommittedEvents().ToList();

            var cache = new RepositoryCache();
            IEventHandler<DomainEvent> eventHandler = new InitialAggregateBuilder(new AggregateFactory(), cache);

            cache.Add(employee);

            var creationEvent = events[0];
            eventHandler.Invoking(i => i.Handle(creationEvent)).ShouldNotThrow<AggregateVersionException>();
        }
        public void initial_builder_should_skip_uncommited_events()
        {
            var employee = FakeEmployee.ArrangeEmployee(2);
            var newCompetences = FakeEmployee.ArrangeCompetencies(3);
            employee.AddCompetences(newCompetences);

            var events = ((IAggregate)employee).GetUncommittedEvents().ToList();

            var cache = new RepositoryCache();
            IEventHandler<DomainEvent> eventHandler = new InitialAggregateBuilder(new AggregateFactory(), cache);

            cache.Add(employee);

            var firstCompetenceChange = events[1];
            eventHandler.Handle(firstCompetenceChange);

            employee.Competencies.Count.Should().Be(5);
        }