Exemplo n.º 1
0
        public async Task HistoryIsSavedForChanges()
        {
            string record1 = "v=TLSRPTv1;rua=mailto:[email protected]";
            string record2 = "v=TLSRPTv1;rua=mailto:[email protected]";

            TlsRptEntityHistoryState state = new TlsRptEntityHistoryState(Id,
                                                                          new List <TlsRptHistoryRecord> {
                new TlsRptHistoryRecord(DateTime.UtcNow.AddDays(-1), null, new List <string> {
                    record1
                })
            });

            await _dao.Save(state);

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

            state2.TlsRptHistory[0].EndDate = DateTime.UtcNow;
            state2.TlsRptHistory.Insert(0, new TlsRptHistoryRecord(DateTime.UtcNow, null, new List <string> {
                record2
            }));

            await _dao.Save(state2);

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

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

            Assert.That(historyStates[0].TlsRptHistory[0].EndDate, Is.Null);
            Assert.That(historyStates[0].TlsRptHistory[0].TlsRptRecords.Count, Is.EqualTo(1));
            Assert.That(historyStates[0].TlsRptHistory[0].TlsRptRecords[0], Is.EqualTo(record2));

            Assert.That(historyStates[0].TlsRptHistory[1].EndDate, Is.Not.Null);
            Assert.That(historyStates[0].TlsRptHistory[1].TlsRptRecords.Count, Is.EqualTo(1));
            Assert.That(historyStates[0].TlsRptHistory[1].TlsRptRecords[0], Is.EqualTo(record1));
        }
Exemplo n.º 2
0
        public async Task HandleDomainCreatedCreatesDomain()
        {
            A.CallTo(() => _entityDao.Get(Id)).Returns <TlsRptEntityHistoryState>(null);
            await _historyEntity.Handle(new DomainCreated(Id, "*****@*****.**", DateTime.Now));

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

            TlsRptEntityHistoryState state = await _dao.Get(messageId);

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

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