Example #1
0
        public async Task single_should_load_aggregate()
        {
            // arrange
            var id          = NewGuid();
            var birthday    = Now.AddYears(-3);
            var anniversary = Now;
            var person      = new Person(id, "Jane", "Smith", birthday);
            var spouse      = new Person(NewGuid(), "John", "Doe", Now);

            person.Marry(spouse, anniversary);
            person.ChangeLastName("Doe");

            var events = new IEvent[]
            {
                new Born(id, "Jane", "Smith", birthday),
                new Married(id, spouse.Id, anniversary),
                new LastNameChanged(id, "Doe")
            };
            var eventStore = new SimpleEventStore(new Dictionary <Guid, IEnumerable <IEvent> >()
            {
                [id] = events
            });
            var repository = new Repository <Person>(eventStore);

            // act
            var twin = await repository.Single(id, CancellationToken.None);

            // assert
            twin.Equals(person).Should().BeTrue();
        }
Example #2
0
        public void replay_all_should_load_aggregate_from_history()
        {
            // arrange
            var id       = NewGuid();
            var birthday = Now.AddYears(-3);
            var person   = new Person(id, "Jane", "Smith", birthday);
            var spouse   = new Person(NewGuid(), "John", "Doe", Now);
            var version  = 0;

            person.Marry(spouse, Now);
            person.ChangeLastName("Doe");

            foreach (var @event in person.UncommittedEvents)
            {
                @event.Version = version++;
            }

            var lifeExperiences = person.UncommittedEvents.ToArray();
            var twin            = new Person();

            person.AcceptChanges();

            // act
            twin.ReplayAll(lifeExperiences);

            // assert
            twin.Equals(person).Should().BeTrue();
            twin.Version.Should().Be(2);
        }
Example #3
0
        public async Task save_should_throw_exception_when_concurrency_is_violated()
        {
            // arrange
            var id          = NewGuid();
            var birthday    = Now.AddYears(-21);
            var newEvents   = new IEvent[] { new Married(id, NewGuid(), Now) };
            var persistence = new SimplePersistence();
            var eventStore  = new SimpleEventStore(persistence);

            await persistence.Persist(new Commit()
            {
                Id = id, Version = 0, Events = { new Born(id, "John", "Doe", birthday) }
            }, CancellationToken.None);

            await persistence.Persist(new Commit()
            {
                Id = id, Version = 1, Events = { new Married(id, NewGuid(), Now) }
            }, CancellationToken.None);

            // act
            Func <Task> save = () => eventStore.Save(id, newEvents, 0, CancellationToken.None);

            // assert
            save.Should().Throw <ConcurrencyException>();
        }
Example #4
0
        public async Task save_should_update_state()
        {
            // arrange
            var repository = new Repository <Person>(new SimpleEventStore());
            var person     = new Person(NewGuid(), "Jane", "Smith", Now.AddYears(-3));
            var spouse     = new Person(NewGuid(), "John", "Doe", Now);

            person.Marry(spouse, Now);
            person.ChangeLastName("Doe");

            // act
            await repository.Save(person, ExpectedVersion.Initial, CancellationToken.None);

            // assert
            person.IsChanged.Should().BeFalse();
            person.UncommittedEvents.Should().BeEmpty();
            person.Version.Should().Be(2);
        }
Example #5
0
        public async Task CreateInSameMonthNextYear()
        {
            var workers = new[] { new Worker {
                                      FullName = "Василий"
                                  } };
            await workerRepository.CreateManyAsync(shop.Id, workers);

            var page = LoadMainPage().GoToWorkerListPage().OpenCalendar();

            for (var i = 0; i < 12; i++)
            {
                page.GoToNextMonth();
            }

            var editor = page.OpenEditor(0, 0).GetEditingView();

            editor.SetTimeRange("10:00", "21:00");
            editor.SetCalendarMode(CalendarFillingMode.FiveByTwo);
            editor.ClickSave();

            CheckMonthFor5By2From(page, DateHelper.GetFirstDayOfMonth(Now.AddYears(1)));
        }
Example #6
0
        public void accept_changes_should_update_state()
        {
            // arrange
            var person  = new Person(NewGuid(), "Jane", "Smith", Now.AddYears(-3));
            var spouse  = new Person(NewGuid(), "John", "Doe", Now);
            var version = 0;

            person.Marry(spouse, Now);
            person.ChangeLastName("Doe");

            foreach (var @event in person.UncommittedEvents)
            {
                @event.Version = version++;
            }

            // act
            person.AcceptChanges();

            // assert
            person.IsChanged.Should().BeFalse();
            person.UncommittedEvents.Should().BeEmpty();
            person.Version.Should().Be(2);
        }
Example #7
0
        public async Task save_should_update_event_versions()
        {
            // arrange
            var id       = NewGuid();
            var birthday = Now.AddYears(-21);
            var events   = new IEvent[]
            {
                new Born(id, "John", "Doe", birthday),
                new Married(id, NewGuid(), Now)
            };
            var persistence = new SimplePersistence();
            var eventStore  = new SimpleEventStore(persistence);
            var version     = 0;
            var sequence    = 0;

            // act
            await eventStore.Save(id, events, ExpectedVersion.Initial, CancellationToken.None);

            // assert
            foreach (var @event in events)
            {
                @event.Should().BeEquivalentTo(new { Version = version, Sequence = sequence++ }, options => options.ExcludingMissingMembers());
            }
        }
Example #8
0
        public MaterialProvider(MaterialLogger logger)
        {
            All    = logger.Read().ToArray();
            AsDays = MakeDiff(EachDay(All)).Reverse().ToArray();
            DateTime firsttime = Now;

            if (All.Count > 0)
            {
                firsttime = All[0].DateTime;
            }
            Durations = new[]
            {
                new { TitleKey = "ChartTimeRange_Days1", From = Now.AddDays(-1) },
                new { TitleKey = "ChartTimeRange_Weeks1", From = Now.AddDays(-7) },
                new { TitleKey = "ChartTimeRange_Weeks2", From = Now.AddDays(-14) },
                new { TitleKey = "ChartTimeRange_Months1", From = Now.AddMonths(-1) },
                new { TitleKey = "ChartTimeRange_Months2", From = Now.AddMonths(-2) },
                new { TitleKey = "ChartTimeRange_Months3", From = Now.AddMonths(-3) },
                new { TitleKey = "ChartTimeRange_Months6", From = Now.AddMonths(-6) },
                new { TitleKey = "ChartTimeRange_Years1", From = Now.AddYears(-1) },
                new { TitleKey = "ChartTimeRange_All", From = firsttime }
            };
            From = Now.AddDays(-14);
        }
Example #9
0
 public static void AddAcceptanceCookie(string domain)
 {
     Session.ExecuteScript(
         $"document.cookie = 'CookiesAccepted=CookiesAccepted; domain={domain}; path=/; expires={Now.AddYears(2).ToUniversalTime()};'");
 }