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_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 initial_builder_should_handle_creation_event()
        {
            var cache = new RepositoryCache();
            IEventHandler<DomainEvent> eventHandler = new InitialAggregateBuilder(new AggregateFactory(), cache);

            for (var i = 0; i < 3; i++)
            {
                var userCreated = FakeUser.ArrangeCreated();
                eventHandler.Handle(userCreated);

                var user = (User)cache.Get(userCreated.AggregateId);

                user.Should().NotBeNull();
                FakeUser.AssertUserCreated(user);
            }
        }
        public void initial_builder_should_handle_change_event()
        {
            var cache = new RepositoryCache();

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

            var created = FakeEmployee.ArrangeCreated();
            var competencies = FakeEmployee.ArrangeCompetenciesChanged(created.AggregateId);

            eventHandler.Handle(created);
            eventHandler.Handle(competencies);

            var employee = cache.Get(created.AggregateId).As<Employee>();
            employee.Should().NotBeNull();
            employee.Id.Should().Be(created.AggregateId);
            employee.Competencies.Select(i => i.CompetenceId).Should().BeEquivalentTo(competencies.Competencies.Select(i => i.CompetenceId));
        }
        public void repository_should_save_user()
        {
            var eventStore = Substitute.For<IEventStore>();
            var cache = new RepositoryCache();

            StoreRepository repository = new StoreRepository(eventStore, cache, new AggregateFactory());

            IEnumerable<DomainEvent> eventsToSave = null;
            eventStore.WhenForAnyArgs(i => i.SaveEvents(null, Guid.Empty)).Do(i => eventsToSave = i.Arg<IEnumerable<DomainEvent>>());

            var user = User.CreateUser(FakeUser.TestLogin, FakeUser.TestPassword, new IdentityGenerator());
            repository.Save(user, Guid.NewGuid());

            cache.Get(user.Id).Should().Be(user);

            var userCreated = eventsToSave.First().As<EventStore.Messages.UserEvents.Created>();

            userCreated.Should().NotBeNull();
            userCreated.Login.Should().Be(FakeUser.TestLogin);
        }
        public void initial_builder_should_handle_two_users_created_event()
        {
            var cache = new RepositoryCache();
            IEventHandler<DomainEvent> eventHandler = new InitialAggregateBuilder(new AggregateFactory(), cache);

            var userCreated = FakeUser.ArrangeCreated();
            var secondCreated = FakeUser.ArrangeCreated(2);

            eventHandler.Handle(userCreated);
            eventHandler.Handle(secondCreated);

            var users = cache.GetAll().ToList();
            users.Count.Should().Be(2);

            FakeUser.AssertUserCreated((User)cache.Get(userCreated.AggregateId));
            users[0].Id.Should().NotBe(users[1].Id);
        }
 public void cache_should_return_null_if_nothing_found()
 {
     var cache = new RepositoryCache();
     var notExistingId = Guid.NewGuid();
     cache.Get(notExistingId).Should().BeNull();
 }