Example #1
0
        public async Task HistoryIsSavedForChanges()
        {
            string spfRecord1 = "spfRecord1";
            string spfRecord2 = "spfRecord2";

            SpfHistoryEntityState state = new SpfHistoryEntityState(Id,
                                                                    new List <SpfHistoryRecord> {
                new SpfHistoryRecord(DateTime.UtcNow.AddDays(-1), null, new List <string> {
                    spfRecord1
                })
            });

            await _dao.Save(state);

            SpfHistoryEntityState state2 = (await SelectAllHistory(Id)).First();

            state2.SpfHistory[0].EndDate = DateTime.UtcNow;
            state2.SpfHistory.Insert(0, new SpfHistoryRecord(DateTime.UtcNow, null, new List <string> {
                spfRecord2
            }));

            await _dao.Save(state2);

            List <SpfHistoryEntityState> historyStates = await SelectAllHistory(Id);

            Assert.That(historyStates[0].SpfHistory.Count, Is.EqualTo(2));

            Assert.That(historyStates[0].SpfHistory[0].EndDate, Is.Null);
            Assert.That(historyStates[0].SpfHistory[0].SpfRecords.Count, Is.EqualTo(1));
            Assert.That(historyStates[0].SpfHistory[0].SpfRecords[0], Is.EqualTo(spfRecord2));

            Assert.That(historyStates[0].SpfHistory[1].EndDate, Is.Not.Null);
            Assert.That(historyStates[0].SpfHistory[1].SpfRecords.Count, Is.EqualTo(1));
            Assert.That(historyStates[0].SpfHistory[1].SpfRecords[0], Is.EqualTo(spfRecord1));
        }
        public async Task HandleDomainCreatedCreatesDomain()
        {
            A.CallTo(() => _spfHistoryEntityDao.Get(Id)).Returns <SpfHistoryEntityState>(null);
            await _spfEntityHistory.Handle(new DomainCreated(Id, "*****@*****.**", DateTime.Now));

            A.CallTo(() => _spfHistoryEntityDao.Save(A <SpfHistoryEntityState> ._)).MustHaveHappenedOnceExactly();
        }
        public async Task Handle(DomainCreated message)
        {
            string messageId = message.Id.ToLower();

            SpfHistoryEntityState state = await _dao.Get(messageId);

            if (state == null)
            {
                state = new SpfHistoryEntityState(messageId);
                await _dao.Save(state);

                _log.LogInformation("Created SpfEntityHistory for {Id}.", messageId);
            }
            else
            {
                _log.LogWarning("Ignoring {EventName} as SpfEntityHistory already exists for {Id}.",
                                nameof(DomainCreated), messageId);
                ;
            }
        }